25 |
|
} |
26 |
|
|
27 |
|
public static Test suite() { |
28 |
< |
return new TestSuite(ConcurrentLinkedDequeTest.class); |
28 |
> |
class Implementation implements CollectionImplementation { |
29 |
> |
public Class<?> klazz() { return ConcurrentLinkedDeque.class; } |
30 |
> |
public Collection emptyCollection() { return new ConcurrentLinkedDeque(); } |
31 |
> |
public Object makeElement(int i) { return i; } |
32 |
> |
public boolean isConcurrent() { return true; } |
33 |
> |
public boolean permitsNulls() { return false; } |
34 |
> |
} |
35 |
> |
return newTestSuite(ConcurrentLinkedDequeTest.class, |
36 |
> |
CollectionTest.testSuite(new Implementation())); |
37 |
|
} |
38 |
|
|
39 |
|
/** |
40 |
|
* Returns a new deque of given size containing consecutive |
41 |
< |
* Integers 0 ... n. |
41 |
> |
* Integers 0 ... n - 1. |
42 |
|
*/ |
43 |
|
private ConcurrentLinkedDeque<Integer> populatedDeque(int n) { |
44 |
|
ConcurrentLinkedDeque<Integer> q = new ConcurrentLinkedDeque<Integer>(); |
47 |
|
assertTrue(q.offer(new Integer(i))); |
48 |
|
assertFalse(q.isEmpty()); |
49 |
|
assertEquals(n, q.size()); |
50 |
+ |
assertEquals((Integer) 0, q.peekFirst()); |
51 |
+ |
assertEquals((Integer) (n - 1), q.peekLast()); |
52 |
|
return q; |
53 |
|
} |
54 |
|
|
85 |
|
*/ |
86 |
|
public void testConstructor5() { |
87 |
|
Integer[] ints = new Integer[SIZE]; |
88 |
< |
for (int i = 0; i < SIZE-1; ++i) |
88 |
> |
for (int i = 0; i < SIZE - 1; ++i) |
89 |
|
ints[i] = new Integer(i); |
90 |
|
try { |
91 |
|
new ConcurrentLinkedDeque(Arrays.asList(ints)); |
125 |
|
public void testSize() { |
126 |
|
ConcurrentLinkedDeque q = populatedDeque(SIZE); |
127 |
|
for (int i = 0; i < SIZE; ++i) { |
128 |
< |
assertEquals(SIZE-i, q.size()); |
128 |
> |
assertEquals(SIZE - i, q.size()); |
129 |
|
q.remove(); |
130 |
|
} |
131 |
|
for (int i = 0; i < SIZE; ++i) { |
341 |
|
public void testAddAll3() { |
342 |
|
ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); |
343 |
|
Integer[] ints = new Integer[SIZE]; |
344 |
< |
for (int i = 0; i < SIZE-1; ++i) |
344 |
> |
for (int i = 0; i < SIZE - 1; ++i) |
345 |
|
ints[i] = new Integer(i); |
346 |
|
try { |
347 |
|
q.addAll(Arrays.asList(ints)); |
380 |
|
*/ |
381 |
|
public void testPollLast() { |
382 |
|
ConcurrentLinkedDeque q = populatedDeque(SIZE); |
383 |
< |
for (int i = SIZE-1; i >= 0; --i) { |
383 |
> |
for (int i = SIZE - 1; i >= 0; --i) { |
384 |
|
assertEquals(i, q.pollLast()); |
385 |
|
} |
386 |
|
assertNull(q.pollLast()); |
449 |
|
assertTrue(q.contains(i)); |
450 |
|
assertTrue(q.remove(i)); |
451 |
|
assertFalse(q.contains(i)); |
452 |
< |
assertTrue(q.contains(i-1)); |
452 |
> |
assertTrue(q.contains(i - 1)); |
453 |
|
} |
454 |
|
for (int i = 0; i < SIZE; i += 2) { |
455 |
|
assertTrue(q.contains(i)); |
456 |
|
assertTrue(q.remove(i)); |
457 |
|
assertFalse(q.contains(i)); |
458 |
< |
assertFalse(q.remove(i+1)); |
459 |
< |
assertFalse(q.contains(i+1)); |
458 |
> |
assertFalse(q.remove(i + 1)); |
459 |
> |
assertFalse(q.contains(i + 1)); |
460 |
|
} |
461 |
|
assertTrue(q.isEmpty()); |
462 |
|
} |
480 |
|
*/ |
481 |
|
public void testPeekLast() { |
482 |
|
ConcurrentLinkedDeque q = populatedDeque(SIZE); |
483 |
< |
for (int i = SIZE-1; i >= 0; --i) { |
483 |
> |
for (int i = SIZE - 1; i >= 0; --i) { |
484 |
|
assertEquals(i, q.peekLast()); |
485 |
|
assertEquals(i, q.pollLast()); |
486 |
|
assertTrue(q.peekLast() == null || |
509 |
|
*/ |
510 |
|
public void testLastElement() { |
511 |
|
ConcurrentLinkedDeque q = populatedDeque(SIZE); |
512 |
< |
for (int i = SIZE-1; i >= 0; --i) { |
512 |
> |
for (int i = SIZE - 1; i >= 0; --i) { |
513 |
|
assertEquals(i, q.getLast()); |
514 |
|
assertEquals(i, q.pollLast()); |
515 |
|
} |
560 |
|
} |
561 |
|
for (int i = 0; i < SIZE; i += 2) { |
562 |
|
assertTrue(q.removeFirstOccurrence(new Integer(i))); |
563 |
< |
assertFalse(q.removeFirstOccurrence(new Integer(i+1))); |
563 |
> |
assertFalse(q.removeFirstOccurrence(new Integer(i + 1))); |
564 |
|
} |
565 |
|
assertTrue(q.isEmpty()); |
566 |
|
} |
575 |
|
} |
576 |
|
for (int i = 0; i < SIZE; i += 2) { |
577 |
|
assertTrue(q.removeLastOccurrence(new Integer(i))); |
578 |
< |
assertFalse(q.removeLastOccurrence(new Integer(i+1))); |
578 |
> |
assertFalse(q.removeLastOccurrence(new Integer(i + 1))); |
579 |
|
} |
580 |
|
assertTrue(q.isEmpty()); |
581 |
|
} |
634 |
|
assertTrue(changed); |
635 |
|
|
636 |
|
assertTrue(q.containsAll(p)); |
637 |
< |
assertEquals(SIZE-i, q.size()); |
637 |
> |
assertEquals(SIZE - i, q.size()); |
638 |
|
p.remove(); |
639 |
|
} |
640 |
|
} |
647 |
|
ConcurrentLinkedDeque q = populatedDeque(SIZE); |
648 |
|
ConcurrentLinkedDeque p = populatedDeque(i); |
649 |
|
assertTrue(q.removeAll(p)); |
650 |
< |
assertEquals(SIZE-i, q.size()); |
650 |
> |
assertEquals(SIZE - i, q.size()); |
651 |
|
for (int j = 0; j < i; ++j) { |
652 |
|
Integer x = (Integer)(p.remove()); |
653 |
|
assertFalse(q.contains(x)); |
763 |
|
final Random rng = new Random(); |
764 |
|
for (int iters = 0; iters < 100; ++iters) { |
765 |
|
int max = rng.nextInt(5) + 2; |
766 |
< |
int split = rng.nextInt(max-1) + 1; |
766 |
> |
int split = rng.nextInt(max - 1) + 1; |
767 |
|
for (int j = 1; j <= max; ++j) |
768 |
|
q.add(new Integer(j)); |
769 |
|
Iterator it = q.iterator(); |
770 |
|
for (int j = 1; j <= split; ++j) |
771 |
|
assertEquals(it.next(), new Integer(j)); |
772 |
|
it.remove(); |
773 |
< |
assertEquals(it.next(), new Integer(split+1)); |
773 |
> |
assertEquals(it.next(), new Integer(split + 1)); |
774 |
|
for (int j = 1; j <= split; ++j) |
775 |
|
q.remove(new Integer(j)); |
776 |
|
it = q.iterator(); |
777 |
< |
for (int j = split+1; j <= max; ++j) { |
777 |
> |
for (int j = split + 1; j <= max; ++j) { |
778 |
|
assertEquals(it.next(), new Integer(j)); |
779 |
|
it.remove(); |
780 |
|
} |
831 |
|
final Random rng = new Random(); |
832 |
|
for (int iters = 0; iters < 100; ++iters) { |
833 |
|
int max = rng.nextInt(5) + 2; |
834 |
< |
int split = rng.nextInt(max-1) + 1; |
834 |
> |
int split = rng.nextInt(max - 1) + 1; |
835 |
|
for (int j = max; j >= 1; --j) |
836 |
|
q.add(new Integer(j)); |
837 |
|
Iterator it = q.descendingIterator(); |
838 |
|
for (int j = 1; j <= split; ++j) |
839 |
|
assertEquals(it.next(), new Integer(j)); |
840 |
|
it.remove(); |
841 |
< |
assertEquals(it.next(), new Integer(split+1)); |
841 |
> |
assertEquals(it.next(), new Integer(split + 1)); |
842 |
|
for (int j = 1; j <= split; ++j) |
843 |
|
q.remove(new Integer(j)); |
844 |
|
it = q.descendingIterator(); |
845 |
< |
for (int j = split+1; j <= max; ++j) { |
845 |
> |
for (int j = split + 1; j <= max; ++j) { |
846 |
|
assertEquals(it.next(), new Integer(j)); |
847 |
|
it.remove(); |
848 |
|
} |