ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ArrayDequeTest.java
(Generate patch)

Comparing jsr166/src/test/tck/ArrayDequeTest.java (file contents):
Revision 1.32 by jsr166, Sat Jan 17 22:55:06 2015 UTC vs.
Revision 1.37 by jsr166, Sun May 24 01:23:17 2015 UTC

# Line 18 | Line 18 | import junit.framework.TestSuite;
18  
19   public class ArrayDequeTest extends JSR166TestCase {
20      public static void main(String[] args) {
21 <        junit.textui.TestRunner.run(suite());
21 >        main(suite(), args);
22      }
23  
24      public static Test suite() {
# Line 51 | Line 51 | public class ArrayDequeTest extends JSR1
51       */
52      public void testConstructor3() {
53          try {
54 <            ArrayDeque q = new ArrayDeque((Collection)null);
54 >            new ArrayDeque((Collection)null);
55              shouldThrow();
56          } catch (NullPointerException success) {}
57      }
# Line 61 | Line 61 | public class ArrayDequeTest extends JSR1
61       */
62      public void testConstructor4() {
63          try {
64 <            Integer[] ints = new Integer[SIZE];
65 <            ArrayDeque q = new ArrayDeque(Arrays.asList(ints));
64 >            new ArrayDeque(Arrays.asList(new Integer[SIZE]));
65              shouldThrow();
66          } catch (NullPointerException success) {}
67      }
# Line 71 | Line 70 | public class ArrayDequeTest extends JSR1
70       * Initializing from Collection with some null elements throws NPE
71       */
72      public void testConstructor5() {
73 +        Integer[] ints = new Integer[SIZE];
74 +        for (int i = 0; i < SIZE - 1; ++i)
75 +            ints[i] = new Integer(i);
76          try {
77 <            Integer[] ints = new Integer[SIZE];
76 <            for (int i = 0; i < SIZE-1; ++i)
77 <                ints[i] = new Integer(i);
78 <            ArrayDeque q = new ArrayDeque(Arrays.asList(ints));
77 >            new ArrayDeque(Arrays.asList(ints));
78              shouldThrow();
79          } catch (NullPointerException success) {}
80      }
# Line 112 | Line 111 | public class ArrayDequeTest extends JSR1
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) {
# Line 125 | Line 124 | public class ArrayDequeTest extends JSR1
124       * push(null) throws NPE
125       */
126      public void testPushNull() {
127 +        ArrayDeque q = new ArrayDeque(1);
128          try {
129            ArrayDeque q = new ArrayDeque(1);
129              q.push(null);
130              shouldThrow();
131          } catch (NullPointerException success) {}
# Line 160 | Line 159 | public class ArrayDequeTest extends JSR1
159       * offer(null) throws NPE
160       */
161      public void testOfferNull() {
162 +        ArrayDeque q = new ArrayDeque();
163          try {
164            ArrayDeque q = new ArrayDeque();
164              q.offer(null);
165              shouldThrow();
166          } catch (NullPointerException success) {}
# Line 171 | Line 170 | public class ArrayDequeTest extends JSR1
170       * offerFirst(null) throws NPE
171       */
172      public void testOfferFirstNull() {
173 +        ArrayDeque q = new ArrayDeque();
174          try {
175            ArrayDeque q = new ArrayDeque();
175              q.offerFirst(null);
176              shouldThrow();
177          } catch (NullPointerException success) {}
# Line 182 | Line 181 | public class ArrayDequeTest extends JSR1
181       * offerLast(null) throws NPE
182       */
183      public void testOfferLastNull() {
184 +        ArrayDeque q = new ArrayDeque();
185          try {
186            ArrayDeque q = new ArrayDeque();
186              q.offerLast(null);
187              shouldThrow();
188          } catch (NullPointerException success) {}
# Line 226 | Line 225 | public class ArrayDequeTest extends JSR1
225       * add(null) throws NPE
226       */
227      public void testAddNull() {
228 +        ArrayDeque q = new ArrayDeque();
229          try {
230            ArrayDeque q = new ArrayDeque();
230              q.add(null);
231              shouldThrow();
232          } catch (NullPointerException success) {}
# Line 237 | Line 236 | public class ArrayDequeTest extends JSR1
236       * addFirst(null) throws NPE
237       */
238      public void testAddFirstNull() {
239 +        ArrayDeque q = new ArrayDeque();
240          try {
241            ArrayDeque q = new ArrayDeque();
241              q.addFirst(null);
242              shouldThrow();
243          } catch (NullPointerException success) {}
# Line 248 | Line 247 | public class ArrayDequeTest extends JSR1
247       * addLast(null) throws NPE
248       */
249      public void testAddLastNull() {
250 +        ArrayDeque q = new ArrayDeque();
251          try {
252            ArrayDeque q = new ArrayDeque();
252              q.addLast(null);
253              shouldThrow();
254          } catch (NullPointerException success) {}
# Line 292 | Line 291 | public class ArrayDequeTest extends JSR1
291       * addAll(null) throws NPE
292       */
293      public void testAddAll1() {
294 +        ArrayDeque q = new ArrayDeque();
295          try {
296            ArrayDeque q = new ArrayDeque();
296              q.addAll(null);
297              shouldThrow();
298          } catch (NullPointerException success) {}
# Line 303 | Line 302 | public class ArrayDequeTest extends JSR1
302       * addAll of a collection with null elements throws NPE
303       */
304      public void testAddAll2() {
305 +        ArrayDeque q = new ArrayDeque();
306          try {
307 <            ArrayDeque q = new ArrayDeque();
308 <            Integer[] ints = new Integer[SIZE];
309 <            q.addAll(Arrays.asList(ints));
307 >            q.addAll(Arrays.asList(new Integer[SIZE]));
308              shouldThrow();
309          } catch (NullPointerException success) {}
310      }
# Line 316 | Line 314 | public class ArrayDequeTest extends JSR1
314       * possibly adding some elements
315       */
316      public void testAddAll3() {
317 +        ArrayDeque q = new ArrayDeque();
318 +        Integer[] ints = new Integer[SIZE];
319 +        for (int i = 0; i < SIZE - 1; ++i)
320 +            ints[i] = new Integer(i);
321          try {
320            ArrayDeque q = new ArrayDeque();
321            Integer[] ints = new Integer[SIZE];
322            for (int i = 0; i < SIZE-1; ++i)
323                ints[i] = new Integer(i);
322              q.addAll(Arrays.asList(ints));
323              shouldThrow();
324          } catch (NullPointerException success) {}
# Line 357 | Line 355 | public class ArrayDequeTest extends JSR1
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());
# Line 442 | Line 440 | public class ArrayDequeTest extends JSR1
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 ||
# Line 486 | Line 484 | public class ArrayDequeTest extends JSR1
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          }
# Line 607 | Line 605 | public class ArrayDequeTest extends JSR1
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      }
# Line 620 | Line 618 | public class ArrayDequeTest extends JSR1
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              }
# Line 652 | Line 650 | public class ArrayDequeTest extends JSR1
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);
# Line 682 | Line 680 | public class ArrayDequeTest extends JSR1
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);
# Line 705 | Line 703 | public class ArrayDequeTest extends JSR1
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  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines