1 UnitTests addPrototype: #Dictionary derivedFrom: {TestCase}.
2 "TODO only tests base functionality, add SingleValueMap, EmptyMap, etc."
4 UnitTests Dictionary addSlot: #months1 valued:
6 result: (Dictionary newSize: 12).
8 result add: 'January' -> 31.
9 result at: 'February' put: 29.
10 result at: 'March' put: 31.
11 result add: 'April' -> 30.
12 result at: 'May' put: 31.
13 result at: 'June' put: 30.
14 result add: (Association cloneSettingSlots: #(key value) to: {'July'. 31}).
15 result at: 'August' put: 31.
16 result at: 'September' put: 30.
17 result at: 'October' put: 31.
18 result at: 'November' put: 30.
19 result add: 'December' -> 31.
24 UnitTests Dictionary addSlot: #months2 valued:
26 result: Dictionary new.
28 result at: 'January' put: 31.
29 result add: 'February' -> 29.
30 result at: 'March' put: 31.
31 result at: 'April' put: 30.
32 result add: (Association cloneSettingSlots: #(key value) to: {'May'. 31}).
33 result at: 'June' put: 30.
34 result at: 'July' put: 31.
35 result at: 'August' put: 31.
36 result at: 'September' put: 30.
37 result add: 'October' -> 31.
38 result at: 'November' put: 30.
39 result add: (Association cloneSettingSlots: #(key value) to: {'December'. 31}).
44 UnitTests Dictionary addSlot: #empty valued: Dictionary new.
48 t@(UnitTests Dictionary traits) testSignals
52 t should: [d1 at: 'invalidKey'] raise: Mapping KeyNotFound
53 description: 'KeyNotFound is not signaled from at:'.
55 t should: [t empty anyOne] raise: Collection IsEmpty
56 description: 'IsEmpty is not signaled from anyOne'.
59 t@(UnitTests Dictionary traits) testAccess
64 t assert: (d1 at: 'January') = (d2 at: 'January') description: 'Value at January differs'.
65 t assert: (d1 at: 'December') = (d2 at: 'December') description: 'Value at December differs'.
67 t assert: (d1 at: 'January' ifAbsent: [t signalFailureDescription: 'at:ifAbsent: block should not get evaluated here']) = 31 description: 'Unexpected value at January'.
69 t assert: (d1 keyAtValue: 29) = (d2 keyAtValue: 29) description: 'keyAtValue: 29 differs'.
71 t assert: (d1 includes: 29) description: 'd1 includes: 29 failed'.
72 t deny: (d1 includes: 19) description: 'd1 includes: 19'.
74 t assert: (d1 includesKey: 'January') description: 'd1 includesKey: \'January\' failed'.
75 t deny: (d1 includesKey: 'foobar') description: 'd1 includesKey: \'foobar\''.
77 t assert: (d1 occurrencesOf: 30) = 4 description: '(d1 occurrencesOf: 30) ~= 4'.
80 t@(UnitTests Dictionary traits) testIteration
84 t assert: (t months2 at: key) = (t months1 at: key) description: 'An element differs while iterating on keys'].
86 "Unless we can ensure ordering, the following test doesn't make sense. But, if order can be ensured, this test might be useful."
89 t assert: (t months2 keyAtValue: value) = ( t months1 keyAtValue: value) description: 'An element differs while iterating on values']."
91 t months1 keysAndValuesDo:
93 t assert: (t months2 at: key) = value description: 'An element differs while iterating on keysAndValues'].
96 t@(UnitTests Dictionary traits) testSize
98 t assert: t months1 size = t months2 size description: 'Sizes differ'.
101 t@(UnitTests Dictionary traits) testEquality
103 t assert: t months1 = t months2 description: 'Equality failed'.
104 t deny: t months1 = t empty description: 'False equality with empty dictionary'.
107 t@(UnitTests Dictionary traits) testMutation
112 d1 at: 'January' put: 0.
113 t assert: (d1 occurrencesOf: 31) = 6 description: '(d1 occurrencesOf: 31) ~= 6 after January set to 0'.
114 t deny: (d1 at: 'January') = (d2 at: 'January') description: 'Mutating d1 failed'.
115 t deny: d1 = d2 description: 'd1 = d2 after mutating d1'.
117 d2 at: 'January' put: 0.
118 t assert: d1 = d2 description: 'd1 ~= d2 after mutating d2, too'.
120 d1 remove: 'February'.
121 t deny: d1 = d2 description: 'd1 = d2 after removing February from d1'.
122 t deny: d1 size = d2 size description: 'd1 size = d2 size after removing February from d1'.
124 d2 remove: 'February'.
125 t assert: d1 = d2 description: 'd1 ~= d2 after removing February from d2, too'.
126 t assert: d1 size = d2 size description: 'd1 size ~= d2 size after removing February from d2, too'.
130 t@(UnitTests Dictionary traits) suite
131 [t suiteForSelectors: {
141 UnitTests addPrototype: #IdentityDictionary derivedFrom: {TestCase}.
143 UnitTests IdentityDictionary addSlot: #list1 valued:
145 result: (IdentityDictionary newSize: 4).
147 result add: Boolean -> 10.
148 result at: True put: 20.
149 result add: (Association cloneSettingSlots: #(key value) to: {False. 30}).
154 UnitTests IdentityDictionary addSlot: #list2 valued:
156 result: (IdentityDictionary newSize: 4).
158 result at: Boolean put: 10.
159 result add: (Association cloneSettingSlots: #(key value) to: {True. 20}).
160 result add: False -> 30.
165 UnitTests IdentityDictionary addSlot: #empty valued: IdentityDictionary new.
168 t@(UnitTests IdentityDictionary traits) testSignals
172 t should: [d1 at: 'invalidKey'] raise: Mapping KeyNotFound
173 description: 'KeyNotFound is not signaled from at:'.
175 t should: [t empty anyOne] raise: Collection IsEmpty
176 description: 'IsEmpty is not signaled from anyOne'.
179 t@(UnitTests IdentityDictionary traits) testAccess
184 t assert: (d1 at: Boolean) = (d2 at: Boolean) description: 'Value at Boolean differs'.
185 t assert: (d1 at: True) = (d2 at: True) description: 'Value at True differs'.
187 t assert: (d1 at: False ifAbsent: [t signalFailureDescription: 'at:ifAbsent: block should not get evaluated here']) = 30 description: 'Unexpected value at January'.
189 t assert: (d1 keyAtValue: 30) = (d2 keyAtValue: 30) description: 'keyAtValue: 30 differs'.
191 t assert: (d1 includes: 20) description: 'd1 includes: 20 failed'.
192 t deny: (d1 includes: 100) description: 'd1 includes: 100'.
194 t assert: (d1 includesKey: True) description: 'd1 includesKey: True failed'.
195 t deny: (d1 includesKey: Dictionary) description: 'd1 includesKey: Dictionary'.
197 t assert: (d1 occurrencesOf: 30) = 1 description: '(d1 occurrencesOf: 30) ~= 1'.
200 t@(UnitTests IdentityDictionary traits) testIteration
204 t assert: (t list2 at: key) = (t list1 at: key) description: 'An element differs while iterating on keys'].
208 t assert: (t list2 keyAtValue: value) = ( t list1 keyAtValue: value) description: 'An element differs while iterating on values'].
210 t list1 keysAndValuesDo:
212 t assert: (t list2 at: key) = value description: 'An element differs while iterating on keysAndValues'].
215 t@(UnitTests IdentityDictionary traits) testSize
217 t assert: t list1 size = t list2 size description: 'Sizes differ'.
220 t@(UnitTests IdentityDictionary traits) testEquality
222 t assert: t list1 = t list2 description: 'Equality failed'.
223 t deny: t list1 = t empty description: 'False equality with empty dictionary'.
226 t@(UnitTests IdentityDictionary traits) testMutation
232 t assert: (d1 occurrencesOf: 30) = 0 description: '(d1 occurrencesOf: 30) ~= 0 after False (which was set to 30) was set to 0'.
233 t deny: (d1 at: False) = (d2 at: False) description: 'Mutating d1 failed'.
234 t deny: d1 = d2 description: 'd1 = d2 after mutating d1'.
237 t assert: d1 = d2 description: 'd1 ~= d2 after mutating d2, too'.
240 t deny: d1 = d2 description: 'd1 = d2 after removing Boolean from d1'.
241 t deny: d1 size = d2 size description: 'd1 size = d2 size after removing Boolean from d1'.
244 t assert: d1 = d2 description: 'd1 ~= d2 after removing Boolean from d2, too'.
245 t assert: d1 size = d2 size description: 'd1 size ~= d2 size after removing Boolean from d2, too'.
248 t@(UnitTests IdentityDictionary traits) suite
249 [t suiteForSelectors: {