1447
|
1 |
"{ Package: 'stx:goodies/regression' }"
|
171
|
2 |
|
|
3 |
"{ NameSpace: RegressionTests }"
|
|
4 |
|
|
5 |
TestCase subclass:#QueueTest
|
|
6 |
instanceVariableNames:''
|
|
7 |
classVariableNames:''
|
|
8 |
poolDictionaries:''
|
1057
|
9 |
category:'tests-Regression-Collections'
|
171
|
10 |
!
|
|
11 |
|
|
12 |
|
1534
|
13 |
!QueueTest class methodsFor:'queries'!
|
|
14 |
|
|
15 |
coveredClassNames
|
|
16 |
^ #( Queue )
|
|
17 |
! !
|
|
18 |
|
1691
|
19 |
!QueueTest methodsFor:'helpers'!
|
|
20 |
|
|
21 |
removeAllSize:size fill:fill
|
|
22 |
|
|
23 |
|q|
|
|
24 |
|
|
25 |
q := Queue new:size.
|
|
26 |
|
|
27 |
1 to:fill do:[:i|
|
|
28 |
q nextPut:i.
|
|
29 |
].
|
|
30 |
q removeAll.
|
|
31 |
self assert:q isEmpty.
|
|
32 |
! !
|
|
33 |
|
|
34 |
!QueueTest methodsFor:'testing'!
|
171
|
35 |
|
|
36 |
testBasic1
|
|
37 |
|
|
38 |
|q el|
|
|
39 |
|
|
40 |
q := Queue new:5.
|
|
41 |
self assert:q isEmpty.
|
|
42 |
self assert:q size == 0.
|
|
43 |
q nextPut:1.
|
|
44 |
self assert:q notEmpty.
|
|
45 |
self assert:q size == 1.
|
|
46 |
q nextPut:2.
|
|
47 |
self assert:q notEmpty.
|
|
48 |
self assert:q size == 2.
|
|
49 |
el := q next.
|
|
50 |
self assert:q notEmpty.
|
|
51 |
self assert:q size == 1.
|
|
52 |
self assert:(el==1).
|
|
53 |
el := q next.
|
|
54 |
self assert:q isEmpty.
|
|
55 |
self assert:q size == 0.
|
|
56 |
self assert:(el==2).
|
|
57 |
|
|
58 |
"
|
1447
|
59 |
self new testBasic1
|
171
|
60 |
"
|
|
61 |
!
|
|
62 |
|
|
63 |
testBasic2
|
|
64 |
|
|
65 |
|q el|
|
|
66 |
|
|
67 |
q := Queue new:5.
|
|
68 |
self assert:q isEmpty.
|
|
69 |
self assert:q size == 0.
|
|
70 |
q nextPut:1.
|
|
71 |
q nextPut:2.
|
|
72 |
q nextPut:3.
|
|
73 |
q nextPut:4.
|
|
74 |
q nextPut:5.
|
|
75 |
el := q next.
|
|
76 |
self assert:(el==1).
|
|
77 |
el := q next.
|
|
78 |
self assert:(el==2).
|
|
79 |
el := q next.
|
|
80 |
self assert:(el==3).
|
|
81 |
el := q next.
|
|
82 |
self assert:(el==4).
|
|
83 |
el := q next.
|
|
84 |
self assert:(el==5).
|
|
85 |
|
|
86 |
"
|
1447
|
87 |
self new testBasic2
|
171
|
88 |
"
|
|
89 |
!
|
|
90 |
|
|
91 |
testBasic3
|
|
92 |
|
|
93 |
|q el|
|
|
94 |
|
|
95 |
q := Queue new:5.
|
|
96 |
self assert:q isEmpty.
|
|
97 |
self assert:q size == 0.
|
|
98 |
q nextPut:1.
|
|
99 |
q nextPut:2.
|
|
100 |
q nextPut:3.
|
|
101 |
q nextPut:4.
|
|
102 |
q nextPut:5.
|
|
103 |
self should:[q nextPut:6] raise:Error.
|
|
104 |
el := q next.
|
|
105 |
self assert:(el==1).
|
|
106 |
el := q next.
|
|
107 |
self assert:(el==2).
|
|
108 |
el := q next.
|
|
109 |
self assert:(el==3).
|
|
110 |
el := q next.
|
|
111 |
self assert:(el==4).
|
|
112 |
el := q next.
|
|
113 |
self assert:(el==5).
|
|
114 |
|
|
115 |
"
|
1447
|
116 |
self new testBasic3
|
171
|
117 |
"
|
|
118 |
!
|
|
119 |
|
|
120 |
testBasic4
|
|
121 |
|
|
122 |
|q el|
|
|
123 |
|
|
124 |
q := Queue new:5.
|
|
125 |
self assert:q isEmpty.
|
|
126 |
self assert:q size == 0.
|
|
127 |
q nextPut:1.
|
|
128 |
q nextPutFirst:2.
|
|
129 |
q nextPutFirst:3.
|
|
130 |
q nextPutFirst:4.
|
|
131 |
q nextPutFirst:5.
|
|
132 |
self should:[q nextPutFirst:6] raise:Error.
|
|
133 |
el := q next.
|
|
134 |
self assert:(el==5).
|
|
135 |
el := q next.
|
|
136 |
self assert:(el==4).
|
|
137 |
el := q next.
|
|
138 |
self assert:(el==3).
|
|
139 |
el := q next.
|
|
140 |
self assert:(el==2).
|
|
141 |
el := q next.
|
|
142 |
self assert:(el==1).
|
|
143 |
|
|
144 |
"
|
1447
|
145 |
self new testBasic4
|
171
|
146 |
"
|
|
147 |
!
|
|
148 |
|
|
149 |
testBasic5
|
|
150 |
|
|
151 |
|q el|
|
|
152 |
|
|
153 |
q := Queue new:5.
|
|
154 |
self assert:q isEmpty.
|
|
155 |
self assert:q size == 0.
|
|
156 |
q nextPutFirst:1.
|
|
157 |
q nextPutFirst:2.
|
|
158 |
q nextPutFirst:3.
|
|
159 |
el := q next.
|
|
160 |
self assert:(el==3).
|
|
161 |
el := q next.
|
|
162 |
self assert:(el==2).
|
|
163 |
el := q next.
|
|
164 |
self assert:(el==1).
|
|
165 |
|
|
166 |
"
|
1447
|
167 |
self new testBasic5
|
171
|
168 |
"
|
|
169 |
!
|
|
170 |
|
1534
|
171 |
testChangeCapacity
|
|
172 |
"tests all kinds of boundary conditions in the capacity-change code
|
|
173 |
(i.e. especially wraps)"
|
|
174 |
|
|
175 |
|q|
|
|
176 |
|
|
177 |
#(false true) do:[:wrap |
|
|
178 |
1 to:10 do:[:fill |
|
|
179 |
1 to:fill do:[:read |
|
|
180 |
Transcript show:'wrap: '; show:wrap; show:' fill: '; show:fill; show:' read: '; showCR:read.
|
|
181 |
|
|
182 |
q := Queue new:10.
|
|
183 |
self assert:(q capacity == 10).
|
|
184 |
wrap ifTrue:[
|
|
185 |
1 to:5 do:[:i | q nextPut:#foo ].
|
|
186 |
].
|
|
187 |
|
|
188 |
1 to:fill do:[:i | q nextPut:i.
|
|
189 |
(i==1 and:[wrap]) ifTrue:[ 1 to:5 do:[:i | q next ] ].
|
|
190 |
].
|
|
191 |
"/ (wrap and:[fill==9 and:[read == 8]]) ifTrue:[self halt].
|
|
192 |
read timesRepeat:[ q next ].
|
|
193 |
q capacity:12.
|
|
194 |
self assert:(q capacity == 12).
|
|
195 |
self assert:(q size == (fill-read)).
|
|
196 |
self assert:((Array streamContents:[:s | q do:[:e |s nextPut:e]]) = (read+1 to:fill) asArray).
|
|
197 |
self assert:(q size == (fill-read)).
|
|
198 |
fill==read ifTrue:[
|
|
199 |
self assert:(q isEmpty).
|
|
200 |
self assert:(q notEmpty not).
|
|
201 |
self assert:(q size == 0).
|
|
202 |
self assert:(q nextOrNil == nil).
|
|
203 |
self assert:(q peekOrNil == nil).
|
|
204 |
self should:[q at:1] raise:SubscriptOutOfBoundsError.
|
|
205 |
] ifFalse:[
|
|
206 |
self assert:(q notEmpty).
|
|
207 |
self assert:(q isEmpty not).
|
|
208 |
self assert:(q at:1) == (read+1).
|
|
209 |
self assert:(q peek) == (read+1).
|
|
210 |
self assert:(q peekOrNil) == (read+1).
|
|
211 |
].
|
|
212 |
].
|
|
213 |
].
|
|
214 |
].
|
|
215 |
!
|
|
216 |
|
171
|
217 |
testRemoveAll
|
|
218 |
0 to:10 do:[:i|
|
1447
|
219 |
self removeAllSize:10 fill:i.
|
171
|
220 |
].
|
|
221 |
! !
|
|
222 |
|
|
223 |
!QueueTest class methodsFor:'documentation'!
|
|
224 |
|
|
225 |
version
|
|
226 |
^ '$Header$'
|
|
227 |
! !
|
1057
|
228 |
|