18 |
|
|
19 |
|
public class ArrayDequeTest extends JSR166TestCase { |
20 |
|
public static void main(String[] args) { |
21 |
< |
junit.textui.TestRunner.run(suite()); |
21 |
> |
main(suite(), args); |
22 |
|
} |
23 |
|
|
24 |
|
public static Test suite() { |
51 |
|
*/ |
52 |
|
public void testConstructor3() { |
53 |
|
try { |
54 |
< |
ArrayDeque q = new ArrayDeque((Collection)null); |
54 |
> |
new ArrayDeque((Collection)null); |
55 |
|
shouldThrow(); |
56 |
|
} catch (NullPointerException success) {} |
57 |
|
} |
61 |
|
*/ |
62 |
|
public void testConstructor4() { |
63 |
|
try { |
64 |
< |
Integer[] ints = new Integer[SIZE]; |
65 |
< |
ArrayDeque q = new ArrayDeque(Arrays.asList(ints)); |
64 |
> |
new ArrayDeque(Arrays.asList(new Integer[SIZE])); |
65 |
|
shouldThrow(); |
66 |
|
} catch (NullPointerException success) {} |
67 |
|
} |
70 |
|
* Initializing from Collection with some null elements throws NPE |
71 |
|
*/ |
72 |
|
public void testConstructor5() { |
73 |
+ |
Integer[] ints = new Integer[SIZE]; |
74 |
+ |
for (int i = 0; i < SIZE - 1; ++i) |
75 |
+ |
ints[i] = new Integer(i); |
76 |
|
try { |
77 |
< |
Integer[] ints = new Integer[SIZE]; |
76 |
< |
for (int i = 0; i < SIZE-1; ++i) |
77 |
< |
ints[i] = new Integer(i); |
78 |
< |
ArrayDeque q = new ArrayDeque(Arrays.asList(ints)); |
77 |
> |
new ArrayDeque(Arrays.asList(ints)); |
78 |
|
shouldThrow(); |
79 |
|
} catch (NullPointerException success) {} |
80 |
|
} |
111 |
|
public void testSize() { |
112 |
|
ArrayDeque q = populatedDeque(SIZE); |
113 |
|
for (int i = 0; i < SIZE; ++i) { |
114 |
< |
assertEquals(SIZE-i, q.size()); |
114 |
> |
assertEquals(SIZE - i, q.size()); |
115 |
|
q.removeFirst(); |
116 |
|
} |
117 |
|
for (int i = 0; i < SIZE; ++i) { |
124 |
|
* push(null) throws NPE |
125 |
|
*/ |
126 |
|
public void testPushNull() { |
127 |
+ |
ArrayDeque q = new ArrayDeque(1); |
128 |
|
try { |
129 |
– |
ArrayDeque q = new ArrayDeque(1); |
129 |
|
q.push(null); |
130 |
|
shouldThrow(); |
131 |
|
} catch (NullPointerException success) {} |
159 |
|
* offer(null) throws NPE |
160 |
|
*/ |
161 |
|
public void testOfferNull() { |
162 |
+ |
ArrayDeque q = new ArrayDeque(); |
163 |
|
try { |
164 |
– |
ArrayDeque q = new ArrayDeque(); |
164 |
|
q.offer(null); |
165 |
|
shouldThrow(); |
166 |
|
} catch (NullPointerException success) {} |
170 |
|
* offerFirst(null) throws NPE |
171 |
|
*/ |
172 |
|
public void testOfferFirstNull() { |
173 |
+ |
ArrayDeque q = new ArrayDeque(); |
174 |
|
try { |
175 |
– |
ArrayDeque q = new ArrayDeque(); |
175 |
|
q.offerFirst(null); |
176 |
|
shouldThrow(); |
177 |
|
} catch (NullPointerException success) {} |
181 |
|
* offerLast(null) throws NPE |
182 |
|
*/ |
183 |
|
public void testOfferLastNull() { |
184 |
+ |
ArrayDeque q = new ArrayDeque(); |
185 |
|
try { |
186 |
– |
ArrayDeque q = new ArrayDeque(); |
186 |
|
q.offerLast(null); |
187 |
|
shouldThrow(); |
188 |
|
} catch (NullPointerException success) {} |
225 |
|
* add(null) throws NPE |
226 |
|
*/ |
227 |
|
public void testAddNull() { |
228 |
+ |
ArrayDeque q = new ArrayDeque(); |
229 |
|
try { |
230 |
– |
ArrayDeque q = new ArrayDeque(); |
230 |
|
q.add(null); |
231 |
|
shouldThrow(); |
232 |
|
} catch (NullPointerException success) {} |
236 |
|
* addFirst(null) throws NPE |
237 |
|
*/ |
238 |
|
public void testAddFirstNull() { |
239 |
+ |
ArrayDeque q = new ArrayDeque(); |
240 |
|
try { |
241 |
– |
ArrayDeque q = new ArrayDeque(); |
241 |
|
q.addFirst(null); |
242 |
|
shouldThrow(); |
243 |
|
} catch (NullPointerException success) {} |
247 |
|
* addLast(null) throws NPE |
248 |
|
*/ |
249 |
|
public void testAddLastNull() { |
250 |
+ |
ArrayDeque q = new ArrayDeque(); |
251 |
|
try { |
252 |
– |
ArrayDeque q = new ArrayDeque(); |
252 |
|
q.addLast(null); |
253 |
|
shouldThrow(); |
254 |
|
} catch (NullPointerException success) {} |
291 |
|
* addAll(null) throws NPE |
292 |
|
*/ |
293 |
|
public void testAddAll1() { |
294 |
+ |
ArrayDeque q = new ArrayDeque(); |
295 |
|
try { |
296 |
– |
ArrayDeque q = new ArrayDeque(); |
296 |
|
q.addAll(null); |
297 |
|
shouldThrow(); |
298 |
|
} catch (NullPointerException success) {} |
302 |
|
* addAll of a collection with null elements throws NPE |
303 |
|
*/ |
304 |
|
public void testAddAll2() { |
305 |
+ |
ArrayDeque q = new ArrayDeque(); |
306 |
|
try { |
307 |
< |
ArrayDeque q = new ArrayDeque(); |
308 |
< |
Integer[] ints = new Integer[SIZE]; |
309 |
< |
q.addAll(Arrays.asList(ints)); |
307 |
> |
q.addAll(Arrays.asList(new Integer[SIZE])); |
308 |
|
shouldThrow(); |
309 |
|
} catch (NullPointerException success) {} |
310 |
|
} |
314 |
|
* possibly adding some elements |
315 |
|
*/ |
316 |
|
public void testAddAll3() { |
317 |
+ |
ArrayDeque q = new ArrayDeque(); |
318 |
+ |
Integer[] ints = new Integer[SIZE]; |
319 |
+ |
for (int i = 0; i < SIZE - 1; ++i) |
320 |
+ |
ints[i] = new Integer(i); |
321 |
|
try { |
320 |
– |
ArrayDeque q = new ArrayDeque(); |
321 |
– |
Integer[] ints = new Integer[SIZE]; |
322 |
– |
for (int i = 0; i < SIZE-1; ++i) |
323 |
– |
ints[i] = new Integer(i); |
322 |
|
q.addAll(Arrays.asList(ints)); |
323 |
|
shouldThrow(); |
324 |
|
} catch (NullPointerException success) {} |
355 |
|
*/ |
356 |
|
public void testPollLast() { |
357 |
|
ArrayDeque q = populatedDeque(SIZE); |
358 |
< |
for (int i = SIZE-1; i >= 0; --i) { |
358 |
> |
for (int i = SIZE - 1; i >= 0; --i) { |
359 |
|
assertEquals(i, q.pollLast()); |
360 |
|
} |
361 |
|
assertNull(q.pollLast()); |
440 |
|
*/ |
441 |
|
public void testPeekLast() { |
442 |
|
ArrayDeque q = populatedDeque(SIZE); |
443 |
< |
for (int i = SIZE-1; i >= 0; --i) { |
443 |
> |
for (int i = SIZE - 1; i >= 0; --i) { |
444 |
|
assertEquals(i, q.peekLast()); |
445 |
|
assertEquals(i, q.pollLast()); |
446 |
|
assertTrue(q.peekLast() == null || |
484 |
|
*/ |
485 |
|
public void testLastElement() { |
486 |
|
ArrayDeque q = populatedDeque(SIZE); |
487 |
< |
for (int i = SIZE-1; i >= 0; --i) { |
487 |
> |
for (int i = SIZE - 1; i >= 0; --i) { |
488 |
|
assertEquals(i, q.getLast()); |
489 |
|
assertEquals(i, q.pollLast()); |
490 |
|
} |
605 |
|
boolean changed = q.retainAll(p); |
606 |
|
assertEquals(changed, (i > 0)); |
607 |
|
assertTrue(q.containsAll(p)); |
608 |
< |
assertEquals(SIZE-i, q.size()); |
608 |
> |
assertEquals(SIZE - i, q.size()); |
609 |
|
p.removeFirst(); |
610 |
|
} |
611 |
|
} |
618 |
|
ArrayDeque q = populatedDeque(SIZE); |
619 |
|
ArrayDeque p = populatedDeque(i); |
620 |
|
assertTrue(q.removeAll(p)); |
621 |
< |
assertEquals(SIZE-i, q.size()); |
621 |
> |
assertEquals(SIZE - i, q.size()); |
622 |
|
for (int j = 0; j < i; ++j) { |
623 |
|
assertFalse(q.contains(p.removeFirst())); |
624 |
|
} |
650 |
|
for (int i = 0; i < SIZE; i++) { |
651 |
|
checkToArray(q); |
652 |
|
assertEquals(i, q.poll()); |
653 |
< |
q.addLast(SIZE+i); |
653 |
> |
q.addLast(SIZE + i); |
654 |
|
} |
655 |
|
for (int i = 0; i < SIZE; i++) { |
656 |
|
checkToArray(q); |
657 |
< |
assertEquals(SIZE+i, q.poll()); |
657 |
> |
assertEquals(SIZE + i, q.poll()); |
658 |
|
} |
659 |
|
} |
660 |
|
|
703 |
|
for (int i = 0; i < SIZE; i++) { |
704 |
|
checkToArray2(q); |
705 |
|
assertEquals(i, q.poll()); |
706 |
< |
q.addLast(SIZE+i); |
706 |
> |
q.addLast(SIZE + i); |
707 |
|
} |
708 |
|
for (int i = 0; i < SIZE; i++) { |
709 |
|
checkToArray2(q); |
710 |
< |
assertEquals(SIZE+i, q.poll()); |
710 |
> |
assertEquals(SIZE + i, q.poll()); |
711 |
|
} |
712 |
|
} |
713 |
|
|
740 |
|
*/ |
741 |
|
public void testIterator() { |
742 |
|
ArrayDeque q = populatedDeque(SIZE); |
745 |
– |
int i = 0; |
743 |
|
Iterator it = q.iterator(); |
744 |
< |
while (it.hasNext()) { |
744 |
> |
int i; |
745 |
> |
for (i = 0; it.hasNext(); i++) |
746 |
|
assertTrue(q.contains(it.next())); |
749 |
– |
++i; |
750 |
– |
} |
747 |
|
assertEquals(i, SIZE); |
748 |
+ |
assertIteratorExhausted(it); |
749 |
+ |
} |
750 |
+ |
|
751 |
+ |
/** |
752 |
+ |
* iterator of empty collection has no elements |
753 |
+ |
*/ |
754 |
+ |
public void testEmptyIterator() { |
755 |
+ |
Deque c = new ArrayDeque(); |
756 |
+ |
assertIteratorExhausted(c.iterator()); |
757 |
+ |
assertIteratorExhausted(c.descendingIterator()); |
758 |
|
} |
759 |
|
|
760 |
|
/** |