228
|
1 |
"{ Package: 'exept:regression' }"
|
|
2 |
|
245
|
3 |
"{ NameSpace: RegressionTests }"
|
|
4 |
|
228
|
5 |
TestCase subclass:#BinaryTreeTester
|
|
6 |
instanceVariableNames:''
|
|
7 |
classVariableNames:''
|
|
8 |
poolDictionaries:''
|
590
|
9 |
category:'tests-Regression'
|
228
|
10 |
!
|
|
11 |
|
|
12 |
!BinaryTreeTester class methodsFor:'documentation'!
|
|
13 |
|
|
14 |
documentation
|
|
15 |
"
|
|
16 |
documentation to be added.
|
|
17 |
|
|
18 |
[author:]
|
|
19 |
Claus Gittinger (cg@alan)
|
|
20 |
|
|
21 |
[instance variables:]
|
|
22 |
|
|
23 |
[class variables:]
|
|
24 |
|
|
25 |
[see also:]
|
|
26 |
|
|
27 |
"
|
|
28 |
!
|
|
29 |
|
|
30 |
history
|
|
31 |
"Created: / 9.12.2003 / 19:34:33 / cg"
|
|
32 |
! !
|
|
33 |
|
590
|
34 |
!BinaryTreeTester class methodsFor:'queries'!
|
|
35 |
|
|
36 |
coveredClassNames
|
|
37 |
^ #( BinaryTree )
|
|
38 |
|
|
39 |
"Created: / 06-07-2011 / 21:42:34 / cg"
|
|
40 |
! !
|
|
41 |
|
228
|
42 |
!BinaryTreeTester methodsFor:'initialize / release'!
|
|
43 |
|
|
44 |
setUp
|
|
45 |
"common setup - invoked before testing."
|
|
46 |
|
|
47 |
super setUp
|
|
48 |
!
|
|
49 |
|
|
50 |
tearDown
|
|
51 |
"common cleanup - invoked after testing."
|
|
52 |
|
|
53 |
super tearDown
|
|
54 |
! !
|
|
55 |
|
|
56 |
!BinaryTreeTester methodsFor:'tests'!
|
|
57 |
|
|
58 |
exhaustive_test03_removing
|
|
59 |
|bt|
|
|
60 |
|
|
61 |
#(10 9 8 7 6 5 4 3 2 1) permutationsDo:[:sequenceToRemoveElements |
|
|
62 |
bt := BinaryTree new.
|
|
63 |
bt addAll:#(1 2 3 4 5 6 7 8 9 10).
|
|
64 |
|
|
65 |
|
|
66 |
sequenceToRemoveElements do:[:each |
|
|
67 |
bt remove:each.
|
|
68 |
self assert: ( bt includes:each ) not.
|
|
69 |
].
|
|
70 |
self assert: ( bt size == 0 ).
|
|
71 |
|
|
72 |
sequenceToRemoveElements do:[:each |
|
|
73 |
bt add:each.
|
|
74 |
self assert: ( bt includes:each ).
|
|
75 |
].
|
|
76 |
self assert: ( bt size == 10 ).
|
|
77 |
].
|
|
78 |
|
|
79 |
"
|
|
80 |
self run:#exhaustive_test03_removing
|
|
81 |
self new exhaustive_test03_removing
|
|
82 |
"
|
|
83 |
!
|
|
84 |
|
|
85 |
test01_empty
|
|
86 |
|bt|
|
|
87 |
|
|
88 |
bt := BinaryTree new.
|
|
89 |
self assert: ( bt size == 0 ).
|
|
90 |
self assert: ( bt isEmpty ).
|
|
91 |
self assert: ( bt asArray = #() ).
|
|
92 |
|
|
93 |
"
|
|
94 |
self run:#test01_empty
|
|
95 |
self new test01_empty
|
|
96 |
"
|
|
97 |
!
|
|
98 |
|
|
99 |
test02_adding
|
|
100 |
|bt|
|
|
101 |
|
|
102 |
bt := BinaryTree new.
|
|
103 |
|
591
|
104 |
self assert: ( bt includes:1 ) not.
|
|
105 |
self assert: ( bt includesIdentical:1 ) not.
|
|
106 |
|
228
|
107 |
bt add:1.
|
|
108 |
self assert: ( bt size == 1 ).
|
|
109 |
self assert: ( bt notEmpty ).
|
|
110 |
self assert: ( bt asArray = #(1) ).
|
591
|
111 |
self assert: ( bt includes:1 ).
|
|
112 |
self assert: ( bt includesIdentical:1 ).
|
228
|
113 |
|
|
114 |
bt add:2.
|
|
115 |
self assert: ( bt size == 2 ).
|
|
116 |
self assert: ( bt asArray = #(1 2) ).
|
|
117 |
|
|
118 |
bt addAll:#(3 4 5 6 7 8 9 10).
|
|
119 |
self assert: ( bt size == 10 ).
|
|
120 |
self assert: ( bt asArray = #(1 2 3 4 5 6 7 8 9 10) ).
|
|
121 |
|
245
|
122 |
bt add:1.
|
|
123 |
self assert: ( bt size == 11 ).
|
|
124 |
self assert: ( bt asArray = #(1 1 2 3 4 5 6 7 8 9 10) ).
|
|
125 |
|
228
|
126 |
"
|
|
127 |
self run:#test02_adding
|
|
128 |
self new test02_adding
|
|
129 |
"
|
591
|
130 |
|
|
131 |
"Modified: / 06-07-2011 / 21:48:24 / cg"
|
228
|
132 |
!
|
|
133 |
|
|
134 |
test03_removing
|
|
135 |
|bt|
|
|
136 |
|
|
137 |
bt := BinaryTree new.
|
591
|
138 |
self should:[ bt remove:11111 ] raise:Error.
|
|
139 |
self should:[ bt removeIdentical:11111 ] raise:Error.
|
|
140 |
|
228
|
141 |
bt addAll:#(1 2 3 4 5 6 7 8 9 10).
|
|
142 |
|
|
143 |
self assert: ( bt size == 10 ).
|
|
144 |
self assert: ( bt asArray = #(1 2 3 4 5 6 7 8 9 10) ).
|
|
145 |
|
591
|
146 |
self should:[ bt remove:11111 ] raise:Error.
|
|
147 |
self should:[ bt removeIdentical:11111 ] raise:Error.
|
|
148 |
|
228
|
149 |
#(4 2 1 3 5 6) do:[:toRemove |
|
|
150 |
|t|
|
|
151 |
|
|
152 |
bt := BinaryTree new.
|
|
153 |
bt addAll:#(1 2 3 4 5 6 7 8 9 10).
|
|
154 |
|
|
155 |
bt remove:toRemove.
|
|
156 |
self assert: ( bt includes:toRemove ) not.
|
|
157 |
self assert: ( bt size == 9 ).
|
|
158 |
|
|
159 |
t := #(1 2 3 4 5 6 7 8 9 10) asOrderedCollection.
|
|
160 |
t remove:toRemove.
|
|
161 |
|
|
162 |
self assert:( bt asArray = t asArray ).
|
|
163 |
].
|
|
164 |
|
|
165 |
"
|
|
166 |
self run:#test03_removing
|
|
167 |
self new test03_removing
|
|
168 |
"
|
591
|
169 |
|
|
170 |
"Modified: / 06-07-2011 / 21:50:16 / cg"
|
228
|
171 |
!
|
|
172 |
|
|
173 |
test04_addingRemoving
|
|
174 |
|allSelectors bt|
|
|
175 |
|
|
176 |
allSelectors := OrderedCollection new.
|
|
177 |
Smalltalk allClassesDo:[:cls |
|
|
178 |
cls instAndClassSelectorsAndMethodsDo:[:sel :mthd |
|
|
179 |
allSelectors add:sel.
|
|
180 |
].
|
|
181 |
].
|
|
182 |
|
|
183 |
bt := BinaryTree new.
|
|
184 |
allSelectors do:[:sel |
|
|
185 |
bt add:sel
|
|
186 |
].
|
|
187 |
self assert:(bt size == allSelectors size).
|
|
188 |
|
|
189 |
allSelectors do:[:sel |
|
|
190 |
self assert:(bt includesIdentical:sel)
|
|
191 |
].
|
|
192 |
|
|
193 |
allSelectors do:[:sel |
|
|
194 |
bt removeIdentical:sel
|
|
195 |
].
|
|
196 |
self assert:(bt isEmpty).
|
|
197 |
|
|
198 |
"
|
|
199 |
self run:#test04_addingRemoving
|
|
200 |
self new test04_addingRemoving
|
|
201 |
"
|
|
202 |
! !
|
|
203 |
|
|
204 |
!BinaryTreeTester class methodsFor:'documentation'!
|
|
205 |
|
591
|
206 |
version_CVS
|
228
|
207 |
^ '$Header$'
|
|
208 |
! !
|