10 |
|
|
11 |
|
public class ArrayDequeTest extends JSR166TestCase { |
12 |
|
public static void main(String[] args) { |
13 |
< |
junit.textui.TestRunner.run (suite()); |
13 |
> |
junit.textui.TestRunner.run (suite()); |
14 |
|
} |
15 |
|
|
16 |
|
public static Test suite() { |
17 |
< |
return new TestSuite(ArrayDequeTest.class); |
17 |
> |
return new TestSuite(ArrayDequeTest.class); |
18 |
|
} |
19 |
|
|
20 |
|
/** |
24 |
|
private ArrayDeque populatedDeque(int n) { |
25 |
|
ArrayDeque q = new ArrayDeque(); |
26 |
|
assertTrue(q.isEmpty()); |
27 |
< |
for (int i = 0; i < n; ++i) |
28 |
< |
assertTrue(q.offerLast(new Integer(i))); |
27 |
> |
for (int i = 0; i < n; ++i) |
28 |
> |
assertTrue(q.offerLast(new Integer(i))); |
29 |
|
assertFalse(q.isEmpty()); |
30 |
< |
assertEquals(n, q.size()); |
30 |
> |
assertEquals(n, q.size()); |
31 |
|
return q; |
32 |
|
} |
33 |
|
|
45 |
|
try { |
46 |
|
ArrayDeque q = new ArrayDeque((Collection)null); |
47 |
|
shouldThrow(); |
48 |
< |
} |
49 |
< |
catch (NullPointerException success) {} |
48 |
> |
} catch (NullPointerException success) {} |
49 |
|
} |
50 |
|
|
51 |
|
/** |
53 |
|
|
54 |
|
*/ |
55 |
|
public void testConstructor6() { |
56 |
< |
try { |
57 |
< |
Integer[] ints = new Integer[SIZE]; |
58 |
< |
for (int i = 0; i < SIZE; ++i) |
59 |
< |
ints[i] = new Integer(i); |
60 |
< |
ArrayDeque q = new ArrayDeque(Arrays.asList(ints)); |
61 |
< |
for (int i = 0; i < SIZE; ++i) |
63 |
< |
assertEquals(ints[i], q.pollFirst()); |
64 |
< |
} |
65 |
< |
finally {} |
56 |
> |
Integer[] ints = new Integer[SIZE]; |
57 |
> |
for (int i = 0; i < SIZE; ++i) |
58 |
> |
ints[i] = new Integer(i); |
59 |
> |
ArrayDeque q = new ArrayDeque(Arrays.asList(ints)); |
60 |
> |
for (int i = 0; i < SIZE; ++i) |
61 |
> |
assertEquals(ints[i], q.pollFirst()); |
62 |
|
} |
63 |
|
|
64 |
|
/** |
94 |
|
* push(null) throws NPE |
95 |
|
*/ |
96 |
|
public void testPushNull() { |
97 |
< |
try { |
97 |
> |
try { |
98 |
|
ArrayDeque q = new ArrayDeque(1); |
99 |
|
q.push(null); |
100 |
|
shouldThrow(); |
101 |
< |
} catch (NullPointerException success) { } |
101 |
> |
} catch (NullPointerException success) {} |
102 |
|
} |
103 |
|
|
104 |
|
/** |
107 |
|
public void testPush() { |
108 |
|
ArrayDeque q = populatedDeque(3); |
109 |
|
q.pollLast(); |
110 |
< |
q.push(four); |
111 |
< |
assertEquals(four,q.peekFirst()); |
110 |
> |
q.push(four); |
111 |
> |
assertEquals(four,q.peekFirst()); |
112 |
|
} |
113 |
|
|
114 |
|
/** |
122 |
|
try { |
123 |
|
q.pop(); |
124 |
|
shouldThrow(); |
125 |
< |
} catch (NoSuchElementException success){ |
130 |
< |
} |
125 |
> |
} catch (NoSuchElementException success) {} |
126 |
|
} |
127 |
|
|
128 |
|
/** |
129 |
|
* offer(null) throws NPE |
130 |
|
*/ |
131 |
|
public void testOfferFirstNull() { |
132 |
< |
try { |
132 |
> |
try { |
133 |
|
ArrayDeque q = new ArrayDeque(); |
134 |
|
q.offerFirst(null); |
135 |
|
shouldThrow(); |
136 |
< |
} catch (NullPointerException success) { |
142 |
< |
} |
136 |
> |
} catch (NullPointerException success) {} |
137 |
|
} |
138 |
|
|
139 |
|
/** |
173 |
|
ArrayDeque q = new ArrayDeque(); |
174 |
|
q.addAll(null); |
175 |
|
shouldThrow(); |
176 |
< |
} |
183 |
< |
catch (NullPointerException success) {} |
176 |
> |
} catch (NullPointerException success) {} |
177 |
|
} |
178 |
|
|
179 |
|
/** |
180 |
|
* Queue contains all elements, in traversal order, of successful addAll |
181 |
|
*/ |
182 |
|
public void testAddAll5() { |
183 |
< |
try { |
184 |
< |
Integer[] empty = new Integer[0]; |
185 |
< |
Integer[] ints = new Integer[SIZE]; |
186 |
< |
for (int i = 0; i < SIZE; ++i) |
187 |
< |
ints[i] = new Integer(i); |
188 |
< |
ArrayDeque q = new ArrayDeque(); |
189 |
< |
assertFalse(q.addAll(Arrays.asList(empty))); |
190 |
< |
assertTrue(q.addAll(Arrays.asList(ints))); |
191 |
< |
for (int i = 0; i < SIZE; ++i) |
199 |
< |
assertEquals(ints[i], q.pollFirst()); |
200 |
< |
} |
201 |
< |
finally {} |
183 |
> |
Integer[] empty = new Integer[0]; |
184 |
> |
Integer[] ints = new Integer[SIZE]; |
185 |
> |
for (int i = 0; i < SIZE; ++i) |
186 |
> |
ints[i] = new Integer(i); |
187 |
> |
ArrayDeque q = new ArrayDeque(); |
188 |
> |
assertFalse(q.addAll(Arrays.asList(empty))); |
189 |
> |
assertTrue(q.addAll(Arrays.asList(ints))); |
190 |
> |
for (int i = 0; i < SIZE; ++i) |
191 |
> |
assertEquals(ints[i], q.pollFirst()); |
192 |
|
} |
193 |
|
|
194 |
|
/** |
199 |
|
for (int i = 0; i < SIZE; ++i) { |
200 |
|
assertEquals(i, ((Integer)q.pollFirst()).intValue()); |
201 |
|
} |
202 |
< |
assertNull(q.pollFirst()); |
202 |
> |
assertNull(q.pollFirst()); |
203 |
|
} |
204 |
|
|
205 |
|
/** |
210 |
|
for (int i = SIZE-1; i >= 0; --i) { |
211 |
|
assertEquals(i, ((Integer)q.pollLast()).intValue()); |
212 |
|
} |
213 |
< |
assertNull(q.pollLast()); |
213 |
> |
assertNull(q.pollLast()); |
214 |
|
} |
215 |
|
|
216 |
|
/** |
221 |
|
for (int i = 0; i < SIZE; ++i) { |
222 |
|
assertEquals(i, ((Integer)q.poll()).intValue()); |
223 |
|
} |
224 |
< |
assertNull(q.poll()); |
224 |
> |
assertNull(q.poll()); |
225 |
|
} |
226 |
|
|
227 |
|
/** |
235 |
|
try { |
236 |
|
q.remove(); |
237 |
|
shouldThrow(); |
238 |
< |
} catch (NoSuchElementException success){ |
249 |
< |
} |
238 |
> |
} catch (NoSuchElementException success) {} |
239 |
|
} |
240 |
|
|
241 |
|
/** |
249 |
|
assertTrue(q.peekFirst() == null || |
250 |
|
i != ((Integer)q.peekFirst()).intValue()); |
251 |
|
} |
252 |
< |
assertNull(q.peekFirst()); |
252 |
> |
assertNull(q.peekFirst()); |
253 |
|
} |
254 |
|
|
255 |
|
/** |
263 |
|
assertTrue(q.peek() == null || |
264 |
|
i != ((Integer)q.peek()).intValue()); |
265 |
|
} |
266 |
< |
assertNull(q.peek()); |
266 |
> |
assertNull(q.peek()); |
267 |
|
} |
268 |
|
|
269 |
|
/** |
277 |
|
assertTrue(q.peekLast() == null || |
278 |
|
i != ((Integer)q.peekLast()).intValue()); |
279 |
|
} |
280 |
< |
assertNull(q.peekLast()); |
280 |
> |
assertNull(q.peekLast()); |
281 |
|
} |
282 |
|
|
283 |
|
/** |
292 |
|
try { |
293 |
|
q.getFirst(); |
294 |
|
shouldThrow(); |
295 |
< |
} |
307 |
< |
catch (NoSuchElementException success) {} |
295 |
> |
} catch (NoSuchElementException success) {} |
296 |
|
} |
297 |
|
|
298 |
|
/** |
307 |
|
try { |
308 |
|
q.getLast(); |
309 |
|
shouldThrow(); |
310 |
< |
} |
311 |
< |
catch (NoSuchElementException success) {} |
324 |
< |
assertNull(q.peekLast()); |
310 |
> |
} catch (NoSuchElementException success) {} |
311 |
> |
assertNull(q.peekLast()); |
312 |
|
} |
313 |
|
|
314 |
|
|
323 |
|
try { |
324 |
|
q.removeFirst(); |
325 |
|
shouldThrow(); |
326 |
< |
} catch (NoSuchElementException success){ |
340 |
< |
} |
326 |
> |
} catch (NoSuchElementException success) {} |
327 |
|
} |
328 |
|
|
329 |
|
/** |
436 |
|
*/ |
437 |
|
public void testToArray() { |
438 |
|
ArrayDeque q = populatedDeque(SIZE); |
439 |
< |
Object[] o = q.toArray(); |
439 |
> |
Object[] o = q.toArray(); |
440 |
|
Arrays.sort(o); |
441 |
< |
for (int i = 0; i < o.length; i++) |
442 |
< |
assertEquals(o[i], q.pollFirst()); |
441 |
> |
for (int i = 0; i < o.length; i++) |
442 |
> |
assertEquals(o[i], q.pollFirst()); |
443 |
|
} |
444 |
|
|
445 |
|
/** |
447 |
|
*/ |
448 |
|
public void testToArray2() { |
449 |
|
ArrayDeque q = populatedDeque(SIZE); |
450 |
< |
Integer[] ints = new Integer[SIZE]; |
451 |
< |
ints = (Integer[])q.toArray(ints); |
450 |
> |
Integer[] ints = new Integer[SIZE]; |
451 |
> |
ints = (Integer[])q.toArray(ints); |
452 |
|
Arrays.sort(ints); |
453 |
|
for (int i = 0; i < ints.length; i++) |
454 |
|
assertEquals(ints[i], q.pollFirst()); |
458 |
|
* toArray(null) throws NPE |
459 |
|
*/ |
460 |
|
public void testToArray_BadArg() { |
461 |
< |
try { |
462 |
< |
ArrayDeque l = new ArrayDeque(); |
463 |
< |
l.add(new Object()); |
464 |
< |
Object o[] = l.toArray(null); |
465 |
< |
shouldThrow(); |
466 |
< |
} catch (NullPointerException success){} |
461 |
> |
try { |
462 |
> |
ArrayDeque l = new ArrayDeque(); |
463 |
> |
l.add(new Object()); |
464 |
> |
Object o[] = l.toArray(null); |
465 |
> |
shouldThrow(); |
466 |
> |
} catch (NullPointerException success) {} |
467 |
|
} |
468 |
|
|
469 |
|
/** |
470 |
|
* toArray with incompatable aray type throws CCE |
471 |
|
*/ |
472 |
|
public void testToArray1_BadArg() { |
473 |
< |
try { |
474 |
< |
ArrayDeque l = new ArrayDeque(); |
475 |
< |
l.add(new Integer(5)); |
476 |
< |
Object o[] = l.toArray(new String[10] ); |
477 |
< |
shouldThrow(); |
478 |
< |
} catch (ArrayStoreException success){} |
473 |
> |
try { |
474 |
> |
ArrayDeque l = new ArrayDeque(); |
475 |
> |
l.add(new Integer(5)); |
476 |
> |
Object o[] = l.toArray(new String[10] ); |
477 |
> |
shouldThrow(); |
478 |
> |
} catch (ArrayStoreException success) {} |
479 |
|
} |
480 |
|
|
481 |
|
/** |
484 |
|
public void testIterator() { |
485 |
|
ArrayDeque q = populatedDeque(SIZE); |
486 |
|
int i = 0; |
487 |
< |
Iterator it = q.iterator(); |
487 |
> |
Iterator it = q.iterator(); |
488 |
|
while (it.hasNext()) { |
489 |
|
assertTrue(q.contains(it.next())); |
490 |
|
++i; |
543 |
|
public void testDescendingIterator() { |
544 |
|
ArrayDeque q = populatedDeque(SIZE); |
545 |
|
int i = 0; |
546 |
< |
Iterator it = q.descendingIterator(); |
546 |
> |
Iterator it = q.descendingIterator(); |
547 |
|
while (it.hasNext()) { |
548 |
|
assertTrue(q.contains(it.next())); |
549 |
|
++i; |
552 |
|
assertFalse(it.hasNext()); |
553 |
|
try { |
554 |
|
it.next(); |
555 |
< |
} catch (NoSuchElementException success) { |
556 |
< |
} |
555 |
> |
shouldThrow(); |
556 |
> |
} catch (NoSuchElementException success) {} |
557 |
|
} |
558 |
|
|
559 |
|
/** |
623 |
|
*/ |
624 |
|
public void testAddFirst() { |
625 |
|
ArrayDeque q = populatedDeque(3); |
626 |
< |
q.addFirst(four); |
627 |
< |
assertEquals(four,q.peekFirst()); |
626 |
> |
q.addFirst(four); |
627 |
> |
assertEquals(four,q.peekFirst()); |
628 |
|
} |
629 |
|
|
630 |
|
/** |
632 |
|
*/ |
633 |
|
public void testAddLast() { |
634 |
|
ArrayDeque q = populatedDeque(3); |
635 |
< |
q.addLast(four); |
636 |
< |
assertEquals(four,q.peekLast()); |
635 |
> |
q.addLast(four); |
636 |
> |
assertEquals(four,q.peekLast()); |
637 |
|
} |
638 |
|
|
639 |
|
} |