|
7 | 7 | #category : #'DataFrame-Tests-Core'
|
8 | 8 | }
|
9 | 9 |
|
| 10 | +{ #category : #private } |
| 11 | +DataFrameTest >> expectedShuffledDataFrameWithSeedOne [ |
| 12 | + "In theory, shuffling an array with a fixed random seed should produce the same result across different versions of Pharo and the same implementation of the random number generator. The purpose of using a fixed seed is to make the random number generation deterministic, meaning that given the same seed, the sequence of random numbers generated will be the same every time. |
| 13 | + There is a difference in the RNG used in Pharo 12, which uses the primitive 231, and the previous Pharo versions, which used a native implementation in privateNextSeed. |
| 14 | + The change was introduced in this commit: https://github.com/pharo-project/pharo/commit/bf22496dbd0996ee470c9f85a7cc076e01dff57f |
| 15 | + So we answer different data frames as the result ordering changes because of this implementation change" |
| 16 | + |
| 17 | + | expected | |
| 18 | + expected := SystemVersion current major >= 12 |
| 19 | + ifTrue: [ |
| 20 | + (DataFrame withRows: #( |
| 21 | + ('Barcelona' 1.609 true) |
| 22 | + ('London' 8.788 false) |
| 23 | + ('Dubai' 2.789 true)) |
| 24 | + rowNames: #( 'A' 'C' 'B')) |
| 25 | + yourself ] |
| 26 | + ifFalse: [ |
| 27 | + (DataFrame withRows: #( |
| 28 | + ('Dubai' 2.789 true) |
| 29 | + ('London' 8.788 false) |
| 30 | + ('Barcelona' 1.609 true)) |
| 31 | + rowNames: #('B' 'C' 'A')) |
| 32 | + yourself ]. |
| 33 | + expected columnNames: #( 'City' 'Population' 'BeenThere' ). |
| 34 | + ^ expected |
| 35 | + |
| 36 | +] |
| 37 | + |
| 38 | +{ #category : #private } |
| 39 | +DataFrameTest >> expectedShuffledDataFrameWithSeedTwo [ |
| 40 | + "In theory, shuffling an array with a fixed random seed should produce the same result across different versions of Pharo and the same implementation of the random number generator. The purpose of using a fixed seed is to make the random number generation deterministic, meaning that given the same seed, the sequence of random numbers generated will be the same every time. |
| 41 | + There is a difference in the RNG used in Pharo 12, which uses the primitive 231, and the previous Pharo versions, which used a native implementation in privateNextSeed. |
| 42 | + The change was introduced in this commit: https://github.com/pharo-project/pharo/commit/bf22496dbd0996ee470c9f85a7cc076e01dff57f |
| 43 | + So we answer different data frames as the result ordering changes because of this implementation change" |
| 44 | + |
| 45 | + | expected | |
| 46 | + expected := SystemVersion current major >= 12 |
| 47 | + ifTrue: [ |
| 48 | + (DataFrame withRows: #( |
| 49 | + ('Dubai' 2.789 true) |
| 50 | + ('Barcelona' 1.609 true) |
| 51 | + ('London' 8.788 false) ) |
| 52 | + rowNames: #('B' 'A' 'C')) |
| 53 | + yourself ] |
| 54 | + ifFalse: [ |
| 55 | + (DataFrame withRows: #( |
| 56 | + ('London' 8.788 false) |
| 57 | + ('Barcelona' 1.609 true) |
| 58 | + ('Dubai' 2.789 true)) |
| 59 | + rowNames: #('C' 'A' 'B')) |
| 60 | + yourself ]. |
| 61 | + expected columnNames: #( 'City' 'Population' 'BeenThere' ). |
| 62 | + ^ expected |
| 63 | + |
| 64 | +] |
| 65 | + |
10 | 66 | { #category : #running }
|
11 | 67 | DataFrameTest >> setUp [
|
12 | 68 |
|
@@ -920,6 +976,19 @@ DataFrameTest >> testColumns [
|
920 | 976 | self assert: df columns equals: expectedCollection
|
921 | 977 | ]
|
922 | 978 |
|
| 979 | +{ #category : #tests } |
| 980 | +DataFrameTest >> testColumnsAllBut [ |
| 981 | + |
| 982 | + | expectedDataFrame | |
| 983 | + expectedDataFrame := DataFrame withRows: #( #( 'Barcelona' 1.609 ) #( 'Dubai' 2.789 ) #( 'London' 8.788 ) ). |
| 984 | + expectedDataFrame rowNames: #( 'A' 'B' 'C' ). |
| 985 | + expectedDataFrame columnNames: #( 'City' 'Population'). |
| 986 | + |
| 987 | + self |
| 988 | + assert: (df columnsAllBut: #(BeenThere)) |
| 989 | + equals: expectedDataFrame |
| 990 | +] |
| 991 | + |
923 | 992 | { #category : #tests }
|
924 | 993 | DataFrameTest >> testColumnsAt [
|
925 | 994 |
|
@@ -5164,6 +5233,20 @@ DataFrameTest >> testSelectEmptyDataFrame [
|
5164 | 5233 | self assert: actual equals: expected
|
5165 | 5234 | ]
|
5166 | 5235 |
|
| 5236 | +{ #category : #tests } |
| 5237 | +DataFrameTest >> testShuffledWithSeed [ |
| 5238 | + |
| 5239 | + | expected | |
| 5240 | + |
| 5241 | + expected := self expectedShuffledDataFrameWithSeedOne. |
| 5242 | + self assert: (df shuffleWithSeed: 1) equals: expected. |
| 5243 | + |
| 5244 | + expected := self expectedShuffledDataFrameWithSeedTwo. |
| 5245 | + self assert: (df shuffleWithSeed: 2) equals: expected. |
| 5246 | + |
| 5247 | + |
| 5248 | +] |
| 5249 | + |
5167 | 5250 | { #category : #tests }
|
5168 | 5251 | DataFrameTest >> testSortBy [
|
5169 | 5252 |
|
|
0 commit comments