47 |
try { |
try { |
48 |
LinkedList q = new LinkedList((Collection)null); |
LinkedList q = new LinkedList((Collection)null); |
49 |
shouldThrow(); |
shouldThrow(); |
50 |
} |
} catch (NullPointerException success) {} |
|
catch (NullPointerException success) {} |
|
51 |
} |
} |
52 |
|
|
53 |
/** |
/** |
54 |
* Queue contains all elements of collection used to initialize |
* Queue contains all elements of collection used to initialize |
|
|
|
55 |
*/ |
*/ |
56 |
public void testConstructor6() { |
public void testConstructor6() { |
|
try { |
|
57 |
Integer[] ints = new Integer[SIZE]; |
Integer[] ints = new Integer[SIZE]; |
58 |
for (int i = 0; i < SIZE; ++i) |
for (int i = 0; i < SIZE; ++i) |
59 |
ints[i] = new Integer(i); |
ints[i] = i; |
60 |
LinkedList q = new LinkedList(Arrays.asList(ints)); |
LinkedList q = new LinkedList(Arrays.asList(ints)); |
61 |
for (int i = 0; i < SIZE; ++i) |
for (int i = 0; i < SIZE; ++i) |
62 |
assertEquals(ints[i], q.poll()); |
assertEquals(ints[i], q.poll()); |
63 |
} |
} |
|
finally {} |
|
|
} |
|
64 |
|
|
65 |
/** |
/** |
66 |
* isEmpty is true before add, false after |
* isEmpty is true before add, false after |
95 |
* offer(null) succeeds |
* offer(null) succeeds |
96 |
*/ |
*/ |
97 |
public void testOfferNull() { |
public void testOfferNull() { |
|
try { |
|
98 |
LinkedList q = new LinkedList(); |
LinkedList q = new LinkedList(); |
99 |
q.offer(null); |
q.offer(null); |
|
} catch (NullPointerException ie) { |
|
|
unexpectedException(); |
|
|
} |
|
100 |
} |
} |
101 |
|
|
102 |
/** |
/** |
127 |
LinkedList q = new LinkedList(); |
LinkedList q = new LinkedList(); |
128 |
q.addAll(null); |
q.addAll(null); |
129 |
shouldThrow(); |
shouldThrow(); |
130 |
} |
} catch (NullPointerException success) {} |
|
catch (NullPointerException success) {} |
|
131 |
} |
} |
132 |
|
|
133 |
/** |
/** |
134 |
* Queue contains all elements, in traversal order, of successful addAll |
* Queue contains all elements, in traversal order, of successful addAll |
135 |
*/ |
*/ |
136 |
public void testAddAll5() { |
public void testAddAll5() { |
|
try { |
|
137 |
Integer[] empty = new Integer[0]; |
Integer[] empty = new Integer[0]; |
138 |
Integer[] ints = new Integer[SIZE]; |
Integer[] ints = new Integer[SIZE]; |
139 |
for (int i = 0; i < SIZE; ++i) |
for (int i = 0; i < SIZE; ++i) |
140 |
ints[i] = new Integer(i); |
ints[i] = i; |
141 |
LinkedList q = new LinkedList(); |
LinkedList q = new LinkedList(); |
142 |
assertFalse(q.addAll(Arrays.asList(empty))); |
assertFalse(q.addAll(Arrays.asList(empty))); |
143 |
assertTrue(q.addAll(Arrays.asList(ints))); |
assertTrue(q.addAll(Arrays.asList(ints))); |
144 |
for (int i = 0; i < SIZE; ++i) |
for (int i = 0; i < SIZE; ++i) |
145 |
assertEquals(ints[i], q.poll()); |
assertEquals(ints[i], q.poll()); |
146 |
} |
} |
|
finally {} |
|
|
} |
|
147 |
|
|
148 |
/** |
/** |
149 |
* addAll with too large an index throws IOOBE |
* addAll with too large an index throws IOOBE |
150 |
*/ |
*/ |
151 |
public void testAddAll2_IndexOutOfBoundsException() { |
public void testAddAll2_IndexOutOfBoundsException() { |
|
try { |
|
152 |
LinkedList l = new LinkedList(); |
LinkedList l = new LinkedList(); |
153 |
l.add(new Object()); |
l.add(new Object()); |
154 |
LinkedList m = new LinkedList(); |
LinkedList m = new LinkedList(); |
155 |
m.add(new Object()); |
m.add(new Object()); |
156 |
|
try { |
157 |
l.addAll(4,m); |
l.addAll(4,m); |
158 |
shouldThrow(); |
shouldThrow(); |
159 |
} catch (IndexOutOfBoundsException success) {} |
} catch (IndexOutOfBoundsException success) {} |
163 |
* addAll with negative index throws IOOBE |
* addAll with negative index throws IOOBE |
164 |
*/ |
*/ |
165 |
public void testAddAll4_BadIndex() { |
public void testAddAll4_BadIndex() { |
|
try { |
|
166 |
LinkedList l = new LinkedList(); |
LinkedList l = new LinkedList(); |
167 |
l.add(new Object()); |
l.add(new Object()); |
168 |
LinkedList m = new LinkedList(); |
LinkedList m = new LinkedList(); |
169 |
m.add(new Object()); |
m.add(new Object()); |
170 |
|
try { |
171 |
l.addAll(-1,m); |
l.addAll(-1,m); |
172 |
shouldThrow(); |
shouldThrow(); |
173 |
} catch (IndexOutOfBoundsException success) {} |
} catch (IndexOutOfBoundsException success) {} |
179 |
public void testPoll() { |
public void testPoll() { |
180 |
LinkedList q = populatedQueue(SIZE); |
LinkedList q = populatedQueue(SIZE); |
181 |
for (int i = 0; i < SIZE; ++i) { |
for (int i = 0; i < SIZE; ++i) { |
182 |
assertEquals(i, ((Integer)q.poll()).intValue()); |
assertEquals(i, q.poll()); |
183 |
} |
} |
184 |
assertNull(q.poll()); |
assertNull(q.poll()); |
185 |
} |
} |
190 |
public void testPeek() { |
public void testPeek() { |
191 |
LinkedList q = populatedQueue(SIZE); |
LinkedList q = populatedQueue(SIZE); |
192 |
for (int i = 0; i < SIZE; ++i) { |
for (int i = 0; i < SIZE; ++i) { |
193 |
assertEquals(i, ((Integer)q.peek()).intValue()); |
assertEquals(i, q.peek()); |
194 |
q.poll(); |
assertEquals(i, q.poll()); |
195 |
assertTrue(q.peek() == null || |
assertTrue(q.peek() == null || |
196 |
i != ((Integer)q.peek()).intValue()); |
!q.peek().equals(i)); |
197 |
} |
} |
198 |
assertNull(q.peek()); |
assertNull(q.peek()); |
199 |
} |
} |
204 |
public void testElement() { |
public void testElement() { |
205 |
LinkedList q = populatedQueue(SIZE); |
LinkedList q = populatedQueue(SIZE); |
206 |
for (int i = 0; i < SIZE; ++i) { |
for (int i = 0; i < SIZE; ++i) { |
207 |
assertEquals(i, ((Integer)q.element()).intValue()); |
assertEquals(i, q.element()); |
208 |
q.poll(); |
assertEquals(i, q.poll()); |
209 |
} |
} |
210 |
try { |
try { |
211 |
q.element(); |
q.element(); |
212 |
shouldThrow(); |
shouldThrow(); |
213 |
} |
} catch (NoSuchElementException success) {} |
|
catch (NoSuchElementException success) {} |
|
214 |
} |
} |
215 |
|
|
216 |
/** |
/** |
219 |
public void testRemove() { |
public void testRemove() { |
220 |
LinkedList q = populatedQueue(SIZE); |
LinkedList q = populatedQueue(SIZE); |
221 |
for (int i = 0; i < SIZE; ++i) { |
for (int i = 0; i < SIZE; ++i) { |
222 |
assertEquals(i, ((Integer)q.remove()).intValue()); |
assertEquals(i, q.remove()); |
223 |
} |
} |
224 |
try { |
try { |
225 |
q.remove(); |
q.remove(); |
226 |
shouldThrow(); |
shouldThrow(); |
227 |
} catch (NoSuchElementException success) { |
} catch (NoSuchElementException success) {} |
|
} |
|
228 |
} |
} |
229 |
|
|
230 |
/** |
/** |
262 |
q.clear(); |
q.clear(); |
263 |
assertTrue(q.isEmpty()); |
assertTrue(q.isEmpty()); |
264 |
assertEquals(0, q.size()); |
assertEquals(0, q.size()); |
265 |
q.add(new Integer(1)); |
assertTrue(q.add(new Integer(1))); |
266 |
assertFalse(q.isEmpty()); |
assertFalse(q.isEmpty()); |
267 |
q.clear(); |
q.clear(); |
268 |
assertTrue(q.isEmpty()); |
assertTrue(q.isEmpty()); |
277 |
for (int i = 0; i < SIZE; ++i) { |
for (int i = 0; i < SIZE; ++i) { |
278 |
assertTrue(q.containsAll(p)); |
assertTrue(q.containsAll(p)); |
279 |
assertFalse(p.containsAll(q)); |
assertFalse(p.containsAll(q)); |
280 |
p.add(new Integer(i)); |
assertTrue(p.add(new Integer(i))); |
281 |
} |
} |
282 |
assertTrue(p.containsAll(q)); |
assertTrue(p.containsAll(q)); |
283 |
} |
} |
341 |
} |
} |
342 |
|
|
343 |
/** |
/** |
344 |
* toArray(null) throws NPE |
* toArray(null) throws NullPointerException |
345 |
*/ |
*/ |
346 |
public void testToArray_BadArg() { |
public void testToArray_NullArg() { |
|
try { |
|
347 |
LinkedList l = new LinkedList(); |
LinkedList l = new LinkedList(); |
348 |
l.add(new Object()); |
l.add(new Object()); |
349 |
Object o[] = l.toArray(null); |
try { |
350 |
|
l.toArray(null); |
351 |
shouldThrow(); |
shouldThrow(); |
352 |
} catch (NullPointerException success) {} |
} catch (NullPointerException success) {} |
353 |
} |
} |
354 |
|
|
355 |
/** |
/** |
356 |
* toArray with incompatable aray type throws CCE |
* toArray(incompatible array type) throws ArrayStoreException |
357 |
*/ |
*/ |
358 |
public void testToArray1_BadArg() { |
public void testToArray1_BadArg() { |
|
try { |
|
359 |
LinkedList l = new LinkedList(); |
LinkedList l = new LinkedList(); |
360 |
l.add(new Integer(5)); |
l.add(new Integer(5)); |
361 |
Object o[] = l.toArray(new String[10] ); |
try { |
362 |
|
l.toArray(new String[10]); |
363 |
shouldThrow(); |
shouldThrow(); |
364 |
} catch (ArrayStoreException success) {} |
} catch (ArrayStoreException success) {} |
365 |
} |
} |
388 |
q.add(new Integer(3)); |
q.add(new Integer(3)); |
389 |
int k = 0; |
int k = 0; |
390 |
for (Iterator it = q.iterator(); it.hasNext();) { |
for (Iterator it = q.iterator(); it.hasNext();) { |
391 |
int i = ((Integer)(it.next())).intValue(); |
assertEquals(++k, it.next()); |
|
assertEquals(++k, i); |
|
392 |
} |
} |
393 |
|
|
394 |
assertEquals(3, k); |
assertEquals(3, k); |
403 |
q.add(new Integer(2)); |
q.add(new Integer(2)); |
404 |
q.add(new Integer(3)); |
q.add(new Integer(3)); |
405 |
Iterator it = q.iterator(); |
Iterator it = q.iterator(); |
406 |
it.next(); |
assertEquals(it.next(), 1); |
407 |
it.remove(); |
it.remove(); |
408 |
it = q.iterator(); |
it = q.iterator(); |
409 |
assertEquals(it.next(), new Integer(2)); |
assertEquals(it.next(), 2); |
410 |
assertEquals(it.next(), new Integer(3)); |
assertEquals(it.next(), 3); |
411 |
assertFalse(it.hasNext()); |
assertFalse(it.hasNext()); |
412 |
} |
} |
413 |
|
|
426 |
assertFalse(it.hasNext()); |
assertFalse(it.hasNext()); |
427 |
try { |
try { |
428 |
it.next(); |
it.next(); |
429 |
} catch (NoSuchElementException success) { |
shouldThrow(); |
430 |
} |
} catch (NoSuchElementException success) {} |
431 |
} |
} |
432 |
|
|
433 |
/** |
/** |
440 |
q.add(new Integer(1)); |
q.add(new Integer(1)); |
441 |
int k = 0; |
int k = 0; |
442 |
for (Iterator it = q.descendingIterator(); it.hasNext();) { |
for (Iterator it = q.descendingIterator(); it.hasNext();) { |
443 |
int i = ((Integer)(it.next())).intValue(); |
assertEquals(++k, it.next()); |
|
assertEquals(++k, i); |
|
444 |
} |
} |
445 |
|
|
446 |
assertEquals(3, k); |
assertEquals(3, k); |
451 |
*/ |
*/ |
452 |
public void testDescendingIteratorRemove () { |
public void testDescendingIteratorRemove () { |
453 |
final LinkedList q = new LinkedList(); |
final LinkedList q = new LinkedList(); |
454 |
q.add(new Integer(3)); |
q.add(three); |
455 |
q.add(new Integer(2)); |
q.add(two); |
456 |
q.add(new Integer(1)); |
q.add(one); |
457 |
Iterator it = q.descendingIterator(); |
Iterator it = q.descendingIterator(); |
458 |
it.next(); |
it.next(); |
459 |
it.remove(); |
it.remove(); |
460 |
it = q.descendingIterator(); |
it = q.descendingIterator(); |
461 |
assertEquals(it.next(), new Integer(2)); |
assertSame(it.next(), two); |
462 |
assertEquals(it.next(), new Integer(3)); |
assertSame(it.next(), three); |
463 |
assertFalse(it.hasNext()); |
assertFalse(it.hasNext()); |
464 |
} |
} |
465 |
|
|
481 |
public void testAddFirst() { |
public void testAddFirst() { |
482 |
LinkedList q = populatedQueue(3); |
LinkedList q = populatedQueue(3); |
483 |
q.addFirst(four); |
q.addFirst(four); |
484 |
assertEquals(four,q.peek()); |
assertSame(four, q.peek()); |
485 |
} |
} |
486 |
|
|
487 |
/** |
/** |
489 |
*/ |
*/ |
490 |
public void testPush() { |
public void testPush() { |
491 |
LinkedList q = populatedQueue(3); |
LinkedList q = populatedQueue(3); |
|
q.pollLast(); |
|
492 |
q.push(four); |
q.push(four); |
493 |
assertEquals(four,q.peekFirst()); |
assertSame(four, q.peekFirst()); |
494 |
} |
} |
495 |
|
|
496 |
/** |
/** |
499 |
public void testPop() { |
public void testPop() { |
500 |
LinkedList q = populatedQueue(SIZE); |
LinkedList q = populatedQueue(SIZE); |
501 |
for (int i = 0; i < SIZE; ++i) { |
for (int i = 0; i < SIZE; ++i) { |
502 |
assertEquals(i, ((Integer)q.pop()).intValue()); |
assertEquals(i, q.pop()); |
503 |
} |
} |
504 |
try { |
try { |
505 |
q.pop(); |
q.pop(); |
506 |
shouldThrow(); |
shouldThrow(); |
507 |
} catch (NoSuchElementException success) { |
} catch (NoSuchElementException success) {} |
|
} |
|
508 |
} |
} |
509 |
|
|
510 |
/** |
/** |
531 |
public void testPollLast() { |
public void testPollLast() { |
532 |
LinkedList q = populatedQueue(SIZE); |
LinkedList q = populatedQueue(SIZE); |
533 |
for (int i = SIZE-1; i >= 0; --i) { |
for (int i = SIZE-1; i >= 0; --i) { |
534 |
assertEquals(i, ((Integer)q.pollLast()).intValue()); |
assertEquals(i, q.pollLast()); |
535 |
} |
} |
536 |
assertNull(q.pollLast()); |
assertNull(q.pollLast()); |
537 |
} |
} |
542 |
public void testPeekFirst() { |
public void testPeekFirst() { |
543 |
LinkedList q = populatedQueue(SIZE); |
LinkedList q = populatedQueue(SIZE); |
544 |
for (int i = 0; i < SIZE; ++i) { |
for (int i = 0; i < SIZE; ++i) { |
545 |
assertEquals(i, ((Integer)q.peekFirst()).intValue()); |
assertEquals(i, q.peekFirst()); |
546 |
q.pollFirst(); |
assertEquals(i, q.pollFirst()); |
547 |
assertTrue(q.peekFirst() == null || |
assertTrue(q.peekFirst() == null || |
548 |
i != ((Integer)q.peekFirst()).intValue()); |
!q.peekFirst().equals(i)); |
549 |
} |
} |
550 |
assertNull(q.peekFirst()); |
assertNull(q.peekFirst()); |
551 |
} |
} |
557 |
public void testPeekLast() { |
public void testPeekLast() { |
558 |
LinkedList q = populatedQueue(SIZE); |
LinkedList q = populatedQueue(SIZE); |
559 |
for (int i = SIZE-1; i >= 0; --i) { |
for (int i = SIZE-1; i >= 0; --i) { |
560 |
assertEquals(i, ((Integer)q.peekLast()).intValue()); |
assertEquals(i, q.peekLast()); |
561 |
q.pollLast(); |
assertEquals(i, q.pollLast()); |
562 |
assertTrue(q.peekLast() == null || |
assertTrue(q.peekLast() == null || |
563 |
i != ((Integer)q.peekLast()).intValue()); |
!q.peekLast().equals(i)); |
564 |
} |
} |
565 |
assertNull(q.peekLast()); |
assertNull(q.peekLast()); |
566 |
} |
} |
568 |
public void testFirstElement() { |
public void testFirstElement() { |
569 |
LinkedList q = populatedQueue(SIZE); |
LinkedList q = populatedQueue(SIZE); |
570 |
for (int i = 0; i < SIZE; ++i) { |
for (int i = 0; i < SIZE; ++i) { |
571 |
assertEquals(i, ((Integer)q.getFirst()).intValue()); |
assertEquals(i, q.getFirst()); |
572 |
q.pollFirst(); |
assertEquals(i, q.pollFirst()); |
573 |
} |
} |
574 |
try { |
try { |
575 |
q.getFirst(); |
q.getFirst(); |
576 |
shouldThrow(); |
shouldThrow(); |
577 |
} |
} catch (NoSuchElementException success) {} |
|
catch (NoSuchElementException success) {} |
|
578 |
} |
} |
579 |
|
|
580 |
/** |
/** |
583 |
public void testLastElement() { |
public void testLastElement() { |
584 |
LinkedList q = populatedQueue(SIZE); |
LinkedList q = populatedQueue(SIZE); |
585 |
for (int i = SIZE-1; i >= 0; --i) { |
for (int i = SIZE-1; i >= 0; --i) { |
586 |
assertEquals(i, ((Integer)q.getLast()).intValue()); |
assertEquals(i, q.getLast()); |
587 |
q.pollLast(); |
assertEquals(i, q.pollLast()); |
588 |
} |
} |
589 |
try { |
try { |
590 |
q.getLast(); |
q.getLast(); |
591 |
shouldThrow(); |
shouldThrow(); |
592 |
} |
} catch (NoSuchElementException success) {} |
|
catch (NoSuchElementException success) {} |
|
593 |
assertNull(q.peekLast()); |
assertNull(q.peekLast()); |
594 |
} |
} |
595 |
|
|