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