10 |
|
|
11 |
|
public class ArrayDequeTest extends JSR166TestCase { |
12 |
|
public static void main(String[] args) { |
13 |
< |
junit.textui.TestRunner.run (suite()); |
13 |
> |
junit.textui.TestRunner.run (suite()); |
14 |
|
} |
15 |
|
|
16 |
|
public static Test suite() { |
30 |
|
assertEquals(n, q.size()); |
31 |
|
return q; |
32 |
|
} |
33 |
< |
|
33 |
> |
|
34 |
|
/** |
35 |
|
* new queue is empty |
36 |
|
*/ |
102 |
|
ArrayDeque q = new ArrayDeque(1); |
103 |
|
q.push(null); |
104 |
|
shouldThrow(); |
105 |
< |
} catch (NullPointerException success) { } |
105 |
> |
} catch (NullPointerException success) { } |
106 |
|
} |
107 |
|
|
108 |
|
/** |
113 |
|
q.pollLast(); |
114 |
|
q.push(four); |
115 |
|
assertEquals(four,q.peekFirst()); |
116 |
< |
} |
116 |
> |
} |
117 |
|
|
118 |
|
/** |
119 |
|
* pop removes next element, or throws NSEE if empty |
127 |
|
q.pop(); |
128 |
|
shouldThrow(); |
129 |
|
} catch (NoSuchElementException success){ |
130 |
< |
} |
130 |
> |
} |
131 |
|
} |
132 |
|
|
133 |
|
/** |
138 |
|
ArrayDeque q = new ArrayDeque(); |
139 |
|
q.offerFirst(null); |
140 |
|
shouldThrow(); |
141 |
< |
} catch (NullPointerException success) { |
142 |
< |
} |
141 |
> |
} catch (NullPointerException success) { |
142 |
> |
} |
143 |
|
} |
144 |
|
|
145 |
|
/** |
146 |
< |
* OfferFirst succeeds |
146 |
> |
* OfferFirst succeeds |
147 |
|
*/ |
148 |
|
public void testOfferFirst() { |
149 |
|
ArrayDeque q = new ArrayDeque(); |
152 |
|
} |
153 |
|
|
154 |
|
/** |
155 |
< |
* OfferLast succeeds |
155 |
> |
* OfferLast succeeds |
156 |
|
*/ |
157 |
|
public void testOfferLast() { |
158 |
|
ArrayDeque q = new ArrayDeque(); |
246 |
|
q.remove(); |
247 |
|
shouldThrow(); |
248 |
|
} catch (NoSuchElementException success){ |
249 |
< |
} |
249 |
> |
} |
250 |
|
} |
251 |
|
|
252 |
|
/** |
337 |
|
q.removeFirst(); |
338 |
|
shouldThrow(); |
339 |
|
} catch (NoSuchElementException success){ |
340 |
< |
} |
340 |
> |
} |
341 |
|
} |
342 |
|
|
343 |
|
/** |
491 |
|
shouldThrow(); |
492 |
|
} catch(ArrayStoreException success){} |
493 |
|
} |
494 |
< |
|
494 |
> |
|
495 |
|
/** |
496 |
|
* iterator iterates through all elements |
497 |
|
*/ |
535 |
|
for (int j = 1; j <= max; ++j) |
536 |
|
q.add(new Integer(j)); |
537 |
|
Iterator it = q.iterator(); |
538 |
< |
for (int j = 1; j <= split; ++j) |
538 |
> |
for (int j = 1; j <= split; ++j) |
539 |
|
assertEquals(it.next(), new Integer(j)); |
540 |
|
it.remove(); |
541 |
|
assertEquals(it.next(), new Integer(split+1)); |
542 |
< |
for (int j = 1; j <= split; ++j) |
542 |
> |
for (int j = 1; j <= split; ++j) |
543 |
|
q.remove(new Integer(j)); |
544 |
|
it = q.iterator(); |
545 |
|
for (int j = split+1; j <= max; ++j) { |
584 |
|
int i = ((Integer)(it.next())).intValue(); |
585 |
|
assertEquals(++k, i); |
586 |
|
} |
587 |
< |
|
587 |
> |
|
588 |
|
assertEquals(3, k); |
589 |
|
q.remove(); |
590 |
|
q.remove(); |
604 |
|
for (int j = max; j >= 1; --j) |
605 |
|
q.add(new Integer(j)); |
606 |
|
Iterator it = q.descendingIterator(); |
607 |
< |
for (int j = 1; j <= split; ++j) |
607 |
> |
for (int j = 1; j <= split; ++j) |
608 |
|
assertEquals(it.next(), new Integer(j)); |
609 |
|
it.remove(); |
610 |
|
assertEquals(it.next(), new Integer(split+1)); |
611 |
< |
for (int j = 1; j <= split; ++j) |
611 |
> |
for (int j = 1; j <= split; ++j) |
612 |
|
q.remove(new Integer(j)); |
613 |
|
it = q.descendingIterator(); |
614 |
|
for (int j = split+1; j <= max; ++j) { |
630 |
|
for (int i = 0; i < SIZE; ++i) { |
631 |
|
assertTrue(s.indexOf(String.valueOf(i)) >= 0); |
632 |
|
} |
633 |
< |
} |
633 |
> |
} |
634 |
|
|
635 |
|
/** |
636 |
|
* peekFirst returns element inserted with addFirst |
639 |
|
ArrayDeque q = populatedDeque(3); |
640 |
|
q.addFirst(four); |
641 |
|
assertEquals(four,q.peekFirst()); |
642 |
< |
} |
642 |
> |
} |
643 |
|
|
644 |
|
/** |
645 |
|
* peekLast returns element inserted with addLast |
648 |
|
ArrayDeque q = populatedDeque(3); |
649 |
|
q.addLast(four); |
650 |
|
assertEquals(four,q.peekLast()); |
651 |
< |
} |
651 |
> |
} |
652 |
|
|
653 |
|
} |