12 |
|
|
13 |
|
public class LinkedListTest extends JSR166TestCase { |
14 |
|
public static void main(String[] args) { |
15 |
< |
junit.textui.TestRunner.run (suite()); |
15 |
> |
junit.textui.TestRunner.run (suite()); |
16 |
|
} |
17 |
|
|
18 |
|
public static Test suite() { |
19 |
< |
return new TestSuite(LinkedListTest.class); |
19 |
> |
return new TestSuite(LinkedListTest.class); |
20 |
|
} |
21 |
|
|
22 |
|
/** |
26 |
|
private LinkedList populatedQueue(int n) { |
27 |
|
LinkedList q = new LinkedList(); |
28 |
|
assertTrue(q.isEmpty()); |
29 |
< |
for (int i = 0; i < n; ++i) |
30 |
< |
assertTrue(q.offer(new Integer(i))); |
29 |
> |
for (int i = 0; i < n; ++i) |
30 |
> |
assertTrue(q.offer(new Integer(i))); |
31 |
|
assertFalse(q.isEmpty()); |
32 |
< |
assertEquals(n, q.size()); |
32 |
> |
assertEquals(n, q.size()); |
33 |
|
return q; |
34 |
|
} |
35 |
|
|
100 |
|
* offer(null) succeeds |
101 |
|
*/ |
102 |
|
public void testOfferNull() { |
103 |
< |
try { |
103 |
> |
try { |
104 |
|
LinkedList q = new LinkedList(); |
105 |
|
q.offer(null); |
106 |
|
} catch (NullPointerException ie) { |
162 |
|
* addAll with too large an index throws IOOBE |
163 |
|
*/ |
164 |
|
public void testAddAll2_IndexOutOfBoundsException() { |
165 |
< |
try { |
166 |
< |
LinkedList l = new LinkedList(); |
167 |
< |
l.add(new Object()); |
168 |
< |
LinkedList m = new LinkedList(); |
169 |
< |
m.add(new Object()); |
170 |
< |
l.addAll(4,m); |
171 |
< |
shouldThrow(); |
172 |
< |
} catch (IndexOutOfBoundsException success) {} |
165 |
> |
try { |
166 |
> |
LinkedList l = new LinkedList(); |
167 |
> |
l.add(new Object()); |
168 |
> |
LinkedList m = new LinkedList(); |
169 |
> |
m.add(new Object()); |
170 |
> |
l.addAll(4,m); |
171 |
> |
shouldThrow(); |
172 |
> |
} catch (IndexOutOfBoundsException success) {} |
173 |
|
} |
174 |
|
|
175 |
|
/** |
176 |
|
* addAll with negative index throws IOOBE |
177 |
|
*/ |
178 |
|
public void testAddAll4_BadIndex() { |
179 |
< |
try { |
180 |
< |
LinkedList l = new LinkedList(); |
181 |
< |
l.add(new Object()); |
182 |
< |
LinkedList m = new LinkedList(); |
183 |
< |
m.add(new Object()); |
184 |
< |
l.addAll(-1,m); |
185 |
< |
shouldThrow(); |
186 |
< |
} catch (IndexOutOfBoundsException success){} |
179 |
> |
try { |
180 |
> |
LinkedList l = new LinkedList(); |
181 |
> |
l.add(new Object()); |
182 |
> |
LinkedList m = new LinkedList(); |
183 |
> |
m.add(new Object()); |
184 |
> |
l.addAll(-1,m); |
185 |
> |
shouldThrow(); |
186 |
> |
} catch (IndexOutOfBoundsException success) {} |
187 |
|
} |
188 |
|
|
189 |
|
/** |
194 |
|
for (int i = 0; i < SIZE; ++i) { |
195 |
|
assertEquals(i, ((Integer)q.poll()).intValue()); |
196 |
|
} |
197 |
< |
assertNull(q.poll()); |
197 |
> |
assertNull(q.poll()); |
198 |
|
} |
199 |
|
|
200 |
|
/** |
208 |
|
assertTrue(q.peek() == null || |
209 |
|
i != ((Integer)q.peek()).intValue()); |
210 |
|
} |
211 |
< |
assertNull(q.peek()); |
211 |
> |
assertNull(q.peek()); |
212 |
|
} |
213 |
|
|
214 |
|
/** |
238 |
|
try { |
239 |
|
q.remove(); |
240 |
|
shouldThrow(); |
241 |
< |
} catch (NoSuchElementException success){ |
242 |
< |
} |
241 |
> |
} catch (NoSuchElementException success) { |
242 |
> |
} |
243 |
|
} |
244 |
|
|
245 |
|
/** |
337 |
|
*/ |
338 |
|
public void testToArray() { |
339 |
|
LinkedList q = populatedQueue(SIZE); |
340 |
< |
Object[] o = q.toArray(); |
340 |
> |
Object[] o = q.toArray(); |
341 |
|
Arrays.sort(o); |
342 |
< |
for (int i = 0; i < o.length; i++) |
343 |
< |
assertEquals(o[i], q.poll()); |
342 |
> |
for (int i = 0; i < o.length; i++) |
343 |
> |
assertEquals(o[i], q.poll()); |
344 |
|
} |
345 |
|
|
346 |
|
/** |
348 |
|
*/ |
349 |
|
public void testToArray2() { |
350 |
|
LinkedList q = populatedQueue(SIZE); |
351 |
< |
Integer[] ints = new Integer[SIZE]; |
352 |
< |
ints = (Integer[])q.toArray(ints); |
351 |
> |
Integer[] ints = new Integer[SIZE]; |
352 |
> |
ints = (Integer[])q.toArray(ints); |
353 |
|
Arrays.sort(ints); |
354 |
|
for (int i = 0; i < ints.length; i++) |
355 |
|
assertEquals(ints[i], q.poll()); |
359 |
|
* toArray(null) throws NPE |
360 |
|
*/ |
361 |
|
public void testToArray_BadArg() { |
362 |
< |
try { |
363 |
< |
LinkedList l = new LinkedList(); |
364 |
< |
l.add(new Object()); |
365 |
< |
Object o[] = l.toArray(null); |
366 |
< |
shouldThrow(); |
367 |
< |
} catch (NullPointerException success){} |
362 |
> |
try { |
363 |
> |
LinkedList l = new LinkedList(); |
364 |
> |
l.add(new Object()); |
365 |
> |
Object o[] = l.toArray(null); |
366 |
> |
shouldThrow(); |
367 |
> |
} catch (NullPointerException success) {} |
368 |
|
} |
369 |
|
|
370 |
|
/** |
371 |
|
* toArray with incompatable aray type throws CCE |
372 |
|
*/ |
373 |
|
public void testToArray1_BadArg() { |
374 |
< |
try { |
375 |
< |
LinkedList l = new LinkedList(); |
376 |
< |
l.add(new Integer(5)); |
377 |
< |
Object o[] = l.toArray(new String[10] ); |
378 |
< |
shouldThrow(); |
379 |
< |
} catch (ArrayStoreException success){} |
374 |
> |
try { |
375 |
> |
LinkedList l = new LinkedList(); |
376 |
> |
l.add(new Integer(5)); |
377 |
> |
Object o[] = l.toArray(new String[10] ); |
378 |
> |
shouldThrow(); |
379 |
> |
} catch (ArrayStoreException success) {} |
380 |
|
} |
381 |
|
|
382 |
|
/** |
385 |
|
public void testIterator() { |
386 |
|
LinkedList q = populatedQueue(SIZE); |
387 |
|
int i = 0; |
388 |
< |
Iterator it = q.iterator(); |
388 |
> |
Iterator it = q.iterator(); |
389 |
|
while (it.hasNext()) { |
390 |
|
assertTrue(q.contains(it.next())); |
391 |
|
++i; |
433 |
|
public void testDescendingIterator() { |
434 |
|
LinkedList q = populatedQueue(SIZE); |
435 |
|
int i = 0; |
436 |
< |
Iterator it = q.descendingIterator(); |
436 |
> |
Iterator it = q.descendingIterator(); |
437 |
|
while (it.hasNext()) { |
438 |
|
assertTrue(q.contains(it.next())); |
439 |
|
++i; |
497 |
|
*/ |
498 |
|
public void testAddFirst() { |
499 |
|
LinkedList q = populatedQueue(3); |
500 |
< |
q.addFirst(four); |
501 |
< |
assertEquals(four,q.peek()); |
500 |
> |
q.addFirst(four); |
501 |
> |
assertEquals(four,q.peek()); |
502 |
|
} |
503 |
|
|
504 |
|
/** |
507 |
|
public void testPush() { |
508 |
|
LinkedList q = populatedQueue(3); |
509 |
|
q.pollLast(); |
510 |
< |
q.push(four); |
511 |
< |
assertEquals(four,q.peekFirst()); |
510 |
> |
q.push(four); |
511 |
> |
assertEquals(four,q.peekFirst()); |
512 |
|
} |
513 |
|
|
514 |
|
/** |
522 |
|
try { |
523 |
|
q.pop(); |
524 |
|
shouldThrow(); |
525 |
< |
} catch (NoSuchElementException success){ |
526 |
< |
} |
525 |
> |
} catch (NoSuchElementException success) { |
526 |
> |
} |
527 |
|
} |
528 |
|
|
529 |
|
/** |
552 |
|
for (int i = SIZE-1; i >= 0; --i) { |
553 |
|
assertEquals(i, ((Integer)q.pollLast()).intValue()); |
554 |
|
} |
555 |
< |
assertNull(q.pollLast()); |
555 |
> |
assertNull(q.pollLast()); |
556 |
|
} |
557 |
|
|
558 |
|
/** |
566 |
|
assertTrue(q.peekFirst() == null || |
567 |
|
i != ((Integer)q.peekFirst()).intValue()); |
568 |
|
} |
569 |
< |
assertNull(q.peekFirst()); |
569 |
> |
assertNull(q.peekFirst()); |
570 |
|
} |
571 |
|
|
572 |
|
|
581 |
|
assertTrue(q.peekLast() == null || |
582 |
|
i != ((Integer)q.peekLast()).intValue()); |
583 |
|
} |
584 |
< |
assertNull(q.peekLast()); |
584 |
> |
assertNull(q.peekLast()); |
585 |
|
} |
586 |
|
|
587 |
|
public void testFirstElement() { |
611 |
|
shouldThrow(); |
612 |
|
} |
613 |
|
catch (NoSuchElementException success) {} |
614 |
< |
assertNull(q.peekLast()); |
614 |
> |
assertNull(q.peekLast()); |
615 |
|
} |
616 |
|
|
617 |
|
/** |