1447
|
1 |
"{ Package: 'stx:goodies/regression' }"
|
296
|
2 |
|
|
3 |
"{ NameSpace: RegressionTests }"
|
|
4 |
|
|
5 |
TestCase subclass:#DictionaryTest
|
2008
|
6 |
instanceVariableNames:'dictionaryClass'
|
296
|
7 |
classVariableNames:''
|
|
8 |
poolDictionaries:''
|
1055
|
9 |
category:'tests-Regression-Collections'
|
296
|
10 |
!
|
|
11 |
|
|
12 |
|
2166
|
13 |
!DictionaryTest methodsFor:'initialize / release'!
|
2008
|
14 |
|
|
15 |
setUp
|
|
16 |
dictionaryClass := Dictionary.
|
|
17 |
"/ dictionaryClass := SmallDictionary.
|
|
18 |
|
|
19 |
"Created: / 14-09-2018 / 16:38:30 / Stefan Vogel"
|
|
20 |
! !
|
|
21 |
|
296
|
22 |
!DictionaryTest methodsFor:'testing'!
|
|
23 |
|
|
24 |
testAddAll
|
2008
|
25 |
"(self run: #testAddAll)"
|
1447
|
26 |
|
2008
|
27 |
| dict1 dict2 |
|
|
28 |
dict1 := dictionaryClass new.
|
|
29 |
dict1 at: #a put:1 ; at: #b put: 2.
|
|
30 |
dict2 := dictionaryClass new.
|
|
31 |
dict2 at: #a put: 3 ; at: #c put: 4.
|
|
32 |
dict1 addAll: dict2.
|
|
33 |
self assert: (dict1 at: #a) = 3.
|
|
34 |
self assert: (dict1 at: #b) = 2.
|
|
35 |
self assert: (dict1 at: #c) = 4.
|
|
36 |
|
|
37 |
"Modified: / 14-09-2018 / 16:38:54 / Stefan Vogel"
|
296
|
38 |
!
|
|
39 |
|
|
40 |
testAssociationsSelect
|
|
41 |
|
1547
|
42 |
"(self selector: #testAssociationsSelect) run"
|
296
|
43 |
|
1547
|
44 |
| answer d|
|
296
|
45 |
|
2008
|
46 |
d := dictionaryClass new.
|
1547
|
47 |
d at: (Array with: #hello with: #world) put: #fooBar.
|
|
48 |
d at: Smalltalk put: #'Smalltalk is the key'.
|
|
49 |
d at: #Smalltalk put: Smalltalk.
|
296
|
50 |
|
1547
|
51 |
answer := d associationsSelect:
|
|
52 |
[:assoc | (assoc key == #Smalltalk) and: [assoc value == Smalltalk]].
|
2008
|
53 |
self should: [answer isKindOf: dictionaryClass].
|
1547
|
54 |
self should: [answer size == 1].
|
|
55 |
self should: [(answer at: #Smalltalk) == Smalltalk].
|
296
|
56 |
|
1547
|
57 |
answer := d associationsSelect:
|
|
58 |
[:assoc | (assoc key == #NoSuchKey) and: [assoc value == #NoSuchValue]].
|
2008
|
59 |
self should: [answer isKindOf: dictionaryClass].
|
1547
|
60 |
self should: [answer size == 0]
|
2008
|
61 |
|
|
62 |
"Modified: / 14-09-2018 / 16:39:05 / Stefan Vogel"
|
296
|
63 |
!
|
|
64 |
|
|
65 |
testComma
|
2008
|
66 |
"(self run: #testComma)"
|
1447
|
67 |
|
2008
|
68 |
| dict1 dict2 dict3 |
|
|
69 |
dict1 := dictionaryClass new.
|
|
70 |
dict1 at: #a put:1 ; at: #b put: 2.
|
|
71 |
dict2 := dictionaryClass new.
|
|
72 |
dict2 at: #a put: 3 ; at: #c put: 4.
|
|
73 |
dict3 := dict1, dict2.
|
|
74 |
self assert: (dict3 at: #a) = 3.
|
|
75 |
self assert: (dict3 at: #b) = 2.
|
|
76 |
self assert: (dict3 at: #c) = 4.
|
|
77 |
|
|
78 |
"Modified: / 14-09-2018 / 16:39:14 / Stefan Vogel"
|
296
|
79 |
!
|
|
80 |
|
|
81 |
testIncludesAssociation
|
1553
|
82 |
"self debug: #testIncludesAssociation"
|
296
|
83 |
|
1553
|
84 |
| d |
|
2008
|
85 |
d := dictionaryClass new
|
1553
|
86 |
at: #five put: 5;
|
|
87 |
at: #givemefive put: 5;
|
|
88 |
at: #six put: 6;
|
|
89 |
yourself.
|
1447
|
90 |
|
1553
|
91 |
self assert: (d includesAssociation: (d associationAt: #five)).
|
|
92 |
self assert: (d associationAt: #five) key == #five.
|
|
93 |
self assert: (d associationAt: #five) value == 5.
|
|
94 |
self assert: (d includesAssociation: (#five -> 5)).
|
|
95 |
self assert: (d includesAssociation: (#five -> 6)) not.
|
|
96 |
|
|
97 |
"Modified: / 06-12-2016 / 14:19:15 / cg"
|
2008
|
98 |
"Modified: / 14-09-2018 / 16:39:21 / Stefan Vogel"
|
1572
|
99 |
!
|
|
100 |
|
|
101 |
testRemoveAllDeclareAll
|
|
102 |
"self debug: #testRemoveAllDeclareAll"
|
|
103 |
|
|
104 |
"/ verifies that we can restore a dictionaries original contents
|
|
105 |
"/ by making a copy of it, then redeclaring from the copy.
|
|
106 |
"/ (needed by the refactorybrowser)
|
|
107 |
|
|
108 |
| d copyOfIt |
|
|
109 |
|
2008
|
110 |
d := dictionaryClass new
|
1572
|
111 |
at: #five put: (5@5);
|
|
112 |
at: #givemefive put: (55@55);
|
|
113 |
at: #six put: (6@6);
|
|
114 |
yourself.
|
|
115 |
|
|
116 |
copyOfIt := d copy.
|
|
117 |
d keysAndValuesDo:[:k :v |
|
|
118 |
self assert: (copyOfIt at:k) == v.
|
|
119 |
].
|
|
120 |
|
|
121 |
"/ add something
|
|
122 |
d at:#seven put:(7@7).
|
|
123 |
|
|
124 |
"/ removeall - redeclare
|
|
125 |
d removeAll; declareAllFrom:copyOfIt.
|
|
126 |
|
|
127 |
self assert: (d size = copyOfIt size).
|
|
128 |
self assert: (d keys = copyOfIt keys).
|
|
129 |
d keysAndValuesDo:[:k :v |
|
|
130 |
self assert: (copyOfIt at:k) == v.
|
|
131 |
].
|
|
132 |
|
|
133 |
"Created: / 06-02-2017 / 12:26:22 / cg"
|
2008
|
134 |
"Modified: / 14-09-2018 / 16:39:28 / Stefan Vogel"
|
296
|
135 |
! !
|
|
136 |
|
|
137 |
!DictionaryTest class methodsFor:'documentation'!
|
|
138 |
|
|
139 |
version
|
|
140 |
^ '$Header$'
|
|
141 |
! !
|
1055
|
142 |
|