author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Wed, 29 Jun 2016 21:40:53 +0100 | |
branch | jv |
changeset 1499 | 26a16a04219b |
parent 1055 | 0d0b2641d00b |
child 1500 | d406a10b2965 |
permissions | -rw-r--r-- |
1499
26a16a04219b
Package renamed from exept:regression to stx:goodies/regression. Hooray!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1055
diff
changeset
|
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)" |
|
17 |
||
18 |
| dict1 dict2 | |
|
19 |
dict1 := Dictionary new. |
|
20 |
dict1 at: #a put:1 ; at: #b put: 2. |
|
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 |
||
35 |
d _ Dictionary new. |
|
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 |
||
40 |
answer _ d associationsSelect: |
|
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 |
||
46 |
answer _ d associationsSelect: |
|
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)" |
|
54 |
||
55 |
| dict1 dict2 dict3 | |
|
56 |
dict1 := Dictionary new. |
|
57 |
dict1 at: #a put:1 ; at: #b put: 2. |
|
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 | |
|
70 |
d := Dictionary new |
|
71 |
at: #five put: 5; |
|
72 |
at: #givemefive put: 5; |
|
73 |
at: #six put: 6; |
|
74 |
yourself. |
|
75 |
||
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 |