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