author | Claus Gittinger <cg@exept.de> |
Tue, 09 Jul 2019 18:53:03 +0200 | |
changeset 2327 | bf482d49aeaf |
parent 2183 | d680bb90df4b |
child 2402 | 87d0eacf18b9 |
permissions | -rw-r--r-- |
1447 | 1 |
"{ Package: 'stx:goodies/regression' }" |
115 | 2 |
|
157 | 3 |
"{ NameSpace: RegressionTests }" |
4 |
||
115 | 5 |
TestCase subclass:#CollectionTests |
293 | 6 |
instanceVariableNames:'empty nonEmpty' |
115 | 7 |
classVariableNames:'' |
8 |
poolDictionaries:'' |
|
1054 | 9 |
category:'tests-Regression-Collections' |
115 | 10 |
! |
11 |
||
212 | 12 |
Object subclass:#SortTestData |
13 |
instanceVariableNames:'value order' |
|
14 |
classVariableNames:'' |
|
15 |
poolDictionaries:'' |
|
16 |
privateIn:CollectionTests |
|
17 |
! |
|
18 |
||
115 | 19 |
!CollectionTests class methodsFor:'documentation'! |
20 |
||
585 | 21 |
coveredClasses |
22 |
^ Collection withAllSubclasses |
|
23 |
! |
|
24 |
||
115 | 25 |
documentation |
26 |
" |
|
27 |
documentation to be added. |
|
28 |
||
29 |
[author:] |
|
1447 | 30 |
Claus Gittinger (cg@alan) |
115 | 31 |
|
32 |
[see also:] |
|
33 |
||
34 |
[instance variables:] |
|
35 |
||
36 |
[class variables:] |
|
37 |
" |
|
38 |
! |
|
39 |
||
40 |
history |
|
41 |
"Created: / 8.11.2001 / 08:17:09 / cg" |
|
42 |
! ! |
|
43 |
||
301 | 44 |
!CollectionTests methodsFor:'helpers'! |
45 |
||
655 | 46 |
checkSorted:aSortedCollection with:sortBlock against:anOriginalCollection |
47 |
|first| |
|
48 |
||
49 |
self assert:aSortedCollection size = anOriginalCollection size. |
|
50 |
||
51 |
"is it sorted?" |
|
52 |
first := true. |
|
53 |
aSortedCollection inject:nil into:[:last :each| |
|
1447 | 54 |
first ifTrue:[first := false] |
55 |
ifFalse:[self assert:(sortBlock value:last value:each)]. each]. |
|
655 | 56 |
|
57 |
"same elements as in original?" |
|
58 |
self assert:(aSortedCollection asBag = anOriginalCollection asBag). |
|
59 |
! |
|
60 |
||
301 | 61 |
collectedDoArgsOf:aCollection |
62 |
|collectedDoArgs| |
|
63 |
||
64 |
collectedDoArgs := OrderedCollection new. |
|
65 |
aCollection do:[:each | collectedDoArgs add:each]. |
|
66 |
^ collectedDoArgs |
|
67 |
! ! |
|
68 |
||
2183 | 69 |
!CollectionTests methodsFor:'initialize / release'! |
293 | 70 |
|
71 |
setUp |
|
1447 | 72 |
empty := Set new. |
73 |
nonEmpty := OrderedCollection with: #x. |
|
293 | 74 |
! ! |
75 |
||
1396 | 76 |
!CollectionTests methodsFor:'tests-byteArray'! |
77 |
||
78 |
testByteArrayReverse |
|
79 |
1 to:1024 do:[:i| |
|
1447 | 80 |
|bytes test rBytes| |
1396 | 81 |
|
1447 | 82 |
bytes := ((1 to:i) asArray collect:[:i | i bitAnd:255]) asByteArray. |
83 |
test := ((i to:1 by:-1) asArray collect:[:i | i bitAnd:255]) asByteArray. |
|
84 |
rBytes := bytes copy. |
|
85 |
self assert:(rBytes reverse = test). |
|
1396 | 86 |
|
1447 | 87 |
rBytes := bytes copy. |
88 |
self assert:(rBytes reverse reverse = bytes). |
|
1396 | 89 |
]. |
90 |
! |
|
91 |
||
92 |
testByteArrayReversed |
|
93 |
1 to:1024 do:[:i| |
|
1447 | 94 |
|bytes test rBytes| |
1396 | 95 |
|
1447 | 96 |
bytes := ((1 to:i) asArray collect:[:i | i bitAnd:255]) asByteArray. |
97 |
test := ((i to:1 by:-1) asArray collect:[:i | i bitAnd:255]) asByteArray. |
|
98 |
self assert:(bytes reversed = test). |
|
1396 | 99 |
|
1447 | 100 |
self assert:(bytes reversed reversed = bytes). |
1396 | 101 |
]. |
102 |
! ! |
|
103 |
||
264 | 104 |
!CollectionTests methodsFor:'tests-dictionary'! |
115 | 105 |
|
106 |
testDictionary01 |
|
301 | 107 |
|d v1 v2 v3 ret| |
115 | 108 |
|
109 |
d := Dictionary new. |
|
110 |
d at:1 put:(v1 := 'one'). |
|
111 |
d at:2 put:(v2 := 'two'). |
|
112 |
d at:3 put:(v3 := 'three'). |
|
113 |
||
114 |
self assert: ( d size == 3 ). |
|
301 | 115 |
|
757
2d776bef407b
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
677
diff
changeset
|
116 |
self assert:(ret := self collectedDoArgsOf:d) asSet = #('one' 'two' 'three') asSet. |
301 | 117 |
self assert:(ret := d collect:[:each | each]) = #('one' 'two' 'three') asBag. |
118 |
self assert:(ret := d select:[:each | true]) = (Dictionary withAssociations:(Array with:(1->'one') with:(2->'two') with:(3->'three'))). |
|
119 |
||
115 | 120 |
self assert: ( (d at:1) == v1 ). |
121 |
self assert: ( (d at:2) == v2 ). |
|
122 |
self assert: ( (d at:3) == v3 ). |
|
123 |
||
124 |
d at:3 put:(v3 := 'drei'). |
|
125 |
||
126 |
self assert: ( d size == 3 ). |
|
127 |
||
128 |
self assert: ( (d at:1) == v1 ). |
|
129 |
self assert: ( (d at:2) == v2 ). |
|
130 |
self assert: ( (d at:3) == v3 ). |
|
131 |
||
132 |
self assert: ( (d keyAtValue:v1) = 1 ). |
|
133 |
||
134 |
" |
|
135 |
self basicNew testDictionary01 |
|
136 |
" |
|
585 | 137 |
|
138 |
"Modified: / 04-07-2011 / 19:28:39 / cg" |
|
264 | 139 |
! ! |
140 |
||
141 |
!CollectionTests methodsFor:'tests-general'! |
|
142 |
||
615 | 143 |
doTestDictionaryLikeAddRemoveOperationsIn:aClass |
144 |
|coll| |
|
145 |
||
146 |
coll := aClass new. |
|
147 |
||
148 |
self assert: ( coll size == 0 ). |
|
149 |
self assert: ( coll isEmpty ). |
|
150 |
self assert: ( coll notEmpty not ). |
|
151 |
self assert: ( coll isEmptyOrNil ). |
|
152 |
self assert: ( coll notEmptyOrNil not ). |
|
153 |
||
154 |
coll at:1 put:'one'. |
|
155 |
||
156 |
self assert: ( coll size == 1 ). |
|
157 |
self assert: ( coll isEmpty not). |
|
158 |
self assert: ( coll notEmpty ). |
|
159 |
self assert: ( coll isEmptyOrNil not ). |
|
160 |
self assert: ( coll notEmptyOrNil ). |
|
161 |
||
162 |
coll at:2 put:'two'. |
|
163 |
||
164 |
self assert: ( coll size == 2 ). |
|
165 |
self assert: ( coll isEmpty not). |
|
166 |
self assert: ( coll notEmpty ). |
|
167 |
self assert: ( coll isEmptyOrNil not ). |
|
168 |
self assert: ( coll notEmptyOrNil ). |
|
169 |
||
170 |
coll removeKey:2. |
|
171 |
self assert: ( coll size == 1 ). |
|
172 |
self assert: ( coll isEmpty not). |
|
173 |
self assert: ( coll notEmpty ). |
|
174 |
self assert: ( coll isEmptyOrNil not ). |
|
175 |
self assert: ( coll notEmptyOrNil ). |
|
176 |
||
177 |
coll removeKey:1. |
|
178 |
self assert: ( coll size == 0 ). |
|
179 |
self assert: ( coll isEmpty ). |
|
180 |
self assert: ( coll notEmpty not ). |
|
181 |
self assert: ( coll isEmptyOrNil ). |
|
182 |
self assert: ( coll notEmptyOrNil not ). |
|
183 |
||
184 |
" |
|
185 |
self basicNew doTestDictionaryLikeAddRemoveOperations |
|
186 |
" |
|
187 |
||
188 |
"Created: / 08-08-2011 / 16:01:14 / cg" |
|
189 |
! |
|
190 |
||
191 |
doTestGeneralAddRemoveOperationsIn:aClass |
|
192 |
|coll| |
|
193 |
||
194 |
coll := aClass new. |
|
195 |
||
196 |
self assert: ( coll size == 0 ). |
|
197 |
self assert: ( coll isEmpty ). |
|
198 |
self assert: ( coll notEmpty not ). |
|
199 |
self assert: ( coll isEmptyOrNil ). |
|
200 |
self assert: ( coll notEmptyOrNil not ). |
|
201 |
||
202 |
coll add:1. |
|
203 |
||
204 |
self assert: ( coll size == 1 ). |
|
205 |
self assert: ( coll isEmpty not). |
|
206 |
self assert: ( coll notEmpty ). |
|
207 |
self assert: ( coll isEmptyOrNil not ). |
|
208 |
self assert: ( coll notEmptyOrNil ). |
|
209 |
||
210 |
coll add:2. |
|
211 |
||
212 |
self assert: ( coll size == 2 ). |
|
213 |
self assert: ( coll isEmpty not). |
|
214 |
self assert: ( coll notEmpty ). |
|
215 |
self assert: ( coll isEmptyOrNil not ). |
|
216 |
self assert: ( coll notEmptyOrNil ). |
|
217 |
||
218 |
coll remove:2. |
|
219 |
self assert: ( coll size == 1 ). |
|
220 |
self assert: ( coll isEmpty not). |
|
221 |
self assert: ( coll notEmpty ). |
|
222 |
self assert: ( coll isEmptyOrNil not ). |
|
223 |
self assert: ( coll notEmptyOrNil ). |
|
224 |
||
225 |
coll remove:1. |
|
226 |
self assert: ( coll size == 0 ). |
|
227 |
self assert: ( coll isEmpty ). |
|
228 |
self assert: ( coll notEmpty not ). |
|
229 |
self assert: ( coll isEmptyOrNil ). |
|
230 |
self assert: ( coll notEmptyOrNil not ). |
|
231 |
||
232 |
" |
|
233 |
self basicNew testGeneralOperations |
|
234 |
" |
|
235 |
||
236 |
"Created: / 08-08-2011 / 16:00:06 / cg" |
|
237 |
! |
|
238 |
||
264 | 239 |
doTestGeneralCollectionOperationsIn:aClass |
240 |
|coll| |
|
241 |
||
242 |
coll := aClass new. |
|
243 |
||
244 |
self assert: ( coll size == 0 ). |
|
245 |
self assert: ( coll isEmpty ). |
|
246 |
self assert: ( coll notEmpty not ). |
|
247 |
self assert: ( coll isEmptyOrNil ). |
|
248 |
self assert: ( coll notEmptyOrNil not ). |
|
249 |
||
250 |
self should: [ coll first ] raise:Error. |
|
251 |
self should: [ coll last ] raise:Error. |
|
252 |
self should: [ (coll at:1) ] raise:Error. |
|
253 |
||
254 |
self assert: ( (coll includes:0) not ). |
|
255 |
||
256 |
" |
|
257 |
self basicNew testGeneralOperations |
|
258 |
" |
|
156 | 259 |
! |
260 |
||
677
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
261 |
doTestSequentialCollectionOperationsIn:aClass |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
262 |
|coll1 coll2| |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
263 |
|
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
264 |
coll1 := self protoCollectionFor: aClass. |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
265 |
|
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
266 |
self assert: ( coll1 size > 0 ). |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
267 |
self assert: ( coll1 isEmpty not ). |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
268 |
self assert: ( coll1 notEmpty ). |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
269 |
self assert: ( coll1 isEmptyOrNil not ). |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
270 |
self assert: ( coll1 notEmptyOrNil ). |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
271 |
|
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
272 |
self assert: ( coll1 first = (coll1 at:1) ). |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
273 |
self assert: ( coll1 last = (coll1 at:(coll1 size)) ). |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
274 |
|
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
275 |
self assert: ( coll1 = coll1 ). |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
276 |
self assert: ( coll1 ~= coll1 ) not. |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
277 |
coll2 := coll1 copy. |
1043
b95983db1639
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
278 |
self assert: (coll1 size == coll2 size). |
b95983db1639
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
279 |
1 to:coll1 size do:[:i | |
1447 | 280 |
"/ coll1 at:10 |
281 |
"/ coll2 at:10 |
|
282 |
self assert:(coll1 at:i) = (coll2 at:i). |
|
1043
b95983db1639
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
283 |
]. |
677
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
284 |
self assert: ( coll2 = coll1 ). |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
285 |
|
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
286 |
coll2 replaceFrom:1 to:coll2 size with:coll1 startingAt:1. |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
287 |
self assert: ( coll2 = coll1 ). |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
288 |
|
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
289 |
"overlapping copy" |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
290 |
coll2 replaceFrom:2 to:coll2 size with:coll2 startingAt:1. |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
291 |
coll2 replaceFrom:1 to:coll2 size-1 with:coll2 startingAt:2. |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
292 |
coll2 at:(coll2 size) put:(coll1 at:coll1 size). |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
293 |
self assert: ( coll2 = coll1 ). |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
294 |
|
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
295 |
" |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
296 |
self basicNew testSequentialCollectionOperations |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
297 |
" |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
298 |
|
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
299 |
"Created: / 08-05-2012 / 10:50:08 / cg" |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
300 |
! |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
301 |
|
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
302 |
protoCollectionFor: aClass |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
303 |
aClass == BooleanArray ifTrue: [ |
1447 | 304 |
^ BooleanArray withAll:#(true false true true false false true false false true) |
677
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
305 |
]. |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
306 |
aClass == BitArray ifTrue: [ |
1447 | 307 |
^ BitArray withAll:#(1 0 1 1 0 0 1 0 0 1) |
1040
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
308 |
]. |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
309 |
aClass == ByteArray ifTrue: [ |
1447 | 310 |
^ ByteArray withAll:#(1 2 3 4 16rFC 16rFD 16rFE 16rFF) |
677
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
311 |
]. |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
312 |
aClass == String ifTrue: [ |
1447 | 313 |
^ 'abcdefghijklmnopqrstuvwxyz' |
677
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
314 |
]. |
1040
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
315 |
(aClass includesBehavior:CharacterArray) ifTrue:[ |
1447 | 316 |
^ 'abcdefghijklmnopqrstuvwxyz' as: aClass |
1040
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
317 |
]. |
1447 | 318 |
(aClass includesBehavior:AbstractNumberVector) ifTrue:[ |
319 |
(aClass includesBehavior:UnboxedIntegerArray) ifTrue:[ |
|
320 |
^ #(1 2 3 4 5 6 7 8 9 10) as: aClass |
|
321 |
]. |
|
322 |
^ #(1.0 2 3.0 4 5.0 6 7.0 8 9.0 10) as: aClass |
|
1040
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
323 |
]. |
1447 | 324 |
^ #(1 true 2.0 false 3 nil 4.0 5 6.0 7 8.0 9 10.0) as: aClass |
677
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
325 |
|
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
326 |
" |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
327 |
self basicNew testSequentialCollectionOperations |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
328 |
" |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
329 |
|
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
330 |
"Created: / 08-05-2012 / 10:50:50 / cg" |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
331 |
! |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
332 |
|
615 | 333 |
testDictionaryLikeAddRemoveOperations |
334 |
|classes| |
|
335 |
||
336 |
classes := OrderedCollection new. |
|
1447 | 337 |
classes |
338 |
add:Dictionary; |
|
339 |
add:IdentityDictionary; |
|
340 |
add:OrderedDictionary; |
|
341 |
add:BTree. |
|
615 | 342 |
|
343 |
classes do:[:eachClass | |
|
1447 | 344 |
self doTestDictionaryLikeAddRemoveOperationsIn:eachClass |
615 | 345 |
]. |
346 |
||
347 |
" |
|
348 |
self basicNew testDictionaryLikeAddRemoveOperations |
|
349 |
" |
|
350 |
||
351 |
"Created: / 08-08-2011 / 15:59:52 / cg" |
|
352 |
! |
|
353 |
||
354 |
testGeneralAddRemoveOperations |
|
355 |
|classes| |
|
356 |
||
357 |
classes := OrderedCollection new. |
|
1447 | 358 |
classes |
359 |
"/ add:RunArray; |
|
360 |
add:Bag; |
|
361 |
add:Set; |
|
362 |
add:IdentitySet; |
|
363 |
"/add:Dictionary; |
|
364 |
"/add:IdentityDictionary; |
|
365 |
add:OrderedCollection; |
|
366 |
add:SortedCollection; |
|
367 |
"/add:Queue; |
|
368 |
"/add:Stack; |
|
369 |
add:SortedCollection; |
|
370 |
"/add:OrderedDictionary; |
|
371 |
add:OrderedSet. |
|
372 |
"/add:BTree. |
|
615 | 373 |
|
374 |
classes do:[:eachClass | |
|
1447 | 375 |
self doTestGeneralAddRemoveOperationsIn:eachClass |
615 | 376 |
]. |
377 |
||
378 |
" |
|
379 |
self basicNew testGeneralAddRemoveOperations |
|
380 |
" |
|
381 |
||
382 |
"Created: / 08-08-2011 / 15:59:02 / cg" |
|
383 |
! |
|
384 |
||
264 | 385 |
testGeneralOperations |
386 |
|classes| |
|
387 |
||
388 |
classes := OrderedCollection new. |
|
1447 | 389 |
classes |
390 |
add:RunArray; |
|
391 |
add:Bag; |
|
392 |
add:Set; |
|
393 |
add:IdentitySet; |
|
394 |
add:Dictionary; |
|
395 |
add:IdentityDictionary; |
|
396 |
add:OrderedCollection; |
|
397 |
add:SortedCollection; |
|
398 |
add:Queue; |
|
399 |
add:Stack; |
|
400 |
add:SortedCollection; |
|
401 |
add:OrderedDictionary; |
|
402 |
add:OrderedSet; |
|
403 |
add:BTree. |
|
264 | 404 |
|
405 |
classes do:[:eachClass | |
|
1447 | 406 |
self doTestGeneralCollectionOperationsIn:eachClass |
264 | 407 |
]. |
408 |
||
409 |
" |
|
410 |
self basicNew testGeneralOperations |
|
411 |
" |
|
615 | 412 |
|
413 |
"Modified: / 08-08-2011 / 15:53:16 / cg" |
|
677
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
414 |
! |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
415 |
|
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
416 |
testSequentialCollectionOperations |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
417 |
|classes| |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
418 |
|
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
419 |
classes := OrderedCollection new. |
1447 | 420 |
classes |
421 |
add:OrderedCollection; |
|
422 |
add:Array; |
|
423 |
add:String; |
|
424 |
add:ByteArray; |
|
425 |
add:WordArray; |
|
426 |
add:IntegerArray; |
|
427 |
add:LongIntegerArray; |
|
428 |
add:SignedWordArray; |
|
429 |
add:SignedIntegerArray; |
|
430 |
add:SignedLongIntegerArray; |
|
431 |
add:FloatArray; |
|
432 |
add:DoubleArray; |
|
433 |
add:HalfFloatArray; |
|
434 |
add:TwoByteString; |
|
435 |
add:Unicode16String; |
|
436 |
add:Unicode32String; |
|
437 |
add:BooleanArray; |
|
438 |
add:BitArray. |
|
677
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
439 |
|
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
440 |
classes do:[:eachClass | |
1447 | 441 |
self doTestSequentialCollectionOperationsIn:eachClass |
677
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
442 |
]. |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
443 |
|
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
444 |
" |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
445 |
self basicNew testSequentialCollectionOperations |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
446 |
" |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
447 |
|
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
448 |
"Created: / 08-05-2012 / 10:48:40 / cg" |
1040
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
449 |
! |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
450 |
|
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
451 |
testSpecialArrayClasses |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
452 |
|a| |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
453 |
|
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
454 |
a := #(1 2 3 4 5) asWordArray. |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
455 |
self assert:(a at:1) == 1. |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
456 |
self assert:(a at:a size) == 5. |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
457 |
self assert:(a first) == 1. |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
458 |
self assert:(a last) == 5. |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
459 |
|
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
460 |
a := #(1 2 3 4 5) asIntegerArray. |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
461 |
self assert:(a at:1) == 1. |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
462 |
self assert:(a at:a size) == 5. |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
463 |
self assert:(a first) == 1. |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
464 |
self assert:(a last) == 5. |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
465 |
|
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
466 |
a := #(1 2 3 4 5) asLongIntegerArray. |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
467 |
self assert:(a at:1) == 1. |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
468 |
self assert:(a at:a size) == 5. |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
469 |
self assert:(a first) == 1. |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
470 |
self assert:(a last) == 5. |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
471 |
|
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
472 |
" |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
473 |
self basicNew testSpecialArrayClasses |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
474 |
" |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
475 |
|
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
476 |
"Created: / 08-05-2012 / 10:48:40 / cg" |
1041
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
477 |
! |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
478 |
|
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
479 |
testSpecialArrayClasses2 |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
480 |
|a| |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
481 |
|
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
482 |
a := #(1 2 3 4 5) asFloatArray. |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
483 |
self assert:(a at:1) = 1.0. |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
484 |
self assert:(a at:a size) = 5.0. |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
485 |
self assert:(a first) = 1.0. |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
486 |
self assert:(a last) = 5.0. |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
487 |
|
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
488 |
a := #(1 2 3 4 5) asDoubleArray. |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
489 |
self assert:(a at:1) = 1.0. |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
490 |
self assert:(a at:a size) = 5.0. |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
491 |
self assert:(a first) = 1.0. |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
492 |
self assert:(a last) = 5.0. |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
493 |
|
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
494 |
a := #(1 2 3 4 5) asHalfFloatArray. |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
495 |
self assert:(a at:1) = 1.0. |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
496 |
self assert:(a at:a size) = 5.0. |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
497 |
self assert:(a first) = 1.0. |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
498 |
self assert:(a last) = 5.0. |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
499 |
|
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
500 |
" |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
501 |
self basicNew testSpecialArrayClasses2 |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
502 |
" |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
503 |
|
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
504 |
"Created: / 08-05-2012 / 10:48:40 / cg" |
264 | 505 |
! ! |
506 |
||
507 |
!CollectionTests methodsFor:'tests-interval'! |
|
508 |
||
162 | 509 |
testInterval01 |
663
437a6c228d34
added interval enumeration test
Claus Gittinger <cg@exept.de>
parents:
657
diff
changeset
|
510 |
|i1 i2 enumeratedValues| |
162 | 511 |
|
644 | 512 |
i1 := 1 to:10. |
162 | 513 |
|
644 | 514 |
self assert: ( i1 size == 10 ). |
162 | 515 |
|
644 | 516 |
self assert: ( i1 includes:1 ). |
517 |
self assert: ( i1 includes:10 ). |
|
162 | 518 |
|
644 | 519 |
self assert: ( i1 min == 1 ). |
520 |
self assert: ( i1 max == 10 ). |
|
162 | 521 |
|
522 |
"cannot add/remove" |
|
644 | 523 |
self should:[i1 add:99] raise:Error. |
524 |
self should:[i1 remove:10] raise:Error. |
|
525 |
||
526 |
i2 := 2 to:20 by:2. |
|
527 |
self assert: ( i2 size == 10 ). |
|
528 |
||
529 |
self assert: ( i2 includes:0 ) not. |
|
530 |
self assert: ( i2 includes:1 ) not. |
|
531 |
self assert: ( i2 includes:2 ). |
|
532 |
self assert: ( i2 includes:3 ) not. |
|
533 |
self assert: ( i2 includes:10 ). |
|
534 |
self assert: ( i2 includes:19 ) not. |
|
535 |
self assert: ( i2 includes:20 ). |
|
536 |
self assert: ( i2 includes:21 ) not. |
|
537 |
self assert: ( i2 includes:22 ) not. |
|
538 |
||
539 |
self assert: ( i2 min == 2 ). |
|
540 |
self assert: ( i2 max == 20 ). |
|
541 |
||
542 |
self assert: ( i2 keys asArray = (1 to:10) asArray ). |
|
162 | 543 |
|
663
437a6c228d34
added interval enumeration test
Claus Gittinger <cg@exept.de>
parents:
657
diff
changeset
|
544 |
enumeratedValues := OrderedCollection new. |
437a6c228d34
added interval enumeration test
Claus Gittinger <cg@exept.de>
parents:
657
diff
changeset
|
545 |
i1 do:[:each | enumeratedValues add:each ]. |
437a6c228d34
added interval enumeration test
Claus Gittinger <cg@exept.de>
parents:
657
diff
changeset
|
546 |
self assert:(enumeratedValues size == 10). |
437a6c228d34
added interval enumeration test
Claus Gittinger <cg@exept.de>
parents:
657
diff
changeset
|
547 |
self assert:(enumeratedValues asArray = #(1 2 3 4 5 6 7 8 9 10)). |
437a6c228d34
added interval enumeration test
Claus Gittinger <cg@exept.de>
parents:
657
diff
changeset
|
548 |
|
437a6c228d34
added interval enumeration test
Claus Gittinger <cg@exept.de>
parents:
657
diff
changeset
|
549 |
enumeratedValues := OrderedCollection new. |
437a6c228d34
added interval enumeration test
Claus Gittinger <cg@exept.de>
parents:
657
diff
changeset
|
550 |
i2 do:[:each | enumeratedValues add:each ]. |
437a6c228d34
added interval enumeration test
Claus Gittinger <cg@exept.de>
parents:
657
diff
changeset
|
551 |
self assert:(enumeratedValues size == 10). |
437a6c228d34
added interval enumeration test
Claus Gittinger <cg@exept.de>
parents:
657
diff
changeset
|
552 |
self assert:(enumeratedValues asArray = #(2 4 6 8 10 12 14 16 18 20)). |
437a6c228d34
added interval enumeration test
Claus Gittinger <cg@exept.de>
parents:
657
diff
changeset
|
553 |
|
666 | 554 |
self assert: (i1 collect:[:el | el even]) asArray = #(false true false true false true false true false true). |
555 |
self assert: (i2 collect:[:el | el even]) asArray = #(true true true true true true true true true true). |
|
664 | 556 |
|
162 | 557 |
" |
558 |
self basicNew testInterval01 |
|
559 |
" |
|
644 | 560 |
|
664 | 561 |
"Modified: / 03-05-2012 / 18:36:41 / cg" |
264 | 562 |
! ! |
563 |
||
301 | 564 |
!CollectionTests methodsFor:'tests-orderedCollection'! |
565 |
||
656
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
566 |
testMergeSortStability01 |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
567 |
"Verify that the sort is stable" |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
568 |
|
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
569 |
| testData lastTestData errs col| |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
570 |
|
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
571 |
testData := OrderedCollection new. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
572 |
testData addAll: ((100 to: 1 by: -1) collect: [ :n | SortTestData new value: n ]). |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
573 |
testData addAll: ((100 to: 1 by: -1) collect: [ :n | SortTestData new value: n ]). |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
574 |
testData addAll: ((100 to: 1 by: -1) collect: [ :n | SortTestData new value: n ]). |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
575 |
testData keysAndValuesDo:[:idx :each| each order: idx ]. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
576 |
|
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
577 |
col := testData copy. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
578 |
col mergeSort:[:v1 :v2 | v1 value < v2 value ]. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
579 |
self checkSorted:col with:[:v1 :v2 | v1 value <= v2 value ] against:testData. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
580 |
|
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
581 |
lastTestData := nil. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
582 |
|
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
583 |
errs := col inject: 0 into: |
1447 | 584 |
[ :totIn :aSortTestData | |totOut| |
585 |
totOut := totIn. |
|
586 |
lastTestData notNil ifTrue: |
|
587 |
[ lastTestData value = aSortTestData value ifTrue: |
|
588 |
[ lastTestData order > aSortTestData order ifTrue: [ totOut := totOut + 1 ] ] ]. |
|
589 |
lastTestData := aSortTestData. |
|
590 |
totOut ]. |
|
656
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
591 |
self should: [ errs = 0 ] |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
592 |
|
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
593 |
" |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
594 |
self basicNew testMergeSortStability01 |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
595 |
" |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
596 |
! |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
597 |
|
301 | 598 |
testOrderedCollection01_Sort1 |
599 |
|col col2| |
|
600 |
||
601 |
col := #( 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ) copy. |
|
602 |
col sort. |
|
585 | 603 |
self assert:( col sameContentsAs: (1 to:20)). |
301 | 604 |
|
605 |
col := #( 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ) copy reverse. |
|
606 |
col sort. |
|
585 | 607 |
self assert:( col sameContentsAs: (1 to:20) ). |
301 | 608 |
|
609 |
col := #( 10 2 13 4 15 6 17 8 19 11 1 12 3 14 5 16 7 18 9 20 ) copy. |
|
610 |
col sort. |
|
585 | 611 |
self assert:( col sameContentsAs: (1 to:20) ). |
301 | 612 |
|
613 |
col := ( 1 to: 10000 ) asOrderedCollection. |
|
614 |
col sort. |
|
585 | 615 |
self assert:( col sameContentsAs: (1 to:10000) ). |
301 | 616 |
|
617 |
col := ( 1 to: 10000 ) asOrderedCollection. |
|
618 |
col2 := ( 1 to: 10000 ) asOrderedCollection. |
|
619 |
col sortWith:col2. |
|
585 | 620 |
self assert:( col sameContentsAs: (1 to:10000) ). |
621 |
self assert:( col2 sameContentsAs: (1 to:10000) ). |
|
301 | 622 |
|
623 |
col := ( 10000 to: 1 by:-1) asOrderedCollection. |
|
624 |
col2 := ( 10000 to: 1 by:-1) asOrderedCollection. |
|
625 |
col sortWith:col2. |
|
585 | 626 |
self assert:( col sameContentsAs: (1 to:10000) ). |
627 |
self assert:( col2 sameContentsAs: (1 to:10000) ). |
|
301 | 628 |
|
629 |
" |
|
1447 | 630 |
self new testOrderedCollection01_Sort1 |
301 | 631 |
" |
585 | 632 |
|
633 |
"Modified: / 04-07-2011 / 19:29:54 / cg" |
|
301 | 634 |
! |
635 |
||
636 |
testOrderedCollection02_SortBigCollection |
|
637 |
| size col sortBlock| |
|
638 |
||
639 |
size := 12500. |
|
640 |
col := OrderedCollection new. |
|
641 |
1 to:size do:[:el| |
|
1447 | 642 |
col add:nil. |
301 | 643 |
]. |
1447 | 644 |
sortBlock := [:entry1 :entry2 | |
645 |
((entry1 isNil) or:[entry2 isNil]) ifTrue:[ |
|
646 |
true |
|
647 |
] ifFalse:[ |
|
648 |
false |
|
649 |
] |
|
301 | 650 |
]. |
651 |
self shouldnt:[col sort:sortBlock] raise:RecursionInterruptSignal. |
|
652 |
||
653 |
" |
|
654 |
self new testOrderedCollection02_SortBigCollection |
|
655 |
" |
|
656 |
! |
|
657 |
||
658 |
testOrderedCollection03_SortBigCollection2 |
|
659 |
| size col| |
|
660 |
||
661 |
size := 12500. |
|
662 |
col := OrderedCollection new. |
|
663 |
1 to:size do:[:el| |
|
1447 | 664 |
col add:'abc'. |
301 | 665 |
]. |
666 |
self shouldnt:[col sort] raise:RecursionInterruptSignal. |
|
667 |
||
668 |
" |
|
669 |
self new testOrderedCollection03_SortBigCollection2 |
|
670 |
" |
|
671 |
! |
|
672 |
||
673 |
testOrderedCollection04_SortNilsInCollection |
|
674 |
| size col sortBlock| |
|
675 |
||
676 |
size := 125. |
|
677 |
col := OrderedCollection new. |
|
678 |
1 to:size do:[:el| |
|
1447 | 679 |
col add:nil. |
301 | 680 |
]. |
1447 | 681 |
sortBlock := [:entry1 :entry2 | |
682 |
((entry1 isNil) or:[entry2 isNil]) ifTrue:[ |
|
683 |
true |
|
684 |
] ifFalse:[ |
|
685 |
false |
|
686 |
] |
|
301 | 687 |
]. |
688 |
"/ col sort:sortBlock. |
|
689 |
self shouldnt:[col sort:sortBlock] raise:RecursionInterruptSignal. |
|
690 |
||
691 |
" |
|
692 |
self new testOrderedCollection04_SortNilsInCollection |
|
693 |
" |
|
655 | 694 |
! |
695 |
||
696 |
testOrderedCollection05_SortRandomCollection |
|
697 |
|data sorted rg coData checkBlock| |
|
1447 | 698 |
|
699 |
checkBlock := [:a :b| a <= b]. |
|
655 | 700 |
rg := Random new. |
701 |
||
702 |
#(1 4 11 2000 20011 200000) do:[:eachSize| |
|
1447 | 703 |
data := Array new:eachSize. |
704 |
1 to:data size do:[:i | |
|
705 |
data at:i put:(rg nextIntegerBetween:1 and:100). |
|
706 |
]. |
|
707 |
sorted := data copy sort. |
|
708 |
self checkSorted:sorted with:checkBlock against:data. |
|
709 |
sorted := sorted sort. |
|
710 |
self checkSorted:sorted with:checkBlock against:data. |
|
711 |
sorted := sorted reverse sort. |
|
712 |
self checkSorted:sorted with:checkBlock against:data. |
|
655 | 713 |
|
1447 | 714 |
coData := data copy. |
715 |
sorted := data copy sortWith:coData. |
|
716 |
self checkSorted:sorted with:checkBlock against:data. |
|
717 |
self checkSorted:coData with:checkBlock against:data. |
|
655 | 718 |
|
1280
977c1f04083e
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1054
diff
changeset
|
719 |
"/ Policy is not yet supported (without libcompat) |
977c1f04083e
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1054
diff
changeset
|
720 |
"/ sorted := data copy sort:[:policy :a :b| a < b]. |
977c1f04083e
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1054
diff
changeset
|
721 |
"/ self checkSorted:sorted with:checkBlock against:data. |
655 | 722 |
|
1447 | 723 |
sorted := data copy sort:[:a :b| a < b]. |
724 |
self checkSorted:sorted with:checkBlock against:data. |
|
655 | 725 |
|
1447 | 726 |
coData := data copy. |
727 |
sorted := data copy sort:[:a :b| a < b] with:coData. |
|
728 |
self checkSorted:sorted with:checkBlock against:data. |
|
729 |
self checkSorted:coData with:checkBlock against:data. |
|
655 | 730 |
]. |
656
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
731 |
! |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
732 |
|
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
733 |
testOrderedCollection06_MergeSortRandomCollection |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
734 |
|data sorted rg checkBlock| |
1447 | 735 |
|
736 |
checkBlock := [:a :b| a <= b]. |
|
656
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
737 |
rg := Random new. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
738 |
|
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
739 |
#(1 4 11 2000 20011 200000) do:[:eachSize| |
1447 | 740 |
data := Array new:eachSize. |
741 |
1 to:data size do:[:i | |
|
742 |
data at:i put:(rg nextIntegerBetween:1 and:100). |
|
743 |
]. |
|
744 |
sorted := data copy mergeSort. |
|
745 |
self checkSorted:sorted with:checkBlock against:data. |
|
746 |
sorted := sorted mergeSort. |
|
747 |
self checkSorted:sorted with:checkBlock against:data. |
|
748 |
sorted := sorted reverse mergeSort. |
|
749 |
self checkSorted:sorted with:checkBlock against:data. |
|
656
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
750 |
|
1447 | 751 |
sorted := data copy mergeSort:[:a :b| a < b]. |
752 |
self checkSorted:sorted with:checkBlock against:data. |
|
656
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
753 |
]. |
657
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
754 |
! |
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
755 |
|
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
756 |
testOrderedCollection07_HeapSortRandomCollection |
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
757 |
|data sorted rg checkBlock| |
1447 | 758 |
|
759 |
checkBlock := [:a :b| a <= b]. |
|
657
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
760 |
rg := Random new. |
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
761 |
|
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
762 |
#(1 4 11 2000 20011 200000) do:[:eachSize| |
1447 | 763 |
data := Array new:eachSize. |
764 |
1 to:data size do:[:i | |
|
765 |
data at:i put:(rg nextIntegerBetween:1 and:100). |
|
766 |
]. |
|
767 |
sorted := data copy heapSort. |
|
768 |
self checkSorted:sorted with:checkBlock against:data. |
|
769 |
sorted := sorted heapSort. |
|
770 |
self checkSorted:sorted with:checkBlock against:data. |
|
771 |
sorted := sorted reverse heapSort. |
|
772 |
self checkSorted:sorted with:checkBlock against:data. |
|
657
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
773 |
|
1447 | 774 |
sorted := data copy heapSort:[:a :b| a < b]. |
775 |
self checkSorted:sorted with:checkBlock against:data. |
|
657
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
776 |
]. |
1422 | 777 |
! |
778 |
||
779 |
testOrderedCollection08_addBefore |
|
780 |
|col| |
|
781 |
||
782 |
col := #( 1 2 3 4 5 ) asOrderedCollection. |
|
783 |
col add:0 beforeIndex:1. |
|
784 |
self assert:(col asArray = #(0 1 2 3 4 5)). |
|
785 |
||
786 |
col := OrderedCollection new. |
|
787 |
col add:10. |
|
788 |
col add:0 beforeIndex:1. |
|
789 |
self assert:(col asArray = #(0 10)). |
|
1447 | 790 |
|
1422 | 791 |
col := OrderedCollection with:10. |
792 |
col add:0 beforeIndex:1. |
|
793 |
self assert:(col asArray = #(0 10)). |
|
794 |
||
795 |
col := OrderedCollection new:1. |
|
796 |
col add:10. |
|
797 |
self assert:(col size == 1). |
|
798 |
self assert:(col asArray = #(10)). |
|
799 |
self assert:(col instVarNamed:'firstIndex') == 1. |
|
800 |
self assert:(col instVarNamed:'lastIndex') == 1. |
|
801 |
||
802 |
col add:0 beforeIndex:1. |
|
803 |
self assert:(col size == 2). |
|
804 |
self assert:(col instVarNamed:'firstIndex') == 1. |
|
805 |
self assert:(col instVarNamed:'lastIndex') == 2. |
|
806 |
self assert:(col asArray = #(0 10)). |
|
807 |
" |
|
1447 | 808 |
self new testOrderedCollection08_addBefore |
1422 | 809 |
" |
1424 | 810 |
! |
811 |
||
812 |
testOrderedCollection09_addAllBefore |
|
813 |
|col| |
|
814 |
||
815 |
col := #( 1 2 3 4 5 ) asOrderedCollection. |
|
816 |
col addAll:#(-2 -1 0) beforeIndex:1. |
|
817 |
self assert:(col asArray = #(-2 -1 0 1 2 3 4 5)). |
|
818 |
||
819 |
col := OrderedCollection new:1. |
|
820 |
col add:10. |
|
821 |
||
822 |
col addAll:#(-2 -1 0) beforeIndex:1. |
|
823 |
self assert:(col size == 4). |
|
824 |
self assert:(col instVarNamed:'firstIndex') == 1. |
|
825 |
self assert:(col instVarNamed:'lastIndex') == 4. |
|
826 |
self assert:(col asArray = #(-2 -1 0 10)). |
|
827 |
" |
|
1447 | 828 |
self new testOrderedCollection09_addAllBefore |
1424 | 829 |
" |
301 | 830 |
! ! |
831 |
||
832 |
!CollectionTests methodsFor:'tests-orderedDictionary'! |
|
833 |
||
834 |
testOrderedDictionary01 |
|
835 |
|d ret| |
|
836 |
||
837 |
d := OrderedDictionary new. |
|
838 |
||
839 |
self assert: ( d size == 0 ). |
|
840 |
self assert: ( d isEmpty ). |
|
841 |
self assert: ( d notEmpty not ). |
|
842 |
||
843 |
d at:'one' put:1. |
|
844 |
d at:'two' put:2. |
|
845 |
d at:'three' put:3. |
|
846 |
||
847 |
self assert: ( d size == 3 ). |
|
848 |
self assert: ( d isEmpty not). |
|
849 |
self assert: ( d notEmpty ). |
|
850 |
||
585 | 851 |
self assert:((ret := self collectedDoArgsOf:d) sameContentsAs: #(1 2 3)). |
301 | 852 |
|
853 |
self assert: ( (d atIndex:1) == 1 ). |
|
854 |
self assert: ( (d atIndex:2) == 2 ). |
|
855 |
self assert: ( (d atIndex:3) == 3 ). |
|
856 |
||
1651 | 857 |
self assert: ( (d firstAssociation) = ('one'->1) ). |
858 |
self assert: ( (d lastAssociation) = ('three'->3) ). |
|
859 |
||
860 |
self assert: ( (d first) = 1 ). |
|
861 |
self assert: ( (d last) = 3 ). |
|
301 | 862 |
|
585 | 863 |
self assert:((ret := d collect:[:each | each]) sameContentsAs: #(1 2 3)). |
864 |
self assert:((ret := d select:[:each | true]) sameContentsAs: (OrderedDictionary withAssociations:(Array with:('one'->1) with:('two'->2) with:('three'->3)))). |
|
301 | 865 |
|
866 |
self assert: ( d includes:1 ). |
|
867 |
self assert: ( d includes:2 ). |
|
868 |
self assert: ( d includes:3 ). |
|
869 |
||
870 |
self assert: ( d includesKey:'one' ). |
|
871 |
self assert: ( d includesKey:'two' ). |
|
872 |
self assert: ( d includesKey:'three' ). |
|
873 |
||
874 |
self assert: ((ret := d removeFirst) = 1). |
|
875 |
self assert: ( d size == 2 ). |
|
876 |
self assert: ((ret := d removeLast) = 3). |
|
877 |
self assert: ( d size == 1 ). |
|
878 |
self assert: ((ret := d removeLast) = 2). |
|
879 |
self assert: ( d size == 0 ). |
|
880 |
self assert: ( d isEmpty ). |
|
881 |
self assert: ( d notEmpty not ). |
|
882 |
||
883 |
" |
|
884 |
self basicNew testOrderedDictionary01 |
|
885 |
" |
|
585 | 886 |
|
887 |
"Modified: / 04-07-2011 / 19:32:34 / cg" |
|
1651 | 888 |
"Modified: / 27-07-2017 / 20:38:42 / mawalch" |
301 | 889 |
! ! |
890 |
||
891 |
!CollectionTests methodsFor:'tests-orderedSet'! |
|
162 | 892 |
|
156 | 893 |
testOrderedSet01 |
894 |
|s v1 v2 v3| |
|
895 |
||
896 |
s := OrderedSet new. |
|
897 |
s add:(v1 := 'one'). |
|
898 |
s add:(v2 := 'two'). |
|
899 |
s add:(v3 := 'three'). |
|
900 |
||
901 |
self assert: ( s size == 3 ). |
|
902 |
self assert: ( (s at:1) == v1 ). |
|
903 |
self assert: ( (s at:2) == v2 ). |
|
904 |
self assert: ( (s at:3) == v3 ). |
|
905 |
||
906 |
self assert: ( s includes:v1 ). |
|
907 |
self assert: ( s includes:v2 ). |
|
908 |
self assert: ( s includes:v3 ). |
|
909 |
||
910 |
self assert: ( s includes:v1 copy). |
|
911 |
self assert: ( s includes:v2 copy). |
|
912 |
self assert: ( s includes:v3 copy). |
|
913 |
||
914 |
"already in - adding again should not change things" |
|
915 |
s add:v1. |
|
916 |
self assert: ( s size == 3 ). |
|
917 |
||
918 |
self assert: ( (s at:1) == v1 ). |
|
919 |
self assert: ( (s at:2) == v2 ). |
|
920 |
self assert: ( (s at:3) == v3 ). |
|
921 |
||
922 |
"set i.e. not identitySet - adding copy should not change things" |
|
923 |
s add:v1 copy. |
|
924 |
self assert: ( s size == 3 ). |
|
925 |
||
926 |
self assert: ( (s at:1) == v1 ). |
|
927 |
self assert: ( (s at:2) == v2 ). |
|
928 |
self assert: ( (s at:3) == v3 ). |
|
929 |
||
930 |
s remove:v1. |
|
931 |
||
932 |
self assert: ( s size == 2 ). |
|
933 |
self assert: ( (s at:1) == v2 ). |
|
934 |
self assert: ( (s at:2) == v3 ). |
|
935 |
||
936 |
self assert: ( s includes:v1 ) not. |
|
937 |
self assert: ( s includes:v2 ). |
|
938 |
self assert: ( s includes:v3 ). |
|
939 |
||
940 |
self assert: ( s includes:v1 copy) not. |
|
941 |
self assert: ( s includes:v2 copy). |
|
942 |
self assert: ( s includes:v3 copy). |
|
943 |
||
944 |
s add:v1. |
|
945 |
||
946 |
self assert: ( s size == 3 ). |
|
947 |
self assert: ( (s at:1) == v2 ). |
|
948 |
self assert: ( (s at:2) == v3 ). |
|
949 |
self assert: ( (s at:3) == v1 ). |
|
950 |
||
951 |
self assert: ( s includes:v1 ). |
|
952 |
self assert: ( s includes:v2 ). |
|
953 |
self assert: ( s includes:v3 ). |
|
954 |
||
955 |
self assert: ( s includes:v1 copy). |
|
956 |
self assert: ( s includes:v2 copy). |
|
957 |
self assert: ( s includes:v3 copy). |
|
958 |
||
959 |
s removeLast. |
|
960 |
||
961 |
self assert: ( s size == 2 ). |
|
962 |
self assert: ( (s at:1) == v2 ). |
|
963 |
self assert: ( (s at:2) == v3 ). |
|
964 |
||
965 |
self assert: ( s includes:v1 ) not. |
|
966 |
self assert: ( s includes:v2 ). |
|
967 |
self assert: ( s includes:v3 ). |
|
968 |
||
969 |
self assert: ( s includes:v1 copy) not. |
|
970 |
self assert: ( s includes:v2 copy). |
|
971 |
self assert: ( s includes:v3 copy). |
|
972 |
||
973 |
" |
|
974 |
self basicNew testOrderedSet01 |
|
975 |
" |
|
301 | 976 |
! |
977 |
||
978 |
testOrderedSet02 |
|
979 |
|col| |
|
980 |
||
981 |
col := OrderedSet new. |
|
982 |
||
983 |
col add:'a'. |
|
984 |
col add:'b'. |
|
985 |
col add:'c'. |
|
986 |
self assert:( col size == 3 ). |
|
1447 | 987 |
self assert:( Array streamContents:[:s | |
988 |
col do:[:each | s nextPut:each] |
|
989 |
] |
|
990 |
) = #('a' 'b' 'c' ). |
|
301 | 991 |
|
992 |
" |
|
1447 | 993 |
self new testOrderedSet02 |
301 | 994 |
" |
995 |
! |
|
996 |
||
997 |
testOrderedSet03 |
|
998 |
|col| |
|
999 |
||
1000 |
col := OrderedSet new. |
|
1001 |
||
1002 |
col add:'a'. |
|
1003 |
col add:'b'. |
|
1004 |
col add:'c'. |
|
1005 |
col add:'a'. |
|
1006 |
col add:'b'. |
|
1007 |
self assert:( col size == 3 ). |
|
1447 | 1008 |
self assert:( Array streamContents:[:s | |
1009 |
col do:[:each | s nextPut:each] |
|
1010 |
] |
|
1011 |
) = #('a' 'b' 'c' ). |
|
301 | 1012 |
|
1013 |
" |
|
1447 | 1014 |
self new testOrderedSet03 |
301 | 1015 |
" |
1016 |
! |
|
1017 |
||
1018 |
testOrderedSet04 |
|
1019 |
|col| |
|
1020 |
||
1021 |
col := OrderedSet new. |
|
1022 |
||
1023 |
col add:'a'. |
|
1024 |
col addFirst:'b'. |
|
1025 |
col addFirst:'c'. |
|
1026 |
self assert:( col size == 3 ). |
|
1447 | 1027 |
self assert:( Array streamContents:[:s | |
1028 |
col do:[:each | s nextPut:each] |
|
1029 |
] |
|
1030 |
) = #('c' 'b' 'a' ). |
|
301 | 1031 |
|
1032 |
" |
|
1447 | 1033 |
self new testOrderedSet04 |
301 | 1034 |
" |
1035 |
! |
|
1036 |
||
1037 |
testOrderedSet05 |
|
1038 |
|col| |
|
1039 |
||
1040 |
col := OrderedSet new. |
|
1041 |
||
1042 |
col add:'a'. |
|
1043 |
col addFirst:'b'. |
|
1044 |
col addFirst:'c'. |
|
1045 |
col add:'a'. |
|
1046 |
col add:'b'. |
|
1047 |
col add:'c'. |
|
1048 |
self assert:( col size == 3 ). |
|
1447 | 1049 |
self assert:( Array streamContents:[:s | |
1050 |
col do:[:each | s nextPut:each] |
|
1051 |
] |
|
1052 |
) = #('c' 'b' 'a' ). |
|
301 | 1053 |
|
1054 |
" |
|
1447 | 1055 |
self new testOrderedSet05 |
301 | 1056 |
" |
264 | 1057 |
! ! |
1058 |
||
1299 | 1059 |
!CollectionTests methodsFor:'tests-reindexedCollection'! |
1060 |
||
1061 |
testReindexedCollection01 |
|
1062 |
|s c c2| |
|
1063 |
||
1064 |
s := OrderedCollection new. |
|
1065 |
s addAll:#('one' 'two' 'three' 'four' 'five'). |
|
1066 |
||
1067 |
c := s from:2. |
|
1447 | 1068 |
|
1299 | 1069 |
self assert: ( c size == (s size - 1) ). |
1070 |
1 to:c size do:[:i | |
|
1447 | 1071 |
self assert: ( (c at:i) == (s at:i+1) ). |
1299 | 1072 |
]. |
1447 | 1073 |
|
1299 | 1074 |
c2 := c collect:[:el |el]. |
1075 |
self assert:(c2 size == c size). |
|
1076 |
self assert:(c2 = c). |
|
1077 |
||
1078 |
c2 := c select:[:el |true]. |
|
1079 |
self assert:(c2 size == c size). |
|
1080 |
self assert:(c2 = c). |
|
1447 | 1081 |
|
1299 | 1082 |
c2 := c select:[:el | el startsWith:'t']. |
1083 |
self assert:(c2 size == (s count:[:el | el startsWith:'t' ])). |
|
1084 |
||
1300 | 1085 |
c2 := c reject:[:el | el startsWith:'t']. |
1086 |
self assert:(c2 size == ((s copyFrom:2) count:[:el | el startsWith:'t' ])). |
|
1087 |
||
1088 |
s := #(1 2 3 4 5 6 7 8). |
|
1089 |
c := s from:2. |
|
1090 |
||
1091 |
self assert: ( c size == (s size - 1) ). |
|
1092 |
1 to:c size do:[:i | |
|
1447 | 1093 |
self assert: ( (c at:i) == (s at:i+1) ). |
1300 | 1094 |
]. |
1095 |
||
1096 |
c2 := c collect:[:el |el]. |
|
1097 |
self assert:(c2 size == c size). |
|
1098 |
self assert:(c2 = c). |
|
1099 |
self assert:(c2 sameContentsAs:(s copyFrom:2)). |
|
1100 |
||
1101 |
c2 := c select:[:el |true]. |
|
1102 |
self assert:(c2 size == c size). |
|
1103 |
self assert:(c2 = c). |
|
1104 |
self assert:(c2 sameContentsAs:(s copyFrom:2)). |
|
1105 |
||
1106 |
c2 := c select:[:el |el even]. |
|
1107 |
self assert:(c2 size == ((s copyFrom:2) select:#even) size). |
|
1108 |
self assert:(c2 sameContentsAs:((s copyFrom:2) select:#even)). |
|
1109 |
||
1110 |
c2 := c reject:[:el |el even]. |
|
1111 |
self assert:(c2 size == ((s copyFrom:2) reject:#even) size). |
|
1112 |
self assert:(c2 sameContentsAs:((s copyFrom:2) reject:#even)). |
|
1113 |
||
1299 | 1114 |
" |
1115 |
self basicNew testReindexedCollection01 |
|
1116 |
" |
|
1117 |
! ! |
|
1118 |
||
297 | 1119 |
!CollectionTests methodsFor:'tests-replace'! |
1120 |
||
1121 |
testEmptyReplace |
|
1122 |
| array1 array2 | |
|
1123 |
||
1124 |
array1 := Array with: 1 with: 2 with: 3 with: 4. |
|
1125 |
array2 := Array with: 5 with: 6 with: 7. |
|
1126 |
||
1127 |
array1 replaceFrom:1 to:0 with:array2 startingAt:1. |
|
1128 |
||
1129 |
self should: [ array1 = #(1 2 3 4) ]. |
|
1130 |
||
1131 |
" |
|
1132 |
self new testEmptyReplace |
|
1133 |
" |
|
538 | 1134 |
! |
1135 |
||
1136 |
testTransliterating |
|
1447 | 1137 |
self assert:( 'abcdefghijkl1234567890' copyTransliterating:'b-g' to:'B-G' ) = 'aBCDEFGhijkl1234567890'. |
1138 |
self assert:( 'abcdefghij-kl1234567890' copyTransliterating:'b\-g' to:'B+G' ) = 'aBcdefGhij+kl1234567890'. |
|
1139 |
self assert:( 'abcdefghijkl1234567890' copyTransliterating:'69' to:'96' ) = 'abcdefghijkl1234597860' . |
|
538 | 1140 |
self assert:( 'abcdefghijkl1234567890' copyTransliterating:'a' to:'b' ) = 'bbcdefghijkl1234567890' . |
1447 | 1141 |
self assert:( 'abcdefghijkl1234567890' copyTransliterating:'aeiou' to:'AEIOU' ) = 'AbcdEfghIjkl1234567890'. |
1142 |
self assert:( 'abcdefghijkl1234567890' copyTransliterating:'0-9' to:'QERTYUIOPX' ) = 'abcdefghijklERTYUIOPXQ' . |
|
538 | 1143 |
|
1144 |
self assert:( 'abcdefghijkl1234567890' copyTransliterating:'0-9' to:'A' complement:false squashDuplicates:false ) |
|
1447 | 1145 |
= 'abcdefghijklAAAAAAAAAA'. |
538 | 1146 |
|
1147 |
self assert:( 'abcdefghijkl1234567890' copyTransliterating:'0-9' to:'A' complement:false squashDuplicates:true ) |
|
1447 | 1148 |
= 'abcdefghijklA'. |
538 | 1149 |
|
1150 |
self assert:( 'abcdefghijkl1234567890' copyTransliterating:'0-9' to:'*' complement:false squashDuplicates:false ) |
|
1447 | 1151 |
= 'abcdefghijkl**********'. |
538 | 1152 |
|
1153 |
self assert:( 'abcdefghijkl1234567890' copyTransliterating:'0-9' to:'*' complement:true squashDuplicates:false ) |
|
1447 | 1154 |
= '************1234567890'. |
538 | 1155 |
|
1156 |
self assert:( 'abcdefghijkl1234567890' copyTransliterating:'a-zA-Z' to:' ' complement:true squashDuplicates:false ) |
|
1447 | 1157 |
= 'abcdefghijkl '. |
538 | 1158 |
|
1159 |
self assert:( 'abcdefghijkl1234567890' copyTransliterating:'a-zA-Z' to:' ' complement:false squashDuplicates:false ) |
|
1447 | 1160 |
= ' 1234567890'. |
538 | 1161 |
|
1162 |
self assert:( 'abcdefghijkl1234567890abcdefghijkl' copyTransliterating:'a-zA-Z' to:'' complement:false squashDuplicates:false ) |
|
1447 | 1163 |
= '1234567890'. |
538 | 1164 |
|
1165 |
self assert:( 'abcdefghijkl1234567890abcdefghijkl' copyTransliterating:'a-zA-Z' to:'' complement:true squashDuplicates:false ) |
|
1447 | 1166 |
= 'abcdefghijklabcdefghijkl'. |
297 | 1167 |
! ! |
1168 |
||
639 | 1169 |
!CollectionTests methodsFor:'tests-searching'! |
1170 |
||
1171 |
test_min_max |
|
1172 |
|a| |
|
1173 |
||
1174 |
#( |
|
1447 | 1175 |
asArray |
1176 |
asFloatArray |
|
1177 |
asDoubleArray |
|
1178 |
asHalfFloatArray |
|
1179 |
asSignedWordArray |
|
1180 |
asSignedIntegerArray |
|
1181 |
asSignedLongIntegerArray |
|
639 | 1182 |
) do:[:converter | |
1447 | 1183 |
|empty| |
640 | 1184 |
|
1447 | 1185 |
empty := #() perform:converter. |
1186 |
self should:[ empty min ] raise:Error. |
|
1187 |
self should:[ empty max ] raise:Error. |
|
1188 |
self should:[ empty minMax ] raise:Error. |
|
640 | 1189 |
|
1447 | 1190 |
#( |
1191 |
(0 0) |
|
1192 |
(1 1) |
|
1193 |
(-1 -1) |
|
1194 |
(0 1) |
|
1195 |
(1 2) |
|
1196 |
(-1 -0) |
|
1197 |
(-1 1) |
|
1198 |
(1 10000) |
|
1199 |
(1 20000) |
|
1200 |
(2 10000) |
|
1201 |
(2 20000) |
|
1202 |
(-1000 1000) |
|
1203 |
(-1000 999) |
|
1204 |
) pairsDo:[:min :max | |
|
1205 |
a := (min to:max) perform:converter. |
|
1206 |
self assert:(a min) = min. |
|
1207 |
self assert:(a max) = max. |
|
1208 |
self assert:(a minMax) = { min. max }. |
|
1044
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1209 |
|
1447 | 1210 |
a := a reverse. |
1211 |
self assert:(a min) = min. |
|
1212 |
self assert:(a max) = max. |
|
1213 |
self assert:(a minMax) = { min. max }. |
|
1044
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1214 |
|
1447 | 1215 |
a := a randomShuffle. |
1216 |
self assert:(a min) = min. |
|
1217 |
self assert:(a max) = max. |
|
1218 |
self assert:(a minMax) = { min. max }. |
|
1219 |
]. |
|
1044
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1220 |
]. |
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1221 |
|
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1222 |
#( |
1447 | 1223 |
asWordArray |
1224 |
asIntegerArray |
|
1225 |
asLongIntegerArray |
|
1044
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1226 |
) do:[:converter | |
1447 | 1227 |
|empty| |
1044
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1228 |
|
1447 | 1229 |
empty := #() perform:converter. |
1230 |
self should:[ empty min ] raise:Error. |
|
1231 |
self should:[ empty max ] raise:Error. |
|
1232 |
self should:[ empty minMax ] raise:Error. |
|
1044
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1233 |
|
1447 | 1234 |
#( |
1235 |
(0 0) |
|
1236 |
(1 1) |
|
1237 |
(0 1) |
|
1238 |
(1 2) |
|
1239 |
(1 10000) |
|
1240 |
(1 10001) |
|
1241 |
(2 10000) |
|
1242 |
(2 10001) |
|
1243 |
) pairsDo:[:min :max | |
|
1244 |
a := (min to:max) perform:converter. |
|
1245 |
self assert:(a min) = min. |
|
1246 |
self assert:(a max) = max. |
|
1247 |
self assert:(a minMax) = { min. max }. |
|
639 | 1248 |
|
1447 | 1249 |
a := a reverse. |
1250 |
self assert:(a min) = min. |
|
1251 |
self assert:(a max) = max. |
|
1252 |
self assert:(a minMax) = { min. max }. |
|
639 | 1253 |
|
1447 | 1254 |
a := a randomShuffle. |
1255 |
self assert:(a min) = min. |
|
1256 |
self assert:(a max) = max. |
|
1257 |
self assert:(a minMax) = { min. max }. |
|
1258 |
]. |
|
639 | 1259 |
]. |
1260 |
||
1423 | 1261 |
(Array with:Array with:OrderedCollection with:ByteArray with:WordArray with:IntegerArray) |
1422 | 1262 |
do:[:cls | |
1447 | 1263 |
a := cls withAll: #(10 20 30 40 50 60 70 80 90 100). |
1422 | 1264 |
|
1447 | 1265 |
self assert:(a indexOf:110) == 0. |
1266 |
self assert:(a indexOf:10) == 1. |
|
1267 |
self assert:(a indexOf:20) == 2. |
|
1268 |
self assert:(a indexOf:30) == 3. |
|
1269 |
self assert:(a indexOf:40) == 4. |
|
1270 |
self assert:(a indexOf:50) == 5. |
|
1271 |
self assert:(a indexOf:60) == 6. |
|
1272 |
self assert:(a indexOf:70) == 7. |
|
1273 |
self assert:(a indexOf:80) == 8. |
|
1274 |
self assert:(a indexOf:90) == 9. |
|
1275 |
self assert:(a indexOf:100) == 10. |
|
1422 | 1276 |
|
1447 | 1277 |
self assert:(a identityIndexOf:110) == 0. |
1278 |
self assert:(a identityIndexOf:10) == 1. |
|
1279 |
self assert:(a identityIndexOf:20) == 2. |
|
1280 |
self assert:(a identityIndexOf:30) == 3. |
|
1281 |
self assert:(a identityIndexOf:40) == 4. |
|
1282 |
self assert:(a identityIndexOf:50) == 5. |
|
1283 |
self assert:(a identityIndexOf:60) == 6. |
|
1284 |
self assert:(a identityIndexOf:70) == 7. |
|
1285 |
self assert:(a identityIndexOf:80) == 8. |
|
1286 |
self assert:(a identityIndexOf:90) == 9. |
|
1287 |
self assert:(a identityIndexOf:100) == 10. |
|
1422 | 1288 |
]. |
1289 |
||
639 | 1290 |
"Created: / 07-10-2011 / 13:11:36 / cg" |
1291 |
! ! |
|
1292 |
||
264 | 1293 |
!CollectionTests methodsFor:'tests-sorting'! |
212 | 1294 |
|
1049
c5c7858fe11e
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1295 |
testLargest |
c5c7858fe11e
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1296 |
| col | |
c5c7858fe11e
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1297 |
|
c5c7858fe11e
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1298 |
col := #(5 16 3 18 17 15 2 12 1 8 14 10 7 11 20 4 19 6 13 9). |
c5c7858fe11e
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1299 |
self assert:(col max == 20). |
c5c7858fe11e
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1300 |
self assert:(col largest:4) asArray = #(17 18 19 20). |
c5c7858fe11e
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1301 |
self assert:(col smallest:4) asArray = #(1 2 3 4). |
c5c7858fe11e
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1302 |
|
c5c7858fe11e
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1303 |
self assert:(col keysOfLargest:4) asArray = #(5 4 17 15). |
c5c7858fe11e
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1304 |
self assert:(col keysOfSmallest:4) asArray = #(9 7 3 16). |
c5c7858fe11e
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1305 |
|
c5c7858fe11e
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1306 |
" |
c5c7858fe11e
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1307 |
self basicNew testLargest |
c5c7858fe11e
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1308 |
" |
c5c7858fe11e
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1309 |
! |
c5c7858fe11e
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1310 |
|
212 | 1311 |
testSort01 |
1312 |
| col errs last | |
|
1313 |
||
1314 |
col := SortedCollection new addAll: (100 to: 1 by: -1); yourself. |
|
1315 |
last := nil. |
|
1316 |
errs := col inject: 0 into: |
|
1447 | 1317 |
[ :totIn :n | |totOut| |
212 | 1318 |
|
1447 | 1319 |
totOut := totIn. |
1320 |
last notNil ifTrue: [ last > n ifTrue: [ totOut := totOut + 1 ] ]. |
|
1321 |
last := n. |
|
1322 |
totOut ]. |
|
212 | 1323 |
self should: [ errs = 0 ] |
1324 |
||
1325 |
" |
|
1326 |
self basicNew testSort01 |
|
1327 |
" |
|
1328 |
! |
|
1329 |
||
1330 |
testSortStability01 |
|
1331 |
"Verify that the sort is stable" |
|
1332 |
||
1333 |
| testData col lastTestData errs | |
|
1334 |
||
1335 |
testData := OrderedCollection new. |
|
656
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1336 |
testData addAll: ((111 to: 1 by: -1) collect: [ :n | SortTestData new value: n ]). |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1337 |
testData addAll: ((111 to: 1 by: -1) collect: [ :n | SortTestData new value: n ]). |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1338 |
testData addAll: ((111 to: 1 by: -1) collect: [ :n | SortTestData new value: n ]). |
212 | 1339 |
1 to: testData size do: [ :i | (testData at: i) order: i ]. |
1340 |
||
656
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1341 |
col := SortedCollection new sortBlock:[ :v1 :v2 | v1 value < v2 value ]. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1342 |
col addAll: testData. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1343 |
|
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1344 |
self checkSorted:col with:[:v1 :v2 | v1 value <= v2 value ] against:testData. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1345 |
|
212 | 1346 |
lastTestData := nil. |
1347 |
||
1348 |
errs := col inject: 0 into: |
|
1447 | 1349 |
[ :totIn :aSortTestData | |totOut| |
1350 |
totOut := totIn. |
|
1351 |
lastTestData notNil ifTrue: |
|
1352 |
[ lastTestData value = aSortTestData value ifTrue: |
|
1353 |
[ lastTestData order > aSortTestData order ifTrue: [ totOut := totOut + 1 ] ] ]. |
|
1354 |
lastTestData := aSortTestData. |
|
1355 |
totOut ]. |
|
212 | 1356 |
self should: [ errs = 0 ] |
1357 |
||
1358 |
" |
|
1359 |
self basicNew testSortStability01 |
|
1360 |
" |
|
1361 |
! |
|
1362 |
||
1363 |
testSortStability02 |
|
656
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1364 |
"Verify that the sort is stable" |
212 | 1365 |
|
656
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1366 |
| testData col lastTestData errs | |
212 | 1367 |
|
656
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1368 |
testData := OrderedCollection new. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1369 |
(25 to: 1 by: -1) do: [ :i | 1 to: 100 do: [ :j | testData add: (SortTestData new value: i ) ] ]. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1370 |
1 to: testData size do: [ :i | (testData at: i) order: i ]. |
212 | 1371 |
|
656
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1372 |
col := SortedCollection new sortBlock: [ :v1 :v2 | v1 value < v2 value ]. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1373 |
col addAll: testData. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1374 |
|
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1375 |
self checkSorted:col with:[:v1 :v2 | v1 value <= v2 value ] against:testData. |
212 | 1376 |
|
656
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1377 |
lastTestData := nil. |
212 | 1378 |
|
656
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1379 |
errs := col inject: 0 into: |
1447 | 1380 |
[ :totIn :aSortTestData | |totOut| |
1381 |
totOut := totIn. |
|
1382 |
lastTestData notNil ifTrue: |
|
1383 |
[ lastTestData value = aSortTestData value ifTrue: |
|
1384 |
[ lastTestData order > aSortTestData order ifTrue: [ totOut := totOut + 1 ] ] ]. |
|
1385 |
lastTestData := aSortTestData. |
|
1386 |
totOut ]. |
|
656
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1387 |
self should: [ errs = 0 ] |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1388 |
|
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1389 |
" |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1390 |
self basicNew testSortStability02 |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1391 |
" |
1282
e64a9d280572
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1280
diff
changeset
|
1392 |
! |
e64a9d280572
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1280
diff
changeset
|
1393 |
|
e64a9d280572
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1280
diff
changeset
|
1394 |
testSortedCollectionQueries |
e64a9d280572
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1280
diff
changeset
|
1395 |
"test a SortedCollection, where only a single attribute is used for sorting. |
e64a9d280572
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1280
diff
changeset
|
1396 |
#include: failed before 2015-06-24" |
1447 | 1397 |
|
1282
e64a9d280572
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1280
diff
changeset
|
1398 |
|collection| |
e64a9d280572
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1280
diff
changeset
|
1399 |
|
e64a9d280572
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1280
diff
changeset
|
1400 |
collection := SortedCollection sortBlock:[:a :b | a key < b key ]. |
1447 | 1401 |
$a to:$z do:[:l | |
1402 |
1 to:100 do:[:i | |
|
1403 |
collection add:(Association key:l value:i) |
|
1404 |
]. |
|
1282
e64a9d280572
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1280
diff
changeset
|
1405 |
]. |
1447 | 1406 |
|
1282
e64a9d280572
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1280
diff
changeset
|
1407 |
"/ make startIndex > 1 and endIndex < size |
1447 | 1408 |
|
1282
e64a9d280572
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1280
diff
changeset
|
1409 |
collection |
1447 | 1410 |
removeFirst; |
1411 |
removeLast. |
|
1412 |
collection |
|
1413 |
keysAndValuesDo:[:eachIndex :eachElement | |
|
1414 |
self assert:(collection detect:[:el | el = eachElement ]) notNil. |
|
1415 |
self assert:(collection includes:eachElement). |
|
1416 |
self assert:(collection indexOf:eachElement) = eachIndex. |
|
1417 |
self assert:(collection occurrencesOf:eachElement) = 1. |
|
1418 |
self |
|
1419 |
assert:(collection |
|
1420 |
includes:(eachElement copy value:(eachElement value + 1000))) not. |
|
1421 |
]. |
|
212 | 1422 |
! ! |
1423 |
||
293 | 1424 |
!CollectionTests methodsFor:'tests-squeak'! |
1425 |
||
1426 |
testIfEmptyifNotEmpty |
|
1427 |
self assert: (empty ifEmpty: [true] ifNotEmpty: [false]). |
|
1428 |
self assert: (nonEmpty ifEmpty: [false] ifNotEmpty: [true]). |
|
1429 |
self assert: (nonEmpty ifEmpty: [false] ifNotEmpty: [:s | s first = #x]) |
|
1430 |
! |
|
1431 |
||
1432 |
testIfEmptyifNotEmptyDo |
|
1433 |
self assert: (empty ifEmpty: [true] ifNotEmptyDo: [:s | false]). |
|
1434 |
self assert: (nonEmpty ifEmpty: [false] ifNotEmptyDo: [:s | s first = #x]) |
|
1435 |
! |
|
1436 |
||
1437 |
testIfNotEmpty |
|
1438 |
empty ifNotEmpty: [self assert: false]. |
|
1439 |
self assert: (nonEmpty ifNotEmpty: [self]) == self. |
|
1440 |
self assert: (nonEmpty ifNotEmpty: [:s | s first]) = #x |
|
1441 |
! |
|
1442 |
||
1443 |
testIfNotEmptyDo |
|
1444 |
empty ifNotEmptyDo: [:s | self assert: false]. |
|
1445 |
self assert: (nonEmpty ifNotEmptyDo: [:s | s first]) = #x |
|
1446 |
! |
|
1447 |
||
1448 |
testIfNotEmptyDoifNotEmpty |
|
1449 |
self assert: (empty ifNotEmptyDo: [:s | false] ifEmpty: [true]). |
|
1450 |
self assert: (nonEmpty ifNotEmptyDo: [:s | s first = #x] ifEmpty: [false]) |
|
1451 |
! |
|
1452 |
||
1453 |
testIfNotEmptyifEmpty |
|
1454 |
self assert: (empty ifEmpty: [true] ifNotEmpty: [false]). |
|
1455 |
self assert: (nonEmpty ifEmpty: [false] ifNotEmpty: [true]). |
|
1456 |
self assert: (nonEmpty ifEmpty: [false] ifNotEmpty: [:s | s first = #x]) |
|
1457 |
! ! |
|
1458 |
||
1894 | 1459 |
!CollectionTests methodsFor:'tests-stringCollection'! |
1460 |
||
1461 |
testStringCollection |
|
1462 |
|separators stringCollection| |
|
1463 |
||
1464 |
self assert:((StringCollection fromString:'') size == 0). |
|
1465 |
||
1466 |
separators := OrderedCollection with:(String lf) with:(String return) with:(String crlf). |
|
1467 |
separators do:[:separator | |
|
1468 |
1 to:3 do:[:i | |
|
1469 |
|stringA stringB stringC stringD| |
|
1470 |
||
1471 |
stringA := ''. |
|
1472 |
stringB := ''. |
|
1473 |
stringC := ''. |
|
1474 |
stringD := 'd'. |
|
1475 |
||
1476 |
1 to:i do:[:j| |
|
1477 |
stringA := stringA , separator. |
|
1478 |
stringB := stringB , separator , 'b'. |
|
1479 |
stringC := stringC , 'c' , separator. |
|
1480 |
stringD := stringD , separator , 'd'. |
|
1481 |
]. |
|
1482 |
||
1483 |
stringCollection := StringCollection fromString:stringA. |
|
1484 |
self assert:(stringCollection size = i). |
|
1485 |
||
1486 |
stringCollection := StringCollection fromString:stringB. |
|
1487 |
self assert:(stringCollection size = (i + 1)). |
|
1488 |
||
1489 |
stringCollection := StringCollection fromString:stringC. |
|
1490 |
self assert:(stringCollection size = i). |
|
1491 |
||
1492 |
stringCollection := StringCollection fromString:stringD. |
|
1493 |
self assert:(stringCollection size = (i + 1)). |
|
1494 |
]. |
|
1495 |
]. |
|
1496 |
! ! |
|
1497 |
||
212 | 1498 |
!CollectionTests::SortTestData methodsFor:'accessing'! |
1499 |
||
1500 |
value |
|
1447 | 1501 |
"Answer the value of the receiver's ''value'' instance variable." |
212 | 1502 |
|
1447 | 1503 |
^value |
212 | 1504 |
! |
1505 |
||
1506 |
value: anObject |
|
1447 | 1507 |
"Set the value of the receiver's ''value'' instance variable to the argument, anObject." |
212 | 1508 |
|
1447 | 1509 |
value := anObject |
212 | 1510 |
! ! |
1511 |
||
1512 |
!CollectionTests::SortTestData methodsFor:'order'! |
|
1513 |
||
1514 |
order |
|
1447 | 1515 |
"Answer the value of the receiver's ''order'' instance variable." |
212 | 1516 |
|
1447 | 1517 |
^order |
212 | 1518 |
! |
1519 |
||
1520 |
order: anObject |
|
1447 | 1521 |
"Set the value of the receiver's ''order'' instance variable to the argument, anObject." |
212 | 1522 |
|
1447 | 1523 |
order := anObject |
212 | 1524 |
! ! |
1525 |
||
1526 |
!CollectionTests::SortTestData methodsFor:'printing & storing'! |
|
1527 |
||
1528 |
printOn: aStream |
|
1447 | 1529 |
super printOn: aStream. |
1530 |
aStream |
|
1531 |
nextPutAll: '(value: '; |
|
1532 |
nextPutAll: value printString; |
|
1533 |
nextPutAll: ' order: '; |
|
1534 |
nextPutAll: order printString; |
|
1535 |
nextPut: $) |
|
115 | 1536 |
! ! |
1537 |
||
1538 |
!CollectionTests class methodsFor:'documentation'! |
|
1539 |
||
1540 |
version |
|
1541 |
^ '$Header$' |
|
640 | 1542 |
! |
1543 |
||
1544 |
version_CVS |
|
1545 |
^ '$Header$' |
|
115 | 1546 |
! ! |
757
2d776bef407b
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
677
diff
changeset
|
1547 |