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 |
|
/** |
202 |
|
for (int i = 0; i < SIZE; ++i) { |
203 |
|
assertEquals(i, ((Integer)q.pollFirst()).intValue()); |
204 |
|
} |
205 |
< |
assertNull(q.pollFirst()); |
205 |
> |
assertNull(q.pollFirst()); |
206 |
|
} |
207 |
|
|
208 |
|
/** |
213 |
|
for (int i = SIZE-1; i >= 0; --i) { |
214 |
|
assertEquals(i, ((Integer)q.pollLast()).intValue()); |
215 |
|
} |
216 |
< |
assertNull(q.pollLast()); |
216 |
> |
assertNull(q.pollLast()); |
217 |
|
} |
218 |
|
|
219 |
|
/** |
224 |
|
for (int i = 0; i < SIZE; ++i) { |
225 |
|
assertEquals(i, ((Integer)q.poll()).intValue()); |
226 |
|
} |
227 |
< |
assertNull(q.poll()); |
227 |
> |
assertNull(q.poll()); |
228 |
|
} |
229 |
|
|
230 |
|
/** |
238 |
|
try { |
239 |
|
q.remove(); |
240 |
|
shouldThrow(); |
241 |
< |
} catch (NoSuchElementException success){ |
249 |
< |
} |
241 |
> |
} catch (NoSuchElementException success) {} |
242 |
|
} |
243 |
|
|
244 |
|
/** |
252 |
|
assertTrue(q.peekFirst() == null || |
253 |
|
i != ((Integer)q.peekFirst()).intValue()); |
254 |
|
} |
255 |
< |
assertNull(q.peekFirst()); |
255 |
> |
assertNull(q.peekFirst()); |
256 |
|
} |
257 |
|
|
258 |
|
/** |
266 |
|
assertTrue(q.peek() == null || |
267 |
|
i != ((Integer)q.peek()).intValue()); |
268 |
|
} |
269 |
< |
assertNull(q.peek()); |
269 |
> |
assertNull(q.peek()); |
270 |
|
} |
271 |
|
|
272 |
|
/** |
280 |
|
assertTrue(q.peekLast() == null || |
281 |
|
i != ((Integer)q.peekLast()).intValue()); |
282 |
|
} |
283 |
< |
assertNull(q.peekLast()); |
283 |
> |
assertNull(q.peekLast()); |
284 |
|
} |
285 |
|
|
286 |
|
/** |
295 |
|
try { |
296 |
|
q.getFirst(); |
297 |
|
shouldThrow(); |
298 |
< |
} |
307 |
< |
catch (NoSuchElementException success) {} |
298 |
> |
} catch (NoSuchElementException success) {} |
299 |
|
} |
300 |
|
|
301 |
|
/** |
310 |
|
try { |
311 |
|
q.getLast(); |
312 |
|
shouldThrow(); |
313 |
< |
} |
314 |
< |
catch (NoSuchElementException success) {} |
324 |
< |
assertNull(q.peekLast()); |
313 |
> |
} catch (NoSuchElementException success) {} |
314 |
> |
assertNull(q.peekLast()); |
315 |
|
} |
316 |
|
|
317 |
|
|
326 |
|
try { |
327 |
|
q.removeFirst(); |
328 |
|
shouldThrow(); |
329 |
< |
} catch (NoSuchElementException success){ |
340 |
< |
} |
329 |
> |
} catch (NoSuchElementException success) {} |
330 |
|
} |
331 |
|
|
332 |
|
/** |
439 |
|
*/ |
440 |
|
public void testToArray() { |
441 |
|
ArrayDeque q = populatedDeque(SIZE); |
442 |
< |
Object[] o = q.toArray(); |
442 |
> |
Object[] o = q.toArray(); |
443 |
|
Arrays.sort(o); |
444 |
< |
for (int i = 0; i < o.length; i++) |
445 |
< |
assertEquals(o[i], q.pollFirst()); |
444 |
> |
for (int i = 0; i < o.length; i++) |
445 |
> |
assertEquals(o[i], q.pollFirst()); |
446 |
|
} |
447 |
|
|
448 |
|
/** |
450 |
|
*/ |
451 |
|
public void testToArray2() { |
452 |
|
ArrayDeque q = populatedDeque(SIZE); |
453 |
< |
Integer[] ints = new Integer[SIZE]; |
454 |
< |
ints = (Integer[])q.toArray(ints); |
453 |
> |
Integer[] ints = new Integer[SIZE]; |
454 |
> |
ints = (Integer[])q.toArray(ints); |
455 |
|
Arrays.sort(ints); |
456 |
|
for (int i = 0; i < ints.length; i++) |
457 |
|
assertEquals(ints[i], q.pollFirst()); |
461 |
|
* toArray(null) throws NPE |
462 |
|
*/ |
463 |
|
public void testToArray_BadArg() { |
464 |
< |
try { |
465 |
< |
ArrayDeque l = new ArrayDeque(); |
466 |
< |
l.add(new Object()); |
467 |
< |
Object o[] = l.toArray(null); |
468 |
< |
shouldThrow(); |
469 |
< |
} catch (NullPointerException success){} |
464 |
> |
try { |
465 |
> |
ArrayDeque l = new ArrayDeque(); |
466 |
> |
l.add(new Object()); |
467 |
> |
Object o[] = l.toArray(null); |
468 |
> |
shouldThrow(); |
469 |
> |
} catch (NullPointerException success) {} |
470 |
|
} |
471 |
|
|
472 |
|
/** |
473 |
|
* toArray with incompatable aray type throws CCE |
474 |
|
*/ |
475 |
|
public void testToArray1_BadArg() { |
476 |
< |
try { |
477 |
< |
ArrayDeque l = new ArrayDeque(); |
478 |
< |
l.add(new Integer(5)); |
479 |
< |
Object o[] = l.toArray(new String[10] ); |
480 |
< |
shouldThrow(); |
481 |
< |
} catch (ArrayStoreException success){} |
476 |
> |
try { |
477 |
> |
ArrayDeque l = new ArrayDeque(); |
478 |
> |
l.add(new Integer(5)); |
479 |
> |
Object o[] = l.toArray(new String[10] ); |
480 |
> |
shouldThrow(); |
481 |
> |
} catch (ArrayStoreException success) {} |
482 |
|
} |
483 |
|
|
484 |
|
/** |
487 |
|
public void testIterator() { |
488 |
|
ArrayDeque q = populatedDeque(SIZE); |
489 |
|
int i = 0; |
490 |
< |
Iterator it = q.iterator(); |
490 |
> |
Iterator it = q.iterator(); |
491 |
|
while (it.hasNext()) { |
492 |
|
assertTrue(q.contains(it.next())); |
493 |
|
++i; |
546 |
|
public void testDescendingIterator() { |
547 |
|
ArrayDeque q = populatedDeque(SIZE); |
548 |
|
int i = 0; |
549 |
< |
Iterator it = q.descendingIterator(); |
549 |
> |
Iterator it = q.descendingIterator(); |
550 |
|
while (it.hasNext()) { |
551 |
|
assertTrue(q.contains(it.next())); |
552 |
|
++i; |
555 |
|
assertFalse(it.hasNext()); |
556 |
|
try { |
557 |
|
it.next(); |
558 |
< |
} catch (NoSuchElementException success) { |
570 |
< |
} |
558 |
> |
} catch (NoSuchElementException success) {} |
559 |
|
} |
560 |
|
|
561 |
|
/** |
625 |
|
*/ |
626 |
|
public void testAddFirst() { |
627 |
|
ArrayDeque q = populatedDeque(3); |
628 |
< |
q.addFirst(four); |
629 |
< |
assertEquals(four,q.peekFirst()); |
628 |
> |
q.addFirst(four); |
629 |
> |
assertEquals(four,q.peekFirst()); |
630 |
|
} |
631 |
|
|
632 |
|
/** |
634 |
|
*/ |
635 |
|
public void testAddLast() { |
636 |
|
ArrayDeque q = populatedDeque(3); |
637 |
< |
q.addLast(four); |
638 |
< |
assertEquals(four,q.peekLast()); |
637 |
> |
q.addLast(four); |
638 |
> |
assertEquals(four,q.peekLast()); |
639 |
|
} |
640 |
|
|
641 |
|
} |