17 |
|
|
18 |
|
public class LinkedListTest extends JSR166TestCase { |
19 |
|
public static void main(String[] args) { |
20 |
< |
junit.textui.TestRunner.run(suite()); |
20 |
> |
main(suite(), args); |
21 |
|
} |
22 |
|
|
23 |
|
public static Test suite() { |
50 |
|
*/ |
51 |
|
public void testConstructor3() { |
52 |
|
try { |
53 |
< |
LinkedList q = new LinkedList((Collection)null); |
53 |
> |
new LinkedList((Collection)null); |
54 |
|
shouldThrow(); |
55 |
|
} catch (NullPointerException success) {} |
56 |
|
} |
87 |
|
public void testSize() { |
88 |
|
LinkedList q = populatedQueue(SIZE); |
89 |
|
for (int i = 0; i < SIZE; ++i) { |
90 |
< |
assertEquals(SIZE-i, q.size()); |
90 |
> |
assertEquals(SIZE - i, q.size()); |
91 |
|
q.remove(); |
92 |
|
} |
93 |
|
for (int i = 0; i < SIZE; ++i) { |
102 |
|
public void testOfferNull() { |
103 |
|
LinkedList q = new LinkedList(); |
104 |
|
q.offer(null); |
105 |
+ |
assertNull(q.get(0)); |
106 |
+ |
assertTrue(q.contains(null)); |
107 |
|
} |
108 |
|
|
109 |
|
/** |
130 |
|
* addAll(null) throws NPE |
131 |
|
*/ |
132 |
|
public void testAddAll1() { |
133 |
+ |
LinkedList q = new LinkedList(); |
134 |
|
try { |
132 |
– |
LinkedList q = new LinkedList(); |
135 |
|
q.addAll(null); |
136 |
|
shouldThrow(); |
137 |
|
} catch (NullPointerException success) {} |
243 |
|
assertTrue(q.contains(i)); |
244 |
|
assertTrue(q.remove((Integer)i)); |
245 |
|
assertFalse(q.contains(i)); |
246 |
< |
assertTrue(q.contains(i-1)); |
246 |
> |
assertTrue(q.contains(i - 1)); |
247 |
|
} |
248 |
|
for (int i = 0; i < SIZE; i += 2) { |
249 |
|
assertTrue(q.contains(i)); |
250 |
|
assertTrue(q.remove((Integer)i)); |
251 |
|
assertFalse(q.contains(i)); |
252 |
< |
assertFalse(q.remove((Integer)(i+1))); |
253 |
< |
assertFalse(q.contains(i+1)); |
252 |
> |
assertFalse(q.remove((Integer)(i + 1))); |
253 |
> |
assertFalse(q.contains(i + 1)); |
254 |
|
} |
255 |
|
assertTrue(q.isEmpty()); |
256 |
|
} |
309 |
|
assertTrue(changed); |
310 |
|
|
311 |
|
assertTrue(q.containsAll(p)); |
312 |
< |
assertEquals(SIZE-i, q.size()); |
312 |
> |
assertEquals(SIZE - i, q.size()); |
313 |
|
p.remove(); |
314 |
|
} |
315 |
|
} |
322 |
|
LinkedList q = populatedQueue(SIZE); |
323 |
|
LinkedList p = populatedQueue(i); |
324 |
|
assertTrue(q.removeAll(p)); |
325 |
< |
assertEquals(SIZE-i, q.size()); |
325 |
> |
assertEquals(SIZE - i, q.size()); |
326 |
|
for (int j = 0; j < i; ++j) { |
327 |
< |
Integer I = (Integer)(p.remove()); |
328 |
< |
assertFalse(q.contains(I)); |
327 |
> |
Integer x = (Integer)(p.remove()); |
328 |
> |
assertFalse(q.contains(x)); |
329 |
|
} |
330 |
|
} |
331 |
|
} |
381 |
|
*/ |
382 |
|
public void testIterator() { |
383 |
|
LinkedList q = populatedQueue(SIZE); |
382 |
– |
int i = 0; |
384 |
|
Iterator it = q.iterator(); |
385 |
< |
while (it.hasNext()) { |
385 |
> |
int i; |
386 |
> |
for (i = 0; it.hasNext(); i++) |
387 |
|
assertTrue(q.contains(it.next())); |
386 |
– |
++i; |
387 |
– |
} |
388 |
|
assertEquals(i, SIZE); |
389 |
+ |
assertIteratorExhausted(it); |
390 |
+ |
} |
391 |
+ |
|
392 |
+ |
/** |
393 |
+ |
* iterator of empty collection has no elements |
394 |
+ |
*/ |
395 |
+ |
public void testEmptyIterator() { |
396 |
+ |
assertIteratorExhausted(new LinkedList().iterator()); |
397 |
|
} |
398 |
|
|
399 |
|
/** |
547 |
|
*/ |
548 |
|
public void testPollLast() { |
549 |
|
LinkedList q = populatedQueue(SIZE); |
550 |
< |
for (int i = SIZE-1; i >= 0; --i) { |
550 |
> |
for (int i = SIZE - 1; i >= 0; --i) { |
551 |
|
assertEquals(i, q.pollLast()); |
552 |
|
} |
553 |
|
assertNull(q.pollLast()); |
572 |
|
*/ |
573 |
|
public void testPeekLast() { |
574 |
|
LinkedList q = populatedQueue(SIZE); |
575 |
< |
for (int i = SIZE-1; i >= 0; --i) { |
575 |
> |
for (int i = SIZE - 1; i >= 0; --i) { |
576 |
|
assertEquals(i, q.peekLast()); |
577 |
|
assertEquals(i, q.pollLast()); |
578 |
|
assertTrue(q.peekLast() == null || |
598 |
|
*/ |
599 |
|
public void testLastElement() { |
600 |
|
LinkedList q = populatedQueue(SIZE); |
601 |
< |
for (int i = SIZE-1; i >= 0; --i) { |
601 |
> |
for (int i = SIZE - 1; i >= 0; --i) { |
602 |
|
assertEquals(i, q.getLast()); |
603 |
|
assertEquals(i, q.pollLast()); |
604 |
|
} |
619 |
|
} |
620 |
|
for (int i = 0; i < SIZE; i += 2) { |
621 |
|
assertTrue(q.removeFirstOccurrence(new Integer(i))); |
622 |
< |
assertFalse(q.removeFirstOccurrence(new Integer(i+1))); |
622 |
> |
assertFalse(q.removeFirstOccurrence(new Integer(i + 1))); |
623 |
|
} |
624 |
|
assertTrue(q.isEmpty()); |
625 |
|
} |
634 |
|
} |
635 |
|
for (int i = 0; i < SIZE; i += 2) { |
636 |
|
assertTrue(q.removeLastOccurrence(new Integer(i))); |
637 |
< |
assertFalse(q.removeLastOccurrence(new Integer(i+1))); |
637 |
> |
assertFalse(q.removeLastOccurrence(new Integer(i + 1))); |
638 |
|
} |
639 |
|
assertTrue(q.isEmpty()); |
640 |
|
} |