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