6 |
|
* Pat Fisher, Mike Judd. |
7 |
|
*/ |
8 |
|
|
9 |
– |
import junit.framework.*; |
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) { |
20 |
|
junit.textui.TestRunner.run(suite()); |
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) { |
237 |
|
*/ |
238 |
|
public void testRemoveElement() { |
239 |
|
LinkedList q = populatedQueue(SIZE); |
240 |
< |
for (int i = 1; i < SIZE; i+=2) { |
240 |
> |
for (int i = 1; i < SIZE; i += 2) { |
241 |
|
assertTrue(q.contains(i)); |
242 |
|
assertTrue(q.remove((Integer)i)); |
243 |
|
assertFalse(q.contains(i)); |
244 |
|
assertTrue(q.contains(i-1)); |
245 |
|
} |
246 |
< |
for (int i = 0; i < SIZE; i+=2) { |
246 |
> |
for (int i = 0; i < SIZE; i += 2) { |
247 |
|
assertTrue(q.contains(i)); |
248 |
|
assertTrue(q.remove((Integer)i)); |
249 |
|
assertFalse(q.contains(i)); |
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 |
|
|
606 |
|
*/ |
607 |
|
public void testRemoveFirstOccurrence() { |
608 |
|
LinkedList q = populatedQueue(SIZE); |
609 |
< |
for (int i = 1; i < SIZE; i+=2) { |
609 |
> |
for (int i = 1; i < SIZE; i += 2) { |
610 |
|
assertTrue(q.removeFirstOccurrence(new Integer(i))); |
611 |
|
} |
612 |
< |
for (int i = 0; i < SIZE; i+=2) { |
612 |
> |
for (int i = 0; i < SIZE; i += 2) { |
613 |
|
assertTrue(q.removeFirstOccurrence(new Integer(i))); |
614 |
|
assertFalse(q.removeFirstOccurrence(new Integer(i+1))); |
615 |
|
} |
621 |
|
*/ |
622 |
|
public void testRemoveLastOccurrence() { |
623 |
|
LinkedList q = populatedQueue(SIZE); |
624 |
< |
for (int i = 1; i < SIZE; i+=2) { |
624 |
> |
for (int i = 1; i < SIZE; i += 2) { |
625 |
|
assertTrue(q.removeLastOccurrence(new Integer(i))); |
626 |
|
} |
627 |
< |
for (int i = 0; i < SIZE; i+=2) { |
627 |
> |
for (int i = 0; i < SIZE; i += 2) { |
628 |
|
assertTrue(q.removeLastOccurrence(new Integer(i))); |
629 |
|
assertFalse(q.removeLastOccurrence(new Integer(i+1))); |
630 |
|
} |