author | Claus Gittinger <cg@exept.de> |
Tue, 25 Feb 2020 17:19:49 +0100 | |
changeset 2586 | 7dc7be5a6f3d |
parent 2257 | 17a046d635e4 |
permissions | -rw-r--r-- |
1447 | 1 |
"{ Package: 'stx:goodies/regression' }" |
228 | 2 |
|
245 | 3 |
"{ NameSpace: RegressionTests }" |
4 |
||
228 | 5 |
TestCase subclass:#BinaryTreeTester |
6 |
instanceVariableNames:'' |
|
7 |
classVariableNames:'' |
|
8 |
poolDictionaries:'' |
|
1065
f0df51e67b06
class: RegressionTests::BinaryTreeTester
Claus Gittinger <cg@exept.de>
parents:
591
diff
changeset
|
9 |
category:'tests-Regression-Collections' |
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:'tests'! |
43 |
||
44 |
exhaustive_test03_removing |
|
45 |
|bt| |
|
46 |
||
47 |
#(10 9 8 7 6 5 4 3 2 1) permutationsDo:[:sequenceToRemoveElements | |
|
48 |
bt := BinaryTree new. |
|
49 |
bt addAll:#(1 2 3 4 5 6 7 8 9 10). |
|
50 |
||
51 |
||
52 |
sequenceToRemoveElements do:[:each | |
|
53 |
bt remove:each. |
|
54 |
self assert: ( bt includes:each ) not. |
|
55 |
]. |
|
56 |
self assert: ( bt size == 0 ). |
|
57 |
||
58 |
sequenceToRemoveElements do:[:each | |
|
59 |
bt add:each. |
|
60 |
self assert: ( bt includes:each ). |
|
61 |
]. |
|
62 |
self assert: ( bt size == 10 ). |
|
63 |
]. |
|
64 |
||
65 |
" |
|
66 |
self run:#exhaustive_test03_removing |
|
67 |
self new exhaustive_test03_removing |
|
68 |
" |
|
69 |
! |
|
70 |
||
71 |
test01_empty |
|
72 |
|bt| |
|
73 |
||
74 |
bt := BinaryTree new. |
|
75 |
self assert: ( bt size == 0 ). |
|
76 |
self assert: ( bt isEmpty ). |
|
77 |
self assert: ( bt asArray = #() ). |
|
78 |
||
79 |
" |
|
80 |
self run:#test01_empty |
|
81 |
self new test01_empty |
|
82 |
" |
|
83 |
! |
|
84 |
||
85 |
test02_adding |
|
86 |
|bt| |
|
87 |
||
88 |
bt := BinaryTree new. |
|
89 |
||
591 | 90 |
self assert: ( bt includes:1 ) not. |
91 |
self assert: ( bt includesIdentical:1 ) not. |
|
92 |
||
228 | 93 |
bt add:1. |
94 |
self assert: ( bt size == 1 ). |
|
95 |
self assert: ( bt notEmpty ). |
|
96 |
self assert: ( bt asArray = #(1) ). |
|
591 | 97 |
self assert: ( bt includes:1 ). |
98 |
self assert: ( bt includesIdentical:1 ). |
|
228 | 99 |
|
100 |
bt add:2. |
|
101 |
self assert: ( bt size == 2 ). |
|
102 |
self assert: ( bt asArray = #(1 2) ). |
|
103 |
||
104 |
bt addAll:#(3 4 5 6 7 8 9 10). |
|
105 |
self assert: ( bt size == 10 ). |
|
106 |
self assert: ( bt asArray = #(1 2 3 4 5 6 7 8 9 10) ). |
|
107 |
||
245 | 108 |
bt add:1. |
109 |
self assert: ( bt size == 11 ). |
|
110 |
self assert: ( bt asArray = #(1 1 2 3 4 5 6 7 8 9 10) ). |
|
111 |
||
228 | 112 |
" |
113 |
self run:#test02_adding |
|
114 |
self new test02_adding |
|
115 |
" |
|
591 | 116 |
|
117 |
"Modified: / 06-07-2011 / 21:48:24 / cg" |
|
228 | 118 |
! |
119 |
||
120 |
test03_removing |
|
121 |
|bt| |
|
122 |
||
123 |
bt := BinaryTree new. |
|
591 | 124 |
self should:[ bt remove:11111 ] raise:Error. |
125 |
self should:[ bt removeIdentical:11111 ] raise:Error. |
|
126 |
||
228 | 127 |
bt addAll:#(1 2 3 4 5 6 7 8 9 10). |
128 |
||
129 |
self assert: ( bt size == 10 ). |
|
130 |
self assert: ( bt asArray = #(1 2 3 4 5 6 7 8 9 10) ). |
|
131 |
||
591 | 132 |
self should:[ bt remove:11111 ] raise:Error. |
133 |
self should:[ bt removeIdentical:11111 ] raise:Error. |
|
134 |
||
228 | 135 |
#(4 2 1 3 5 6) do:[:toRemove | |
136 |
|t| |
|
137 |
||
138 |
bt := BinaryTree new. |
|
139 |
bt addAll:#(1 2 3 4 5 6 7 8 9 10). |
|
140 |
||
141 |
bt remove:toRemove. |
|
142 |
self assert: ( bt includes:toRemove ) not. |
|
143 |
self assert: ( bt size == 9 ). |
|
144 |
||
145 |
t := #(1 2 3 4 5 6 7 8 9 10) asOrderedCollection. |
|
146 |
t remove:toRemove. |
|
147 |
||
148 |
self assert:( bt asArray = t asArray ). |
|
149 |
]. |
|
150 |
||
151 |
" |
|
152 |
self run:#test03_removing |
|
153 |
self new test03_removing |
|
154 |
" |
|
591 | 155 |
|
156 |
"Modified: / 06-07-2011 / 21:50:16 / cg" |
|
228 | 157 |
! |
158 |
||
159 |
test04_addingRemoving |
|
160 |
|allSelectors bt| |
|
161 |
||
162 |
allSelectors := OrderedCollection new. |
|
163 |
Smalltalk allClassesDo:[:cls | |
|
164 |
cls instAndClassSelectorsAndMethodsDo:[:sel :mthd | |
|
165 |
allSelectors add:sel. |
|
166 |
]. |
|
167 |
]. |
|
168 |
||
169 |
bt := BinaryTree new. |
|
170 |
allSelectors do:[:sel | |
|
171 |
bt add:sel |
|
172 |
]. |
|
173 |
self assert:(bt size == allSelectors size). |
|
174 |
||
175 |
allSelectors do:[:sel | |
|
176 |
self assert:(bt includesIdentical:sel) |
|
177 |
]. |
|
178 |
||
179 |
allSelectors do:[:sel | |
|
180 |
bt removeIdentical:sel |
|
181 |
]. |
|
182 |
self assert:(bt isEmpty). |
|
183 |
||
184 |
" |
|
185 |
self run:#test04_addingRemoving |
|
186 |
self new test04_addingRemoving |
|
187 |
" |
|
188 |
! ! |
|
189 |
||
190 |
!BinaryTreeTester class methodsFor:'documentation'! |
|
191 |
||
591 | 192 |
version_CVS |
228 | 193 |
^ '$Header$' |
194 |
! ! |
|
1065
f0df51e67b06
class: RegressionTests::BinaryTreeTester
Claus Gittinger <cg@exept.de>
parents:
591
diff
changeset
|
195 |