author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Sat, 19 Nov 2016 10:43:57 +0000 | |
branch | jv |
changeset 1544 | 657989d600f7 |
parent 1500 | d406a10b2965 |
child 1564 | 2a4963ef3a4a |
permissions | -rw-r--r-- |
1447 | 1 |
"{ Package: 'stx:goodies/regression' }" |
296 | 2 |
|
3 |
"{ NameSpace: RegressionTests }" |
|
4 |
||
5 |
TestCase subclass:#DictionaryTest |
|
6 |
instanceVariableNames:'' |
|
7 |
classVariableNames:'' |
|
8 |
poolDictionaries:'' |
|
1055 | 9 |
category:'tests-Regression-Collections' |
296 | 10 |
! |
11 |
||
12 |
||
13 |
!DictionaryTest methodsFor:'testing'! |
|
14 |
||
15 |
testAddAll |
|
16 |
"(self run: #testAddAll)" |
|
1447 | 17 |
|
296 | 18 |
| dict1 dict2 | |
19 |
dict1 := Dictionary new. |
|
1447 | 20 |
dict1 at: #a put:1 ; at: #b put: 2. |
296 | 21 |
dict2 := Dictionary new. |
22 |
dict2 at: #a put: 3 ; at: #c put: 4. |
|
23 |
dict1 addAll: dict2. |
|
24 |
self assert: (dict1 at: #a) = 3. |
|
25 |
self assert: (dict1 at: #b) = 2. |
|
26 |
self assert: (dict1 at: #c) = 4. |
|
27 |
! |
|
28 |
||
29 |
testAssociationsSelect |
|
30 |
||
31 |
"(self selector: #testAssociationsSelect) run" |
|
32 |
||
33 |
| answer d| |
|
34 |
||
1544
657989d600f7
Fixed `DictionaryTests`: Do not use Smallalk-80-style `_` assignments
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1500
diff
changeset
|
35 |
d := Dictionary new. |
296 | 36 |
d at: (Array with: #hello with: #world) put: #fooBar. |
37 |
d at: Smalltalk put: #'Smalltalk is the key'. |
|
38 |
d at: #Smalltalk put: Smalltalk. |
|
39 |
||
1544
657989d600f7
Fixed `DictionaryTests`: Do not use Smallalk-80-style `_` assignments
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1500
diff
changeset
|
40 |
answer := d associationsSelect: |
296 | 41 |
[:assoc | (assoc key == #Smalltalk) and: [assoc value == Smalltalk]]. |
42 |
self should: [answer isKindOf: Dictionary]. |
|
43 |
self should: [answer size == 1]. |
|
44 |
self should: [(answer at: #Smalltalk) == Smalltalk]. |
|
45 |
||
1544
657989d600f7
Fixed `DictionaryTests`: Do not use Smallalk-80-style `_` assignments
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1500
diff
changeset
|
46 |
answer := d associationsSelect: |
296 | 47 |
[:assoc | (assoc key == #NoSuchKey) and: [assoc value == #NoSuchValue]]. |
48 |
self should: [answer isKindOf: Dictionary]. |
|
49 |
self should: [answer size == 0] |
|
50 |
! |
|
51 |
||
52 |
testComma |
|
53 |
"(self run: #testComma)" |
|
1447 | 54 |
|
296 | 55 |
| dict1 dict2 dict3 | |
56 |
dict1 := Dictionary new. |
|
1447 | 57 |
dict1 at: #a put:1 ; at: #b put: 2. |
296 | 58 |
dict2 := Dictionary new. |
59 |
dict2 at: #a put: 3 ; at: #c put: 4. |
|
60 |
dict3 := dict1, dict2. |
|
61 |
self assert: (dict3 at: #a) = 3. |
|
62 |
self assert: (dict3 at: #b) = 2. |
|
63 |
self assert: (dict3 at: #c) = 4. |
|
64 |
! |
|
65 |
||
66 |
testIncludesAssociation |
|
67 |
"self debug: #testIncludesAssociation" |
|
68 |
||
69 |
| d | |
|
1447 | 70 |
d := Dictionary new |
71 |
at: #five put: 5; |
|
296 | 72 |
at: #givemefive put: 5; |
73 |
at: #six put: 6; |
|
74 |
yourself. |
|
1447 | 75 |
|
296 | 76 |
self assert: (d includesAssociation: (d associationAt: #five)). |
77 |
self assert: (d includesAssociation: (#five -> 5)). |
|
78 |
self assert: (d includesAssociation: (#five -> 6)) not. |
|
79 |
! ! |
|
80 |
||
81 |
!DictionaryTest class methodsFor:'documentation'! |
|
82 |
||
83 |
version |
|
84 |
^ '$Header$' |
|
85 |
! ! |
|
1055 | 86 |