1 |
|
/* |
2 |
|
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
|
* Expert Group and released to the public domain, as explained at |
4 |
< |
* http://creativecommons.org/licenses/publicdomain |
4 |
> |
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
* Other contributors include Andrew Wright, Jeffrey Hayes, |
6 |
|
* Pat Fisher, Mike Judd. |
7 |
|
*/ |
8 |
|
|
9 |
< |
import junit.framework.*; |
10 |
< |
import java.util.*; |
11 |
< |
import java.util.concurrent.*; |
9 |
> |
import java.util.Arrays; |
10 |
> |
import java.util.Collection; |
11 |
> |
import java.util.Iterator; |
12 |
> |
import java.util.LinkedList; |
13 |
> |
import java.util.NoSuchElementException; |
14 |
> |
|
15 |
> |
import junit.framework.Test; |
16 |
> |
import junit.framework.TestSuite; |
17 |
|
|
18 |
|
public class LinkedListTest extends JSR166TestCase { |
19 |
|
public static void main(String[] args) { |
25 |
|
} |
26 |
|
|
27 |
|
/** |
28 |
< |
* Create a queue of given size containing consecutive |
28 |
> |
* Returns a new queue of given size containing consecutive |
29 |
|
* Integers 0 ... n. |
30 |
|
*/ |
31 |
|
private LinkedList<Integer> populatedQueue(int n) { |
413 |
|
q.add(new Integer(2)); |
414 |
|
q.add(new Integer(3)); |
415 |
|
Iterator it = q.iterator(); |
416 |
< |
assertEquals(it.next(), 1); |
416 |
> |
assertEquals(1, it.next()); |
417 |
|
it.remove(); |
418 |
|
it = q.iterator(); |
419 |
< |
assertEquals(it.next(), 2); |
420 |
< |
assertEquals(it.next(), 3); |
419 |
> |
assertEquals(2, it.next()); |
420 |
> |
assertEquals(3, it.next()); |
421 |
|
assertFalse(it.hasNext()); |
422 |
|
} |
423 |
|
|
473 |
|
assertFalse(it.hasNext()); |
474 |
|
} |
475 |
|
|
471 |
– |
|
476 |
|
/** |
477 |
|
* toString contains toStrings of elements |
478 |
|
*/ |
480 |
|
LinkedList q = populatedQueue(SIZE); |
481 |
|
String s = q.toString(); |
482 |
|
for (int i = 0; i < SIZE; ++i) { |
483 |
< |
assertTrue(s.indexOf(String.valueOf(i)) >= 0); |
483 |
> |
assertTrue(s.contains(String.valueOf(i))); |
484 |
|
} |
485 |
|
} |
486 |
|
|
559 |
|
assertNull(q.peekFirst()); |
560 |
|
} |
561 |
|
|
558 |
– |
|
562 |
|
/** |
563 |
|
* peekLast returns next element, or null if empty |
564 |
|
*/ |