6 |
* Pat Fisher, Mike Judd. |
* Pat Fisher, Mike Judd. |
7 |
*/ |
*/ |
8 |
|
|
|
import junit.framework.*; |
|
9 |
import java.util.Arrays; |
import java.util.Arrays; |
10 |
import java.util.Collection; |
import java.util.Collection; |
11 |
import java.util.Iterator; |
import java.util.Iterator; |
12 |
import java.util.LinkedList; |
import java.util.LinkedList; |
13 |
import java.util.NoSuchElementException; |
import java.util.NoSuchElementException; |
14 |
|
|
15 |
|
import junit.framework.Test; |
16 |
|
import junit.framework.TestSuite; |
17 |
|
|
18 |
public class LinkedListTest extends JSR166TestCase { |
public class LinkedListTest extends JSR166TestCase { |
19 |
public static void main(String[] args) { |
public static void main(String[] args) { |
20 |
junit.textui.TestRunner.run(suite()); |
main(suite(), args); |
21 |
} |
} |
22 |
|
|
23 |
public static Test suite() { |
public static Test suite() { |
25 |
} |
} |
26 |
|
|
27 |
/** |
/** |
28 |
* Create a queue of given size containing consecutive |
* Returns a new queue of given size containing consecutive |
29 |
* Integers 0 ... n. |
* Integers 0 ... n. |
30 |
*/ |
*/ |
31 |
private LinkedList<Integer> populatedQueue(int n) { |
private LinkedList<Integer> populatedQueue(int n) { |
50 |
*/ |
*/ |
51 |
public void testConstructor3() { |
public void testConstructor3() { |
52 |
try { |
try { |
53 |
LinkedList q = new LinkedList((Collection)null); |
new LinkedList((Collection)null); |
54 |
shouldThrow(); |
shouldThrow(); |
55 |
} catch (NullPointerException success) {} |
} catch (NullPointerException success) {} |
56 |
} |
} |
102 |
public void testOfferNull() { |
public void testOfferNull() { |
103 |
LinkedList q = new LinkedList(); |
LinkedList q = new LinkedList(); |
104 |
q.offer(null); |
q.offer(null); |
105 |
|
assertNull(q.get(0)); |
106 |
|
assertTrue(q.contains(null)); |
107 |
} |
} |
108 |
|
|
109 |
/** |
/** |
130 |
* addAll(null) throws NPE |
* addAll(null) throws NPE |
131 |
*/ |
*/ |
132 |
public void testAddAll1() { |
public void testAddAll1() { |
|
try { |
|
133 |
LinkedList q = new LinkedList(); |
LinkedList q = new LinkedList(); |
134 |
|
try { |
135 |
q.addAll(null); |
q.addAll(null); |
136 |
shouldThrow(); |
shouldThrow(); |
137 |
} catch (NullPointerException success) {} |
} catch (NullPointerException success) {} |
324 |
assertTrue(q.removeAll(p)); |
assertTrue(q.removeAll(p)); |
325 |
assertEquals(SIZE-i, q.size()); |
assertEquals(SIZE-i, q.size()); |
326 |
for (int j = 0; j < i; ++j) { |
for (int j = 0; j < i; ++j) { |
327 |
Integer I = (Integer)(p.remove()); |
Integer x = (Integer)(p.remove()); |
328 |
assertFalse(q.contains(I)); |
assertFalse(q.contains(x)); |
329 |
} |
} |
330 |
} |
} |
331 |
} |
} |
381 |
*/ |
*/ |
382 |
public void testIterator() { |
public void testIterator() { |
383 |
LinkedList q = populatedQueue(SIZE); |
LinkedList q = populatedQueue(SIZE); |
|
int i = 0; |
|
384 |
Iterator it = q.iterator(); |
Iterator it = q.iterator(); |
385 |
while (it.hasNext()) { |
int i; |
386 |
|
for (i = 0; it.hasNext(); i++) |
387 |
assertTrue(q.contains(it.next())); |
assertTrue(q.contains(it.next())); |
|
++i; |
|
|
} |
|
388 |
assertEquals(i, SIZE); |
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 |
/** |
/** |