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() { |
174 |
|
} |
175 |
|
|
176 |
|
/** |
177 |
< |
* poll succeeds unless empty |
177 |
> |
* poll succeeds unless empty |
178 |
|
*/ |
179 |
|
public void testPoll() { |
180 |
|
LinkedList q = populatedQueue(SIZE); |
185 |
|
} |
186 |
|
|
187 |
|
/** |
188 |
< |
* peek returns next element, or null if empty |
188 |
> |
* peek returns next element, or null if empty |
189 |
|
*/ |
190 |
|
public void testPeek() { |
191 |
|
LinkedList q = populatedQueue(SIZE); |
214 |
|
} |
215 |
|
|
216 |
|
/** |
217 |
< |
* remove removes next element, or throws NSEE if empty |
217 |
> |
* remove removes next element, or throws NSEE if empty |
218 |
|
*/ |
219 |
|
public void testRemove() { |
220 |
|
LinkedList q = populatedQueue(SIZE); |
318 |
|
} |
319 |
|
|
320 |
|
/** |
321 |
< |
* toArray contains all elements |
321 |
> |
* toArray contains all elements in FIFO order |
322 |
|
*/ |
323 |
|
public void testToArray() { |
324 |
|
LinkedList q = populatedQueue(SIZE); |
325 |
|
Object[] o = q.toArray(); |
326 |
– |
Arrays.sort(o); |
326 |
|
for (int i = 0; i < o.length; i++) |
327 |
< |
assertEquals(o[i], q.poll()); |
327 |
> |
assertSame(o[i], q.poll()); |
328 |
|
} |
329 |
|
|
330 |
|
/** |
331 |
< |
* toArray(a) contains all elements |
331 |
> |
* toArray(a) contains all elements in FIFO order |
332 |
|
*/ |
333 |
|
public void testToArray2() { |
334 |
|
LinkedList q = populatedQueue(SIZE); |
335 |
|
Integer[] ints = new Integer[SIZE]; |
336 |
< |
ints = (Integer[])q.toArray(ints); |
338 |
< |
Arrays.sort(ints); |
336 |
> |
assertSame(ints, q.toArray(ints)); |
337 |
|
for (int i = 0; i < ints.length; i++) |
338 |
< |
assertEquals(ints[i], q.poll()); |
338 |
> |
assertSame(ints[i], q.poll()); |
339 |
|
} |
340 |
|
|
341 |
|
/** |
342 |
< |
* toArray(null) throws NPE |
342 |
> |
* toArray(null) throws NullPointerException |
343 |
|
*/ |
344 |
< |
public void testToArray_BadArg() { |
344 |
> |
public void testToArray_NullArg() { |
345 |
|
LinkedList l = new LinkedList(); |
346 |
|
l.add(new Object()); |
347 |
|
try { |
348 |
< |
Object o[] = l.toArray(null); |
348 |
> |
l.toArray(null); |
349 |
|
shouldThrow(); |
350 |
|
} catch (NullPointerException success) {} |
351 |
|
} |
352 |
|
|
353 |
|
/** |
354 |
< |
* toArray with incompatable aray type throws CCE |
354 |
> |
* toArray(incompatible array type) throws ArrayStoreException |
355 |
|
*/ |
356 |
|
public void testToArray1_BadArg() { |
357 |
|
LinkedList l = new LinkedList(); |
358 |
|
l.add(new Integer(5)); |
359 |
|
try { |
360 |
< |
Object o[] = l.toArray(new String[10]); |
360 |
> |
l.toArray(new String[10]); |
361 |
|
shouldThrow(); |
362 |
|
} catch (ArrayStoreException success) {} |
363 |
|
} |
364 |
|
|
365 |
|
/** |
366 |
< |
* iterator iterates through all elements |
366 |
> |
* iterator iterates through all elements |
367 |
|
*/ |
368 |
|
public void testIterator() { |
369 |
|
LinkedList q = populatedQueue(SIZE); |
377 |
|
} |
378 |
|
|
379 |
|
/** |
380 |
< |
* iterator ordering is FIFO |
380 |
> |
* iterator ordering is FIFO |
381 |
|
*/ |
382 |
|
public void testIteratorOrdering() { |
383 |
|
final LinkedList q = new LinkedList(); |
395 |
|
/** |
396 |
|
* iterator.remove removes current element |
397 |
|
*/ |
398 |
< |
public void testIteratorRemove () { |
398 |
> |
public void testIteratorRemove() { |
399 |
|
final LinkedList q = new LinkedList(); |
400 |
|
q.add(new Integer(1)); |
401 |
|
q.add(new Integer(2)); |
410 |
|
} |
411 |
|
|
412 |
|
/** |
413 |
< |
* Descending iterator iterates through all elements |
413 |
> |
* Descending iterator iterates through all elements |
414 |
|
*/ |
415 |
|
public void testDescendingIterator() { |
416 |
|
LinkedList q = populatedQueue(SIZE); |
429 |
|
} |
430 |
|
|
431 |
|
/** |
432 |
< |
* Descending iterator ordering is reverse FIFO |
432 |
> |
* Descending iterator ordering is reverse FIFO |
433 |
|
*/ |
434 |
|
public void testDescendingIteratorOrdering() { |
435 |
|
final LinkedList q = new LinkedList(); |
447 |
|
/** |
448 |
|
* descendingIterator.remove removes current element |
449 |
|
*/ |
450 |
< |
public void testDescendingIteratorRemove () { |
450 |
> |
public void testDescendingIteratorRemove() { |
451 |
|
final LinkedList q = new LinkedList(); |
452 |
|
q.add(three); |
453 |
|
q.add(two); |
492 |
|
} |
493 |
|
|
494 |
|
/** |
495 |
< |
* pop removes next element, or throws NSEE if empty |
495 |
> |
* pop removes next element, or throws NSEE if empty |
496 |
|
*/ |
497 |
|
public void testPop() { |
498 |
|
LinkedList q = populatedQueue(SIZE); |
524 |
|
} |
525 |
|
|
526 |
|
/** |
527 |
< |
* pollLast succeeds unless empty |
527 |
> |
* pollLast succeeds unless empty |
528 |
|
*/ |
529 |
|
public void testPollLast() { |
530 |
|
LinkedList q = populatedQueue(SIZE); |
535 |
|
} |
536 |
|
|
537 |
|
/** |
538 |
< |
* peekFirst returns next element, or null if empty |
538 |
> |
* peekFirst returns next element, or null if empty |
539 |
|
*/ |
540 |
|
public void testPeekFirst() { |
541 |
|
LinkedList q = populatedQueue(SIZE); |
550 |
|
|
551 |
|
|
552 |
|
/** |
553 |
< |
* peekLast returns next element, or null if empty |
553 |
> |
* peekLast returns next element, or null if empty |
554 |
|
*/ |
555 |
|
public void testPeekLast() { |
556 |
|
LinkedList q = populatedQueue(SIZE); |
576 |
|
} |
577 |
|
|
578 |
|
/** |
579 |
< |
* getLast returns next element, or throws NSEE if empty |
579 |
> |
* getLast returns next element, or throws NSEE if empty |
580 |
|
*/ |
581 |
|
public void testLastElement() { |
582 |
|
LinkedList q = populatedQueue(SIZE); |