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 |
|
1547
|
31 |
"(self selector: #testAssociationsSelect) run"
|
296
|
32 |
|
1547
|
33 |
| answer d|
|
296
|
34 |
|
1547
|
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.
|
296
|
39 |
|
1547
|
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].
|
296
|
45 |
|
1547
|
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]
|
296
|
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
|
1553
|
67 |
"self debug: #testIncludesAssociation"
|
296
|
68 |
|
1553
|
69 |
| d |
|
|
70 |
d := Dictionary new
|
|
71 |
at: #five put: 5;
|
|
72 |
at: #givemefive put: 5;
|
|
73 |
at: #six put: 6;
|
|
74 |
yourself.
|
1447
|
75 |
|
1553
|
76 |
self assert: (d includesAssociation: (d associationAt: #five)).
|
|
77 |
self assert: (d associationAt: #five) key == #five.
|
|
78 |
self assert: (d associationAt: #five) value == 5.
|
|
79 |
self assert: (d includesAssociation: (#five -> 5)).
|
|
80 |
self assert: (d includesAssociation: (#five -> 6)) not.
|
|
81 |
|
|
82 |
"Modified: / 06-12-2016 / 14:19:15 / cg"
|
1572
|
83 |
!
|
|
84 |
|
|
85 |
testRemoveAllDeclareAll
|
|
86 |
"self debug: #testRemoveAllDeclareAll"
|
|
87 |
|
|
88 |
"/ verifies that we can restore a dictionaries original contents
|
|
89 |
"/ by making a copy of it, then redeclaring from the copy.
|
|
90 |
"/ (needed by the refactorybrowser)
|
|
91 |
|
|
92 |
| d copyOfIt |
|
|
93 |
|
|
94 |
d := Dictionary new
|
|
95 |
at: #five put: (5@5);
|
|
96 |
at: #givemefive put: (55@55);
|
|
97 |
at: #six put: (6@6);
|
|
98 |
yourself.
|
|
99 |
|
|
100 |
copyOfIt := d copy.
|
|
101 |
d keysAndValuesDo:[:k :v |
|
|
102 |
self assert: (copyOfIt at:k) == v.
|
|
103 |
].
|
|
104 |
|
|
105 |
"/ add something
|
|
106 |
d at:#seven put:(7@7).
|
|
107 |
|
|
108 |
"/ removeall - redeclare
|
|
109 |
d removeAll; declareAllFrom:copyOfIt.
|
|
110 |
|
|
111 |
self assert: (d size = copyOfIt size).
|
|
112 |
self assert: (d keys = copyOfIt keys).
|
|
113 |
d keysAndValuesDo:[:k :v |
|
|
114 |
self assert: (copyOfIt at:k) == v.
|
|
115 |
].
|
|
116 |
|
|
117 |
"Created: / 06-02-2017 / 12:26:22 / cg"
|
296
|
118 |
! !
|
|
119 |
|
|
120 |
!DictionaryTest class methodsFor:'documentation'!
|
|
121 |
|
|
122 |
version
|
|
123 |
^ '$Header$'
|
|
124 |
! !
|
1055
|
125 |
|