1974
|
1 |
"
|
|
2 |
COPYRIGHT (c) Claus Gittinger / eXept Software AG
|
|
3 |
COPYRIGHT (c) 2016 Jan Vrany
|
|
4 |
All Rights Reserved
|
|
5 |
|
|
6 |
This software is furnished under a license and may be used
|
|
7 |
only in accordance with the terms of that license and with the
|
|
8 |
inclusion of the above copyright notice. This software may not
|
|
9 |
be provided or otherwise made available to, or used by, any
|
|
10 |
other person. No title to or ownership of the software is
|
|
11 |
hereby transferred.
|
|
12 |
"
|
1447
|
13 |
"{ Package: 'stx:goodies/regression' }"
|
296
|
14 |
|
|
15 |
"{ NameSpace: RegressionTests }"
|
|
16 |
|
|
17 |
TestCase subclass:#DictionaryTest
|
|
18 |
instanceVariableNames:''
|
|
19 |
classVariableNames:''
|
|
20 |
poolDictionaries:''
|
1055
|
21 |
category:'tests-Regression-Collections'
|
296
|
22 |
!
|
|
23 |
|
1974
|
24 |
!DictionaryTest class methodsFor:'documentation'!
|
|
25 |
|
|
26 |
copyright
|
|
27 |
"
|
|
28 |
COPYRIGHT (c) Claus Gittinger / eXept Software AG
|
|
29 |
COPYRIGHT (c) 2016 Jan Vrany
|
|
30 |
All Rights Reserved
|
|
31 |
|
|
32 |
This software is furnished under a license and may be used
|
|
33 |
only in accordance with the terms of that license and with the
|
|
34 |
inclusion of the above copyright notice. This software may not
|
|
35 |
be provided or otherwise made available to, or used by, any
|
|
36 |
other person. No title to or ownership of the software is
|
|
37 |
hereby transferred.
|
|
38 |
"
|
|
39 |
! !
|
296
|
40 |
|
|
41 |
!DictionaryTest methodsFor:'testing'!
|
|
42 |
|
|
43 |
testAddAll
|
|
44 |
"(self run: #testAddAll)"
|
1447
|
45 |
|
296
|
46 |
| dict1 dict2 |
|
|
47 |
dict1 := Dictionary new.
|
1447
|
48 |
dict1 at: #a put:1 ; at: #b put: 2.
|
296
|
49 |
dict2 := Dictionary new.
|
|
50 |
dict2 at: #a put: 3 ; at: #c put: 4.
|
|
51 |
dict1 addAll: dict2.
|
|
52 |
self assert: (dict1 at: #a) = 3.
|
|
53 |
self assert: (dict1 at: #b) = 2.
|
|
54 |
self assert: (dict1 at: #c) = 4.
|
|
55 |
!
|
|
56 |
|
|
57 |
testAssociationsSelect
|
|
58 |
|
1547
|
59 |
"(self selector: #testAssociationsSelect) run"
|
296
|
60 |
|
1547
|
61 |
| answer d|
|
296
|
62 |
|
1547
|
63 |
d := Dictionary new.
|
|
64 |
d at: (Array with: #hello with: #world) put: #fooBar.
|
|
65 |
d at: Smalltalk put: #'Smalltalk is the key'.
|
|
66 |
d at: #Smalltalk put: Smalltalk.
|
296
|
67 |
|
1547
|
68 |
answer := d associationsSelect:
|
|
69 |
[:assoc | (assoc key == #Smalltalk) and: [assoc value == Smalltalk]].
|
|
70 |
self should: [answer isKindOf: Dictionary].
|
|
71 |
self should: [answer size == 1].
|
|
72 |
self should: [(answer at: #Smalltalk) == Smalltalk].
|
296
|
73 |
|
1547
|
74 |
answer := d associationsSelect:
|
|
75 |
[:assoc | (assoc key == #NoSuchKey) and: [assoc value == #NoSuchValue]].
|
|
76 |
self should: [answer isKindOf: Dictionary].
|
|
77 |
self should: [answer size == 0]
|
296
|
78 |
!
|
|
79 |
|
|
80 |
testComma
|
|
81 |
"(self run: #testComma)"
|
1447
|
82 |
|
296
|
83 |
| dict1 dict2 dict3 |
|
|
84 |
dict1 := Dictionary new.
|
1447
|
85 |
dict1 at: #a put:1 ; at: #b put: 2.
|
296
|
86 |
dict2 := Dictionary new.
|
|
87 |
dict2 at: #a put: 3 ; at: #c put: 4.
|
|
88 |
dict3 := dict1, dict2.
|
|
89 |
self assert: (dict3 at: #a) = 3.
|
|
90 |
self assert: (dict3 at: #b) = 2.
|
|
91 |
self assert: (dict3 at: #c) = 4.
|
|
92 |
!
|
|
93 |
|
|
94 |
testIncludesAssociation
|
1553
|
95 |
"self debug: #testIncludesAssociation"
|
296
|
96 |
|
1553
|
97 |
| d |
|
|
98 |
d := Dictionary new
|
|
99 |
at: #five put: 5;
|
|
100 |
at: #givemefive put: 5;
|
|
101 |
at: #six put: 6;
|
|
102 |
yourself.
|
1447
|
103 |
|
1553
|
104 |
self assert: (d includesAssociation: (d associationAt: #five)).
|
|
105 |
self assert: (d associationAt: #five) key == #five.
|
|
106 |
self assert: (d associationAt: #five) value == 5.
|
|
107 |
self assert: (d includesAssociation: (#five -> 5)).
|
|
108 |
self assert: (d includesAssociation: (#five -> 6)) not.
|
|
109 |
|
|
110 |
"Modified: / 06-12-2016 / 14:19:15 / cg"
|
296
|
111 |
! !
|
|
112 |
|
|
113 |
!DictionaryTest class methodsFor:'documentation'!
|
|
114 |
|
|
115 |
version
|
|
116 |
^ '$Header$'
|
|
117 |
! !
|
1055
|
118 |
|