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"
|
296
|
83 |
! !
|
|
84 |
|
|
85 |
!DictionaryTest class methodsFor:'documentation'!
|
|
86 |
|
|
87 |
version
|
|
88 |
^ '$Header$'
|
|
89 |
! !
|
1055
|
90 |
|