From 028822496c04e00fa3393759d298ba13c27ad44e Mon Sep 17 00:00:00 2001 From: Joshua-Dias-Barreto Date: Mon, 29 May 2023 12:09:02 +0530 Subject: [PATCH 1/2] Added tests for untested methods. --- src/DataFrame-Tests/DataFrameTest.class.st | 112 +++++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/src/DataFrame-Tests/DataFrameTest.class.st b/src/DataFrame-Tests/DataFrameTest.class.st index 20f33daa..973ea4b8 100644 --- a/src/DataFrame-Tests/DataFrameTest.class.st +++ b/src/DataFrame-Tests/DataFrameTest.class.st @@ -295,6 +295,47 @@ DataFrameTest >> testAddRowSizeMismatch [ self should: aBlock raise: SizeMismatch ] +{ #category : #tests } +DataFrameTest >> testApplyElementwise [ + + | dataFrame expected | + dataFrame := DataFrame + withRows: + #( #( 1.1 1.7 1.3 ) + #( 2.2 2.4 2.8 ) + #( 3.5 3.2 3.3 ) ) + rowNames: #( A B C ) + columnNames: #( 1 2 3 ). + expected := DataFrame + withRows: #( #( 1 1 1 ) + #( 2 2 2 ) + #( 3 3 3 ) ) + rowNames: #( A B C ) + columnNames: #( 1 2 3 ). + + dataFrame applyElementwise: [ :value | value floor ]. + self assert: dataFrame equals: expected +] + +{ #category : #tests } +DataFrameTest >> testApplyToAllColumns [ + + | dataFrame actual expected | + dataFrame := DataFrame + withRows: #( #( 1 4 7 ) + #( 2 5 8 ) + #( 3 6 9 ) ) + rowNames: #( A B C ) + columnNames: #( 1 2 3 ). + expected := DataSeries + withKeys: #( 1 2 3 ) + values: #( 3 6 9 ) + name: 'max'. + + actual := dataFrame applyToAllColumns: #max. + self assert: actual equals: expected +] + { #category : #tests } DataFrameTest >> testAsArray [ @@ -328,6 +369,20 @@ DataFrameTest >> testAsArrayOfRows [ self assert: df asArrayOfRows equals: (expected collect: [ :e | e asArray ]) ] +{ #category : #tests } +DataFrameTest >> testAsArrayOfRowsWithName [ + + | expected | + expected := { + #( 'A' 'Barcelona' 1.609 true ) asArray. + #( 'B' 'Dubai' 2.789 true ) asArray. + #( 'C' 'London' 8.788 false ) asArray }. + + self + assert: df asArrayOfRowsWithName + equals: expected asOrderedCollection +] + { #category : #tests } DataFrameTest >> testAt [ @@ -1007,6 +1062,22 @@ DataFrameTest >> testCopy2 [ self assert: copy numberOfColumns equals: 3 ] +{ #category : #tests } +DataFrameTest >> testCopyReplaceIn2DCollectionBy [ + + | expected | + expected := DataFrame withRows: + #( #( Barcelona 1.609 true ) + #( Dubai 2.789 true ) + #( London 8.788 true ) ). + + expected rowNames: #( A B C ). + expected columnNames: #( City Population BeenThere ). + + df copyReplace: false in2DCollectionBy: #( true true true ). + self assert: df equals: expected +] + { #category : #tests } DataFrameTest >> testCreateDataFrameWith3ColumnsAndNoRows [ | dataFrame | @@ -1716,6 +1787,18 @@ DataFrameTest >> testFindAllIndicesOfAtColumnFloat [ self assert: (df findAllIndicesOf: 2.789 atColumn: 'Population') equals: #(2 4) asOrderedCollection ] +{ #category : #tests } +DataFrameTest >> testFirst [ + + | actual expected | + expected := DataSeries + withKeys: #( 'City' 'Population' 'BeenThere' ) + values: #( 'Barcelona' 1.609 true ) + name: 'A'. + actual := df first. + self assert: actual equals: expected +] + { #category : #replacing } DataFrameTest >> testHasNils [ @@ -1913,6 +1996,35 @@ Data columns (total 3 columns): ' ] +{ #category : #tests } +DataFrameTest >> testInitializeColumns [ + + | anArrayOfColumns dataFrame | + anArrayOfColumns := #( #( 'Barcelona' 'Dubai' 'London' ) + #( 1.609 2.789 8.788 ) #( true true false ) ). + dataFrame := DataFrame new. + dataFrame initializeColumns: anArrayOfColumns. + dataFrame rowNames: #( 'A' 'B' 'C' ). + dataFrame columnNames: #( 'City' 'Population' 'BeenThere' ). + + self assert: dataFrame equals: df +] + +{ #category : #tests } +DataFrameTest >> testInitializeRows [ + + | anArrayOfRows dataFrame | + anArrayOfRows := #( #( 'Barcelona' 1.609 true ) + #( 'Dubai' 2.789 true ) + #( 'London' 8.788 false ) ). + dataFrame := DataFrame new. + dataFrame initializeRows: anArrayOfRows. + dataFrame rowNames: #( 'A' 'B' 'C' ). + dataFrame columnNames: #( 'City' 'Population' 'BeenThere' ). + + self assert: dataFrame equals: df +] + { #category : #tests } DataFrameTest >> testInjectInto [ | numericDataFrame actual expected | From 8cf504b54c042400605f62e3fb6019d2fdb2bbad Mon Sep 17 00:00:00 2001 From: Joshua-Dias-Barreto Date: Mon, 29 May 2023 12:14:34 +0530 Subject: [PATCH 2/2] Formatted tests for readability. --- src/DataFrame-Tests/DataFrameTest.class.st | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/DataFrame-Tests/DataFrameTest.class.st b/src/DataFrame-Tests/DataFrameTest.class.st index 973ea4b8..32fbeee7 100644 --- a/src/DataFrame-Tests/DataFrameTest.class.st +++ b/src/DataFrame-Tests/DataFrameTest.class.st @@ -301,15 +301,11 @@ DataFrameTest >> testApplyElementwise [ | dataFrame expected | dataFrame := DataFrame withRows: - #( #( 1.1 1.7 1.3 ) - #( 2.2 2.4 2.8 ) - #( 3.5 3.2 3.3 ) ) + #( #( 1.1 1.7 1.3 ) #( 2.2 2.4 2.8 ) #( 3.5 3.2 3.3 ) ) rowNames: #( A B C ) columnNames: #( 1 2 3 ). expected := DataFrame - withRows: #( #( 1 1 1 ) - #( 2 2 2 ) - #( 3 3 3 ) ) + withRows: #( #( 1 1 1 ) #( 2 2 2 ) #( 3 3 3 ) ) rowNames: #( A B C ) columnNames: #( 1 2 3 ). @@ -322,9 +318,7 @@ DataFrameTest >> testApplyToAllColumns [ | dataFrame actual expected | dataFrame := DataFrame - withRows: #( #( 1 4 7 ) - #( 2 5 8 ) - #( 3 6 9 ) ) + withRows: #( #( 1 4 7 ) #( 2 5 8 ) #( 3 6 9 ) ) rowNames: #( A B C ) columnNames: #( 1 2 3 ). expected := DataSeries @@ -1067,8 +1061,7 @@ DataFrameTest >> testCopyReplaceIn2DCollectionBy [ | expected | expected := DataFrame withRows: - #( #( Barcelona 1.609 true ) - #( Dubai 2.789 true ) + #( #( Barcelona 1.609 true ) #( Dubai 2.789 true ) #( London 8.788 true ) ). expected rowNames: #( A B C ). @@ -2015,8 +2008,7 @@ DataFrameTest >> testInitializeRows [ | anArrayOfRows dataFrame | anArrayOfRows := #( #( 'Barcelona' 1.609 true ) - #( 'Dubai' 2.789 true ) - #( 'London' 8.788 false ) ). + #( 'Dubai' 2.789 true ) #( 'London' 8.788 false ) ). dataFrame := DataFrame new. dataFrame initializeRows: anArrayOfRows. dataFrame rowNames: #( 'A' 'B' 'C' ).