71 |
|
*/ |
72 |
|
public void testConstructor5() { |
73 |
|
Integer[] ints = new Integer[SIZE]; |
74 |
< |
for (int i = 0; i < SIZE-1; ++i) |
74 |
> |
for (int i = 0; i < SIZE - 1; ++i) |
75 |
|
ints[i] = new Integer(i); |
76 |
|
try { |
77 |
|
new ArrayDeque(Arrays.asList(ints)); |
111 |
|
public void testSize() { |
112 |
|
ArrayDeque q = populatedDeque(SIZE); |
113 |
|
for (int i = 0; i < SIZE; ++i) { |
114 |
< |
assertEquals(SIZE-i, q.size()); |
114 |
> |
assertEquals(SIZE - i, q.size()); |
115 |
|
q.removeFirst(); |
116 |
|
} |
117 |
|
for (int i = 0; i < SIZE; ++i) { |
316 |
|
public void testAddAll3() { |
317 |
|
ArrayDeque q = new ArrayDeque(); |
318 |
|
Integer[] ints = new Integer[SIZE]; |
319 |
< |
for (int i = 0; i < SIZE-1; ++i) |
319 |
> |
for (int i = 0; i < SIZE - 1; ++i) |
320 |
|
ints[i] = new Integer(i); |
321 |
|
try { |
322 |
|
q.addAll(Arrays.asList(ints)); |
355 |
|
*/ |
356 |
|
public void testPollLast() { |
357 |
|
ArrayDeque q = populatedDeque(SIZE); |
358 |
< |
for (int i = SIZE-1; i >= 0; --i) { |
358 |
> |
for (int i = SIZE - 1; i >= 0; --i) { |
359 |
|
assertEquals(i, q.pollLast()); |
360 |
|
} |
361 |
|
assertNull(q.pollLast()); |
395 |
|
assertTrue(q.contains(i)); |
396 |
|
assertTrue(q.remove(i)); |
397 |
|
assertFalse(q.contains(i)); |
398 |
< |
assertTrue(q.contains(i-1)); |
398 |
> |
assertTrue(q.contains(i - 1)); |
399 |
|
} |
400 |
|
for (int i = 0; i < SIZE; i += 2) { |
401 |
|
assertTrue(q.contains(i)); |
402 |
|
assertTrue(q.remove(i)); |
403 |
|
assertFalse(q.contains(i)); |
404 |
< |
assertFalse(q.remove(i+1)); |
405 |
< |
assertFalse(q.contains(i+1)); |
404 |
> |
assertFalse(q.remove(i + 1)); |
405 |
> |
assertFalse(q.contains(i + 1)); |
406 |
|
} |
407 |
|
assertTrue(q.isEmpty()); |
408 |
|
} |
440 |
|
*/ |
441 |
|
public void testPeekLast() { |
442 |
|
ArrayDeque q = populatedDeque(SIZE); |
443 |
< |
for (int i = SIZE-1; i >= 0; --i) { |
443 |
> |
for (int i = SIZE - 1; i >= 0; --i) { |
444 |
|
assertEquals(i, q.peekLast()); |
445 |
|
assertEquals(i, q.pollLast()); |
446 |
|
assertTrue(q.peekLast() == null || |
484 |
|
*/ |
485 |
|
public void testLastElement() { |
486 |
|
ArrayDeque q = populatedDeque(SIZE); |
487 |
< |
for (int i = SIZE-1; i >= 0; --i) { |
487 |
> |
for (int i = SIZE - 1; i >= 0; --i) { |
488 |
|
assertEquals(i, q.getLast()); |
489 |
|
assertEquals(i, q.pollLast()); |
490 |
|
} |
535 |
|
} |
536 |
|
for (int i = 0; i < SIZE; i += 2) { |
537 |
|
assertTrue(q.removeFirstOccurrence(new Integer(i))); |
538 |
< |
assertFalse(q.removeFirstOccurrence(new Integer(i+1))); |
538 |
> |
assertFalse(q.removeFirstOccurrence(new Integer(i + 1))); |
539 |
|
} |
540 |
|
assertTrue(q.isEmpty()); |
541 |
|
} |
550 |
|
} |
551 |
|
for (int i = 0; i < SIZE; i += 2) { |
552 |
|
assertTrue(q.removeLastOccurrence(new Integer(i))); |
553 |
< |
assertFalse(q.removeLastOccurrence(new Integer(i+1))); |
553 |
> |
assertFalse(q.removeLastOccurrence(new Integer(i + 1))); |
554 |
|
} |
555 |
|
assertTrue(q.isEmpty()); |
556 |
|
} |
605 |
|
boolean changed = q.retainAll(p); |
606 |
|
assertEquals(changed, (i > 0)); |
607 |
|
assertTrue(q.containsAll(p)); |
608 |
< |
assertEquals(SIZE-i, q.size()); |
608 |
> |
assertEquals(SIZE - i, q.size()); |
609 |
|
p.removeFirst(); |
610 |
|
} |
611 |
|
} |
618 |
|
ArrayDeque q = populatedDeque(SIZE); |
619 |
|
ArrayDeque p = populatedDeque(i); |
620 |
|
assertTrue(q.removeAll(p)); |
621 |
< |
assertEquals(SIZE-i, q.size()); |
621 |
> |
assertEquals(SIZE - i, q.size()); |
622 |
|
for (int j = 0; j < i; ++j) { |
623 |
|
assertFalse(q.contains(p.removeFirst())); |
624 |
|
} |
650 |
|
for (int i = 0; i < SIZE; i++) { |
651 |
|
checkToArray(q); |
652 |
|
assertEquals(i, q.poll()); |
653 |
< |
q.addLast(SIZE+i); |
653 |
> |
q.addLast(SIZE + i); |
654 |
|
} |
655 |
|
for (int i = 0; i < SIZE; i++) { |
656 |
|
checkToArray(q); |
657 |
< |
assertEquals(SIZE+i, q.poll()); |
657 |
> |
assertEquals(SIZE + i, q.poll()); |
658 |
|
} |
659 |
|
} |
660 |
|
|
661 |
|
void checkToArray2(ArrayDeque q) { |
662 |
|
int size = q.size(); |
663 |
< |
Integer[] a1 = size == 0 ? null : new Integer[size-1]; |
663 |
> |
Integer[] a1 = (size == 0) ? null : new Integer[size - 1]; |
664 |
|
Integer[] a2 = new Integer[size]; |
665 |
< |
Integer[] a3 = new Integer[size+2]; |
665 |
> |
Integer[] a3 = new Integer[size + 2]; |
666 |
|
if (size > 0) Arrays.fill(a1, 42); |
667 |
|
Arrays.fill(a2, 42); |
668 |
|
Arrays.fill(a3, 42); |
669 |
< |
Integer[] b1 = size == 0 ? null : (Integer[]) q.toArray(a1); |
669 |
> |
Integer[] b1 = (size == 0) ? null : (Integer[]) q.toArray(a1); |
670 |
|
Integer[] b2 = (Integer[]) q.toArray(a2); |
671 |
|
Integer[] b3 = (Integer[]) q.toArray(a3); |
672 |
|
assertSame(a2, b2); |
680 |
|
assertSame(b3[i], x); |
681 |
|
} |
682 |
|
assertNull(a3[size]); |
683 |
< |
assertEquals(42, (int) a3[size+1]); |
683 |
> |
assertEquals(42, (int) a3[size + 1]); |
684 |
|
if (size > 0) { |
685 |
|
assertNotSame(a1, b1); |
686 |
|
assertEquals(size, b1.length); |
703 |
|
for (int i = 0; i < SIZE; i++) { |
704 |
|
checkToArray2(q); |
705 |
|
assertEquals(i, q.poll()); |
706 |
< |
q.addLast(SIZE+i); |
706 |
> |
q.addLast(SIZE + i); |
707 |
|
} |
708 |
|
for (int i = 0; i < SIZE; i++) { |
709 |
|
checkToArray2(q); |
710 |
< |
assertEquals(SIZE+i, q.poll()); |
710 |
> |
assertEquals(SIZE + i, q.poll()); |
711 |
|
} |
712 |
|
} |
713 |
|
|
781 |
|
final Random rng = new Random(); |
782 |
|
for (int iters = 0; iters < 100; ++iters) { |
783 |
|
int max = rng.nextInt(5) + 2; |
784 |
< |
int split = rng.nextInt(max-1) + 1; |
784 |
> |
int split = rng.nextInt(max - 1) + 1; |
785 |
|
for (int j = 1; j <= max; ++j) |
786 |
|
q.add(new Integer(j)); |
787 |
|
Iterator it = q.iterator(); |
788 |
|
for (int j = 1; j <= split; ++j) |
789 |
|
assertEquals(it.next(), new Integer(j)); |
790 |
|
it.remove(); |
791 |
< |
assertEquals(it.next(), new Integer(split+1)); |
791 |
> |
assertEquals(it.next(), new Integer(split + 1)); |
792 |
|
for (int j = 1; j <= split; ++j) |
793 |
|
q.remove(new Integer(j)); |
794 |
|
it = q.iterator(); |
795 |
< |
for (int j = split+1; j <= max; ++j) { |
795 |
> |
for (int j = split + 1; j <= max; ++j) { |
796 |
|
assertEquals(it.next(), new Integer(j)); |
797 |
|
it.remove(); |
798 |
|
} |
849 |
|
final Random rng = new Random(); |
850 |
|
for (int iters = 0; iters < 100; ++iters) { |
851 |
|
int max = rng.nextInt(5) + 2; |
852 |
< |
int split = rng.nextInt(max-1) + 1; |
852 |
> |
int split = rng.nextInt(max - 1) + 1; |
853 |
|
for (int j = max; j >= 1; --j) |
854 |
|
q.add(new Integer(j)); |
855 |
|
Iterator it = q.descendingIterator(); |
856 |
|
for (int j = 1; j <= split; ++j) |
857 |
|
assertEquals(it.next(), new Integer(j)); |
858 |
|
it.remove(); |
859 |
< |
assertEquals(it.next(), new Integer(split+1)); |
859 |
> |
assertEquals(it.next(), new Integer(split + 1)); |
860 |
|
for (int j = 1; j <= split; ++j) |
861 |
|
q.remove(new Integer(j)); |
862 |
|
it = q.descendingIterator(); |
863 |
< |
for (int j = split+1; j <= max; ++j) { |
863 |
> |
for (int j = split + 1; j <= max; ++j) { |
864 |
|
assertEquals(it.next(), new Integer(j)); |
865 |
|
it.remove(); |
866 |
|
} |