/
DictionaryTest.class.st
742 lines (595 loc) · 19.8 KB
/
DictionaryTest.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
"
SUnit tests for dictionaries
"
Class {
#name : #DictionaryTest,
#superclass : #CollectionRootTest,
#traits : 'TIncludesTest + TDictionaryAddingTest + TDictionaryComparingTest + TDictionaryCopyingTest + TDictionaryEnumeratingTest + (TDictionaryPrintingTest - {#testPrintElementsOn. #testStoreOn}) + TDictionaryRemovingTest + (TPutBasicTest - {#testAtPutOutOfBounds}) + TAsStringCommaAndDelimiterTest + TPrintTest + TConvertTest + TConvertAsSortedTest + (TCopyTest - {#testCopyEmptyWithout. #testCopyNonEmptyWithout. #testCopyNonEmptyWithoutNotIncluded}) + TSetArithmetic + TDictionaryIncludesWithIdentityCheckTest + TDictionaryValueAccessTest + TDictionaryKeysValuesAssociationsAccess + TDictionaryKeyAccessTest + TDictionaryAssociationAccessTest + TStructuralEqualityTest + TOccurrencesForMultiplinessTest',
#classTraits : 'TIncludesTest classTrait + TDictionaryAddingTest classTrait + TDictionaryComparingTest classTrait + TDictionaryCopyingTest classTrait + TDictionaryEnumeratingTest classTrait + TDictionaryPrintingTest classTrait + TDictionaryRemovingTest classTrait + TPutBasicTest classTrait + TAsStringCommaAndDelimiterTest classTrait + TPrintTest classTrait + TConvertTest classTrait + TConvertAsSortedTest classTrait + TCopyTest classTrait + TSetArithmetic classTrait + TDictionaryIncludesWithIdentityCheckTest classTrait + TDictionaryValueAccessTest classTrait + TDictionaryKeysValuesAssociationsAccess classTrait + TDictionaryKeyAccessTest classTrait + TDictionaryAssociationAccessTest classTrait + TStructuralEqualityTest classTrait + TOccurrencesForMultiplinessTest classTrait',
#instVars : [
'emptyDict',
'nonEmptyDict',
'nonEmpty5ElementsNoDuplicates',
'indexArray',
'valueArray',
'nonEmpty1Element',
'collectionNotIncluded',
'collectionIncluded',
'associationNotIn',
'valueNotIn',
'keyNotIn',
'dictionaryNotIncluded',
'nonEmptyWithFloat',
'dictionaryWithDuplicateValues',
'duplicateValue'
],
#classInstVars : [
'testToto',
'pt1'
],
#category : #'Collections-Tests-Unordered'
}
{ #category : #helpers }
DictionaryTest >> aValue [
^ 33
]
{ #category : #helpers }
DictionaryTest >> anIndex [
^ #GG
]
{ #category : #requirements }
DictionaryTest >> anotherElementNotIn [
^ 42
]
{ #category : #requirements }
DictionaryTest >> anotherElementOrAssociationIn [
" return an element (or an association for Dictionary ) present in 'collection' "
^ self collection associations anyOne.
]
{ #category : #requirements }
DictionaryTest >> anotherElementOrAssociationNotIn [
" return an element (or an association for Dictionary )not present in 'collection' "
^ associationNotIn
]
{ #category : #helpers }
DictionaryTest >> anotherValue [
^ 66
]
{ #category : #requirements }
DictionaryTest >> associationWithKeyAlreadyInToAdd [
" return an association that will be used to add to nonEmptyDict (the key of this association is already included in nonEmptyDict)"
^ (self nonEmptyDict keys anyOne)->valueNotIn .
]
{ #category : #requirements }
DictionaryTest >> associationWithKeyNotInToAdd [
" return an association that will be used to add to nonEmptyDict"
^ associationNotIn
]
{ #category : #requirements }
DictionaryTest >> canBeUnhealthy [
^ true
]
{ #category : #setup }
DictionaryTest >> classToBeTested [
^ Dictionary
]
{ #category : #requirements }
DictionaryTest >> collection [
^ self nonEmptyDict
]
{ #category : #requirements }
DictionaryTest >> collectionClass [
" return the class to be used to create instances of the class tested"
^ self classToBeTested
]
{ #category : #requirements }
DictionaryTest >> collectionNotIncluded [
" return a collection for wich each element is not included in 'nonEmpty' "
^collectionNotIncluded
]
{ #category : #requirements }
DictionaryTest >> collectionWithElement [
"Returns a collection that already includes what is returned by #element."
^ nonEmpty5ElementsNoDuplicates add: self element ;yourself.
]
{ #category : #requirements }
DictionaryTest >> collectionWithElementsToRemove [
" return a collection of elements included in 'nonEmpty' "
^ collectionIncluded
]
{ #category : #requirements }
DictionaryTest >> collectionWithEqualElements [
" return a collecition including atLeast two elements equal"
^ dictionaryWithDuplicateValues
]
{ #category : #requirements }
DictionaryTest >> collectionWithSortableElements [
" return a collection elements that can be sorte ( understanding message ' < ' or ' > ')"
^ nonEmpty5ElementsNoDuplicates
]
{ #category : #requirements }
DictionaryTest >> collectionWithoutEqualElements [
" return a collection without equal elements"
^ nonEmpty5ElementsNoDuplicates
]
{ #category : #requirements }
DictionaryTest >> collectionWithoutNilElements [
" return a collection that doesn't includes a nil element and that doesn't includes equal elements'"
^nonEmpty5ElementsNoDuplicates
]
{ #category : #requirements }
DictionaryTest >> element [
^ 30
]
{ #category : #requirements }
DictionaryTest >> elementNotIn [
"return an element not included in 'nonEmpty' "
^ valueNotIn
]
{ #category : #requirements }
DictionaryTest >> elementNotInForOccurrences [
^ 666
]
{ #category : #requirements }
DictionaryTest >> elementToAdd [
" return an element of type 'nonEmpy' elements'type'"
^ #u->5.
]
{ #category : #requirements }
DictionaryTest >> elementTwiceInForOccurrences [
" return an element included exactly two time in # collectionWithEqualElements"
^ duplicateValue
]
{ #category : #requirements }
DictionaryTest >> empty [
^ emptyDict
]
{ #category : #requirements }
DictionaryTest >> emptyDict [
^ emptyDict
]
{ #category : #requirements }
DictionaryTest >> expectedElementByDetect [
^ 30
]
{ #category : #requirements }
DictionaryTest >> expectedSizeAfterReject [
self flag: 'what should this return?'
]
{ #category : #requirements }
DictionaryTest >> indexInNonEmpty [
" return an index between bounds of 'nonEmpty' "
^ #a
]
{ #category : #requirements }
DictionaryTest >> integerCollectionWithoutEqualElements [
" return a collection of integer without equal elements"
^ nonEmpty5ElementsNoDuplicates
]
{ #category : #requirements }
DictionaryTest >> keyNotIn [
" return a key not included in nonEmpty"
^ keyNotIn
]
{ #category : #requirements }
DictionaryTest >> keyNotInNonEmpty [
" return a key not included in nonEmpty"
^ keyNotIn
]
{ #category : #requirements }
DictionaryTest >> keyNotInNonEmptyDict [
" return a key not included in nonEmptyDict"
^ keyNotIn
]
{ #category : #requirements }
DictionaryTest >> newEmptyDict [
^ self emptyDict copy
]
{ #category : #requirements }
DictionaryTest >> nonEmpty [
^ nonEmptyDict
]
{ #category : #requirements }
DictionaryTest >> nonEmpty1Element [
" return a collection of size 1 including one element"
^ nonEmpty1Element
]
{ #category : #requirements }
DictionaryTest >> nonEmptyDict [
^ nonEmptyDict
]
{ #category : #requirements }
DictionaryTest >> nonEmptyDifferentFromNonEmptyDict [
" return a dictionary for which all keys are not included in nonEmptyDict"
^ dictionaryNotIncluded
]
{ #category : #requirements }
DictionaryTest >> nonEmptyWithCopyNonIdentical. [
" return a collection including elements for wich copy is not identical to the initial element ( this is not the cas of Integer )"
^nonEmptyWithFloat
]
{ #category : #requirements }
DictionaryTest >> nonEmptyWithoutEqualsValues [
" return a dictionary that doesn't include equal values'"
^nonEmpty5ElementsNoDuplicates
]
{ #category : #requirements }
DictionaryTest >> otherCollection [
"Returns a collection that does not include what is returned by #element."
^ nonEmpty5ElementsNoDuplicates
]
{ #category : #requirements }
DictionaryTest >> otherDictionaryClasses [
"(DictionaryTest withAllSubclasses collect: [:each | each new classToBeTested]) asArray"
^ {SmallDictionary. IdentityDictionary. PluggableDictionary.
WeakValueDictionary. SystemDictionary. WeakKeyDictionary. SmallIdentityDictionary.
WeakIdentityKeyDictionary. WeakKeyToCollectionDictionary. Dictionary}
reject: [:each | each new species == self classToBeTested new species]
]
{ #category : #requirements }
DictionaryTest >> result [
^ self collectionClass newFromPairs: {
#a . SmallInteger .
#b . SmallInteger .
#c . SmallInteger .
#d . SmallInteger }
]
{ #category : #running }
DictionaryTest >> setUp [
emptyDict := self classToBeTested new.
nonEmptyDict := self classToBeTested new.
nonEmptyDict
at: #a
put: self elementTwiceIn;
at: #b
put: 30;
at: #c
put: self elementTwiceIn;
at: #d
put: -2.
nonEmpty5ElementsNoDuplicates := self classToBeTested new
at: #a
put: 5;
at: #b
put: 4;
at: #c
put: 7;
at: #d
put: 6;
at: #e
put: 9;
yourself.
valueNotIn := 666.
keyNotIn := #z .
associationNotIn := keyNotIn->valueNotIn.
dictionaryNotIncluded := Dictionary new add: associationNotIn ;yourself.
collectionNotIncluded := { valueNotIn. valueNotIn }.
collectionIncluded := { (self elementTwiceIn) }.
indexArray := #(2 3 1 ).
valueArray := #(5 5 5 ).
nonEmpty1Element := self classToBeTested new
at: #a
put: 5;
yourself.
nonEmptyWithFloat := Dictionary new add: #A->2.5; add: #b->3.5 ; yourself.
duplicateValue := 2.5.
dictionaryWithDuplicateValues := Dictionary new add: #A->duplicateValue ; add: #b->3.5 ; add: #C->duplicateValue ; yourself.
]
{ #category : #requirements }
DictionaryTest >> sizeCollection [
^ nonEmptyDict
]
{ #category : #requirements }
DictionaryTest >> speciesClass [
^ Dictionary
]
{ #category : #'tests - adding' }
DictionaryTest >> testAdd [
"| dict |
dict := self emptyDict.
dict add: #a -> 1.
dict add: #b -> 2.
self assert: (dict at: #a) = 1.
self assert: (dict at: #b) = 2"
| dictionary result |
dictionary := self nonEmptyDict.
result := dictionary add: self associationWithKeyNotInToAdd.
self assert: result = self associationWithKeyNotInToAdd
]
{ #category : #'tests - adding' }
DictionaryTest >> testAddWithKeyAlreadyIn [
| dictionary result association |
dictionary := self nonEmptyDict.
association := self associationWithKeyNotInToAdd.
result := dictionary add: association.
self assert: result = association.
self assert: (dictionary at: association key) = association value
]
{ #category : #'tests - adding' }
DictionaryTest >> testAddWithKeyNotIn [
| dictionary result association |
dictionary := self nonEmptyDict.
association := self associationWithKeyNotInToAdd.
result := dictionary add: association.
self assert: result = association.
self assert: (dictionary at: association key) = association value
]
{ #category : #tests }
DictionaryTest >> testAsSet [
"Non regression test for http://bugs.squeak.org/view.php?id=7258"
| aDictionary aSet assoc0 assoc1 |
"Create a dictionary"
aDictionary := Dictionary new.
"Convert it to a Set"
aSet := aDictionary asSet.
"Add two associations to it"
assoc0 := #first -> 0.
assoc1 := #first -> 1.
aSet add: assoc0 copy; add: assoc1.
"Check if the two associations were added (that should happen if they are different)"
self
assert: (assoc0 copy ~= assoc1) ==> (aSet size > 1)
description:
'When adding two different elements, the set size should be greater than one'
]
{ #category : #tests }
DictionaryTest >> testDictionaryPublicProtocolCompatibility [
"Tests that other dictionaries and their classes respond to the messages
in the public protocols (ignoring extensions, private, printing, copying,
and comparing) that Dictionary and its metaclass implement."
| dict |
self collectionClass == Dictionary
ifTrue: [ ^ self ].
dict := self emptyDict.
{(dict -> Dictionary).
(dict class -> Dictionary class)}
do: [ :assoc |
assoc value protocols
reject: [ :protocol |
#('private' 'print' 'copy' 'compar' '*')
anySatisfy: [ :each | protocol asString beginsWith: each ] ]
thenDo: [ :protocol |
(assoc value selectorsInProtocol: protocol)
do: [ :each | self assert: (assoc key respondsTo: each) ] ] ]
]
{ #category : #'tests - flatCollect' }
DictionaryTest >> testFlatCollect [
| res |
res := {#first -> -1. #second -> 5 . #three -> -33} asDictionary flatCollect: [:e | { e abs } ].
self assert: res asSet equals: #(1 5 33) asSet.
]
{ #category : #'tests - flatCollect' }
DictionaryTest >> testFlatCollect2 [
| res |
res := {#first -> #(-2 3). #second -> #(-4 5)} asDictionary flatCollect: [:e | e collect: #abs].
self assert: res asSet equals: #(2 3 4 5) asSet.
]
{ #category : #'tests - flatCollect' }
DictionaryTest >> testFlatCollect3 [
| res |
res := {#first -> #(-2 3). #second -> #(-4 5)} asDictionary flatCollect: [:e | {e collect: #abs}].
self assert: res asSet equals: #(#(2 3) #(4 5)) asSet.
]
{ #category : #'tests - testing' }
DictionaryTest >> testHasBindingThatBeginsWith [
| newDict |
newDict := self collectionClass new
at: #abc put: 10;
at: #abcd put: 100;
at: #def put: 20;
yourself.
self assert: (newDict hasBindingThatBeginsWith: 'ab').
self assert: (newDict hasBindingThatBeginsWith: 'def').
self deny: (newDict hasBindingThatBeginsWith: 'defg').
]
{ #category : #'tests - testing' }
DictionaryTest >> testIncludeAssociation [
self assert: (nonEmptyDict includesAssociation: #a -> self elementTwiceIn).
self assert: (nonEmptyDict includesAssociation: (nonEmptyDict associations first)).
]
{ #category : #'tests - testing' }
DictionaryTest >> testIncludes [
| o1 o2 newDict |
self assert: (nonEmptyDict includes: self element).
o1 := 2 @ 3.
o2 := 2 @ 3.
self deny: (o1 == o2).
self assert: (o1 = o2).
newDict := self collectionClass new.
newDict at: #a put: o1.
self assert: (newDict includes: o2).
]
{ #category : #'tests - testing' }
DictionaryTest >> testIncludesAssociationNoValue [
| association dictionary |
association := Association key: #key.
self assert: association value isNil.
dictionary := self collectionClass new.
dictionary add: association.
self assert: (dictionary at: #key) isNil
]
{ #category : #'tests - testing' }
DictionaryTest >> testIncludesAssociationWithValue [
| association dictionary |
association := Association key: #key value: 1.
dictionary := self collectionClass new.
dictionary add: association.
self assert: (dictionary at: #key) = 1
]
{ #category : #'tests - includes' }
DictionaryTest >> testIncludesElementIsNotThere [
"self debug: #testIncludesElementIsNotThere"
self deny: (self nonEmpty includes: self elementNotInForOccurrences).
self assert: (self nonEmpty includes: self nonEmpty anyOne).
self deny: (self empty includes: self elementNotInForOccurrences)
]
{ #category : #'tests - testing' }
DictionaryTest >> testIsDictionary [
self deny: Object new isDictionary.
self assert: nonEmptyDict isDictionary.
self assert: emptyDict isDictionary.
]
{ #category : #'tests - integrity' }
DictionaryTest >> testIsHealthy [
| dict |
self canBeUnhealthy
ifFalse: [
self assert: self nonEmpty isHealthy.
^ self ].
dict := self emptyDict.
[ | a1 a2 |
"we use associations as keys on purpose, because they change their
hash depending on the key"
a1 := 1 -> 2.
a2 := 2 -> 2.
dict
at: a1 put: 2;
at: a2 put: 3.
self assert: dict isHealthy.
a1 key: 0.
a2 key: 0.
self deny: dict isHealthy ]
ensure: [ dict removeAll ]
]
{ #category : #'tests - dictionary key access' }
DictionaryTest >> testKeyAtIdentityValueIfAbsent [
"self run: #testKeyAtValue"
"self debug: #testKeyAtValue"
| dict value result |
dict := self nonEmpty.
value := dict values anyOne.
result := dict keyAtIdentityValue: value ifAbsent: [ nil ].
self assert: (dict at: result) = value.
self assert: (dict keyAtIdentityValue: self valueNotIn ifAbsent: [ nil ]) isNil
]
{ #category : #'tests - dictionary key access' }
DictionaryTest >> testKeyAtValueIfAbsent [
"self run: #testKeyAtValue"
"self debug: #testKeyAtValue"
| dict value result |
dict := self nonEmpty.
value := dict values anyOne.
result := dict keyAtValue: value ifAbsent: [ nil ].
self assert: (dict at: result) = value.
self assert: (dict keyAtValue: self valueNotIn ifAbsent: [ nil ]) isNil
]
{ #category : #'tests - testing' }
DictionaryTest >> testKeyForIdentity [
self assert: (nonEmptyDict keyForIdentity: 30) = #b.
"The value 20 is associated to two different associations"
self assert: (#(a c) includes: (nonEmptyDict keyForIdentity: self elementTwiceIn))
]
{ #category : #'tests - new' }
DictionaryTest >> testNew [
| d |
d := self classToBeTested new: 10.
self assert: d size = 0.
"Why 14? Mysterious"
"self assert: d capacity = 14"
]
{ #category : #'tests - new' }
DictionaryTest >> testNewFrom [
| assocs |
self assert: (self classToBeTested newFrom: {}) = self emptyDict.
self assert: (self classToBeTested newFrom: nonEmptyDict copy) = self nonEmptyDict.
assocs := self nonEmptyDict associations collect: [:each | each copy].
self assert: (self classToBeTested newFrom: assocs) = self nonEmptyDict.
]
{ #category : #'tests - new' }
DictionaryTest >> testNewFromPairs [
| assocs pairs |
assocs := self nonEmptyDict associations.
pairs := OrderedCollection new.
assocs do: [:each |
pairs
add: each key;
add: each value].
0 to: pairs size do: [:i | | dictFromPairs dictFromAssocs |
dictFromPairs := self classToBeTested newFromPairs: (pairs copyFrom: 1 to: i).
dictFromAssocs := self classToBeTested newFrom: (assocs copyFrom: 1 to: (i / 2) floor).
self assert: dictFromPairs = dictFromAssocs].
]
{ #category : #tests }
DictionaryTest >> testNilHashCollision [
"Ensures that fixCollisionsFrom: does the right thing in the presence of a nil key"
| dict key |
self supportsNilKey
ifFalse: [ ^ self ].
dict := self collectionClass new.
key := nil hash. "any key with same hash as nil"
dict at: key hash put: 1.
dict at: nil put: 2.
self assert: (dict includesKey: nil).
dict removeKey: key.
self assert: (dict includesKey: nil).
]
{ #category : #'tests - testing' }
DictionaryTest >> testOccurrencesOf [
"self run:#testOccurrencesOf"
| dict |
dict := self collectionClass new.
dict at: #a put: 1.
dict at: #b put: 2.
dict at: #c put: 1.
dict at: #d put: 3.
dict at: nil put: nil.
dict at: #z put: nil.
self assert: (dict occurrencesOf: 1 ) equals: 2.
self supportsNilKey
ifTrue: [ self assert: (dict occurrencesOf: nil ) equals: 2 ]
ifFalse: [ self assert: (dict occurrencesOf: nil ) equals: 1 ].
]
{ #category : #'tests - comparing' }
DictionaryTest >> testOtherDictionaryEquality [
self otherDictionaryClasses do: [:each | | nonEmptyDict2 |
nonEmptyDict2 := each new.
self deny: self empty = nonEmptyDict2.
self deny: nonEmptyDict2 = self empty.
self nonEmptyDict keysAndValuesDo: [:key :value | nonEmptyDict2 at: key put: value].
self deny: self nonEmptyDict = nonEmptyDict2.
self deny: nonEmptyDict2 = self nonEmptyDict]
]
{ #category : #tests }
DictionaryTest >> testRemoveAll [
"Allows one to remove all elements of a collection"
| dict1 dict2 s2 |
dict1 := self collectionClass new.
dict1
at: #a put:1 ;
at: #b put: 2.
dict2 := dict1 copy.
s2 := dict2 size.
dict1 removeAll.
self assert: dict1 size = 0.
self assert: dict2 size = s2 description: 'the copy has not been modified'.
]
{ #category : #tests }
DictionaryTest >> testSelectIsNotShallowCopy [
"self debug: #testSelectIsNotShallowCopy"
| original even |
original := self collectionClass new.
original at: #one put: 1.
original at: #two put: 2.
even := original select: [:value |value even].
even at: #two put: 'deux'.
self assert: (original at: #two) = 2
description: 'modifying a selection should not modify the original'
]
{ #category : #'tests - printing' }
DictionaryTest >> testStoreOnWithNegativeInteger [
| dictionary |
dictionary := { 'x' -> -1 } as: self classToBeTested.
self
assert: (String streamContents: [ :s | dictionary storeOn: s ])
equals: '((',self classToBeTested name,' new) add: (''x''-> -1); yourself)'
]
{ #category : #requirements }
DictionaryTest >> valueNotIn [
" return a value not included in nonEmpty "
^valueNotIn
]
{ #category : #requirements }
DictionaryTest >> valueNotInNonEmpty [
" return a value not included in nonEmpty"
^ valueNotIn
]