22 |
|
} |
23 |
|
|
24 |
|
public static Test suite() { |
25 |
< |
return new TestSuite(ArrayDequeTest.class); |
25 |
> |
class Implementation implements CollectionImplementation { |
26 |
> |
public Class<?> klazz() { return ArrayDeque.class; } |
27 |
> |
public Collection emptyCollection() { return new ArrayDeque(); } |
28 |
> |
public Object makeElement(int i) { return i; } |
29 |
> |
public boolean isConcurrent() { return false; } |
30 |
> |
public boolean permitsNulls() { return false; } |
31 |
> |
} |
32 |
> |
return newTestSuite(ArrayDequeTest.class, |
33 |
> |
CollectionTest.testSuite(new Implementation())); |
34 |
|
} |
35 |
|
|
36 |
|
/** |
403 |
|
assertTrue(q.contains(i)); |
404 |
|
assertTrue(q.remove(i)); |
405 |
|
assertFalse(q.contains(i)); |
406 |
< |
assertTrue(q.contains(i-1)); |
406 |
> |
assertTrue(q.contains(i - 1)); |
407 |
|
} |
408 |
|
for (int i = 0; i < SIZE; i += 2) { |
409 |
|
assertTrue(q.contains(i)); |
410 |
|
assertTrue(q.remove(i)); |
411 |
|
assertFalse(q.contains(i)); |
412 |
< |
assertFalse(q.remove(i+1)); |
413 |
< |
assertFalse(q.contains(i+1)); |
412 |
> |
assertFalse(q.remove(i + 1)); |
413 |
> |
assertFalse(q.contains(i + 1)); |
414 |
|
} |
415 |
|
assertTrue(q.isEmpty()); |
416 |
|
} |
538 |
|
*/ |
539 |
|
public void testRemoveFirstOccurrence() { |
540 |
|
ArrayDeque q = populatedDeque(SIZE); |
541 |
+ |
assertFalse(q.removeFirstOccurrence(null)); |
542 |
|
for (int i = 1; i < SIZE; i += 2) { |
543 |
|
assertTrue(q.removeFirstOccurrence(new Integer(i))); |
544 |
|
} |
545 |
|
for (int i = 0; i < SIZE; i += 2) { |
546 |
|
assertTrue(q.removeFirstOccurrence(new Integer(i))); |
547 |
< |
assertFalse(q.removeFirstOccurrence(new Integer(i+1))); |
547 |
> |
assertFalse(q.removeFirstOccurrence(new Integer(i + 1))); |
548 |
|
} |
549 |
|
assertTrue(q.isEmpty()); |
550 |
+ |
assertFalse(q.removeFirstOccurrence(null)); |
551 |
+ |
assertFalse(q.removeFirstOccurrence(42)); |
552 |
+ |
q = new ArrayDeque(); |
553 |
+ |
assertFalse(q.removeFirstOccurrence(null)); |
554 |
+ |
assertFalse(q.removeFirstOccurrence(42)); |
555 |
|
} |
556 |
|
|
557 |
|
/** |
559 |
|
*/ |
560 |
|
public void testRemoveLastOccurrence() { |
561 |
|
ArrayDeque q = populatedDeque(SIZE); |
562 |
+ |
assertFalse(q.removeLastOccurrence(null)); |
563 |
|
for (int i = 1; i < SIZE; i += 2) { |
564 |
|
assertTrue(q.removeLastOccurrence(new Integer(i))); |
565 |
|
} |
566 |
|
for (int i = 0; i < SIZE; i += 2) { |
567 |
|
assertTrue(q.removeLastOccurrence(new Integer(i))); |
568 |
< |
assertFalse(q.removeLastOccurrence(new Integer(i+1))); |
568 |
> |
assertFalse(q.removeLastOccurrence(new Integer(i + 1))); |
569 |
|
} |
570 |
|
assertTrue(q.isEmpty()); |
571 |
+ |
assertFalse(q.removeLastOccurrence(null)); |
572 |
+ |
assertFalse(q.removeLastOccurrence(42)); |
573 |
+ |
q = new ArrayDeque(); |
574 |
+ |
assertFalse(q.removeLastOccurrence(null)); |
575 |
+ |
assertFalse(q.removeLastOccurrence(42)); |
576 |
|
} |
577 |
|
|
578 |
|
/** |
801 |
|
final Random rng = new Random(); |
802 |
|
for (int iters = 0; iters < 100; ++iters) { |
803 |
|
int max = rng.nextInt(5) + 2; |
804 |
< |
int split = rng.nextInt(max-1) + 1; |
804 |
> |
int split = rng.nextInt(max - 1) + 1; |
805 |
|
for (int j = 1; j <= max; ++j) |
806 |
|
q.add(new Integer(j)); |
807 |
|
Iterator it = q.iterator(); |
808 |
|
for (int j = 1; j <= split; ++j) |
809 |
|
assertEquals(it.next(), new Integer(j)); |
810 |
|
it.remove(); |
811 |
< |
assertEquals(it.next(), new Integer(split+1)); |
811 |
> |
assertEquals(it.next(), new Integer(split + 1)); |
812 |
|
for (int j = 1; j <= split; ++j) |
813 |
|
q.remove(new Integer(j)); |
814 |
|
it = q.iterator(); |
815 |
< |
for (int j = split+1; j <= max; ++j) { |
815 |
> |
for (int j = split + 1; j <= max; ++j) { |
816 |
|
assertEquals(it.next(), new Integer(j)); |
817 |
|
it.remove(); |
818 |
|
} |
869 |
|
final Random rng = new Random(); |
870 |
|
for (int iters = 0; iters < 100; ++iters) { |
871 |
|
int max = rng.nextInt(5) + 2; |
872 |
< |
int split = rng.nextInt(max-1) + 1; |
872 |
> |
int split = rng.nextInt(max - 1) + 1; |
873 |
|
for (int j = max; j >= 1; --j) |
874 |
|
q.add(new Integer(j)); |
875 |
|
Iterator it = q.descendingIterator(); |
876 |
|
for (int j = 1; j <= split; ++j) |
877 |
|
assertEquals(it.next(), new Integer(j)); |
878 |
|
it.remove(); |
879 |
< |
assertEquals(it.next(), new Integer(split+1)); |
879 |
> |
assertEquals(it.next(), new Integer(split + 1)); |
880 |
|
for (int j = 1; j <= split; ++j) |
881 |
|
q.remove(new Integer(j)); |
882 |
|
it = q.descendingIterator(); |
883 |
< |
for (int j = split+1; j <= max; ++j) { |
883 |
> |
for (int j = split + 1; j <= max; ++j) { |
884 |
|
assertEquals(it.next(), new Integer(j)); |
885 |
|
it.remove(); |
886 |
|
} |