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

Comparing jsr166/src/test/tck/ConcurrentLinkedDequeTest.java (file contents):
Revision 1.15 by jsr166, Wed Dec 31 20:09:08 2014 UTC vs.
Revision 1.23 by jsr166, Sun Oct 16 20:16:36 2016 UTC

# Line 21 | Line 21 | import junit.framework.TestSuite;
21   public class ConcurrentLinkedDequeTest extends JSR166TestCase {
22  
23      public static void main(String[] args) {
24 <        junit.textui.TestRunner.run(suite());
24 >        main(suite(), args);
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      /**
# Line 55 | Line 63 | public class ConcurrentLinkedDequeTest e
63       */
64      public void testConstructor3() {
65          try {
66 <            ConcurrentLinkedDeque q = new ConcurrentLinkedDeque((Collection)null);
66 >            new ConcurrentLinkedDeque((Collection)null);
67              shouldThrow();
68          } catch (NullPointerException success) {}
69      }
# Line 65 | Line 73 | public class ConcurrentLinkedDequeTest e
73       */
74      public void testConstructor4() {
75          try {
76 <            Integer[] ints = new Integer[SIZE];
69 <            ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(Arrays.asList(ints));
76 >            new ConcurrentLinkedDeque(Arrays.asList(new Integer[SIZE]));
77              shouldThrow();
78          } catch (NullPointerException success) {}
79      }
# Line 75 | Line 82 | public class ConcurrentLinkedDequeTest e
82       * Initializing from Collection with some null elements throws NPE
83       */
84      public void testConstructor5() {
85 +        Integer[] ints = new Integer[SIZE];
86 +        for (int i = 0; i < SIZE - 1; ++i)
87 +            ints[i] = new Integer(i);
88          try {
89 <            Integer[] ints = new Integer[SIZE];
80 <            for (int i = 0; i < SIZE-1; ++i)
81 <                ints[i] = new Integer(i);
82 <            ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(Arrays.asList(ints));
89 >            new ConcurrentLinkedDeque(Arrays.asList(ints));
90              shouldThrow();
91          } catch (NullPointerException success) {}
92      }
# Line 116 | Line 123 | public class ConcurrentLinkedDequeTest e
123      public void testSize() {
124          ConcurrentLinkedDeque q = populatedDeque(SIZE);
125          for (int i = 0; i < SIZE; ++i) {
126 <            assertEquals(SIZE-i, q.size());
126 >            assertEquals(SIZE - i, q.size());
127              q.remove();
128          }
129          for (int i = 0; i < SIZE; ++i) {
# Line 129 | Line 136 | public class ConcurrentLinkedDequeTest e
136       * push(null) throws NPE
137       */
138      public void testPushNull() {
139 +        ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
140          try {
133            ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
141              q.push(null);
142              shouldThrow();
143          } catch (NullPointerException success) {}
# Line 164 | Line 171 | public class ConcurrentLinkedDequeTest e
171       * offer(null) throws NPE
172       */
173      public void testOfferNull() {
174 +        ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
175          try {
168            ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
176              q.offer(null);
177              shouldThrow();
178          } catch (NullPointerException success) {}
# Line 175 | Line 182 | public class ConcurrentLinkedDequeTest e
182       * offerFirst(null) throws NPE
183       */
184      public void testOfferFirstNull() {
185 +        ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
186          try {
179            ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
187              q.offerFirst(null);
188              shouldThrow();
189          } catch (NullPointerException success) {}
# Line 186 | Line 193 | public class ConcurrentLinkedDequeTest e
193       * offerLast(null) throws NPE
194       */
195      public void testOfferLastNull() {
196 +        ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
197          try {
190            ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
198              q.offerLast(null);
199              shouldThrow();
200          } catch (NullPointerException success) {}
# Line 230 | Line 237 | public class ConcurrentLinkedDequeTest e
237       * add(null) throws NPE
238       */
239      public void testAddNull() {
240 +        ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
241          try {
234            ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
242              q.add(null);
243              shouldThrow();
244          } catch (NullPointerException success) {}
# Line 241 | Line 248 | public class ConcurrentLinkedDequeTest e
248       * addFirst(null) throws NPE
249       */
250      public void testAddFirstNull() {
251 +        ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
252          try {
245            ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
253              q.addFirst(null);
254              shouldThrow();
255          } catch (NullPointerException success) {}
# Line 252 | Line 259 | public class ConcurrentLinkedDequeTest e
259       * addLast(null) throws NPE
260       */
261      public void testAddLastNull() {
262 +        ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
263          try {
256            ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
264              q.addLast(null);
265              shouldThrow();
266          } catch (NullPointerException success) {}
# Line 296 | Line 303 | public class ConcurrentLinkedDequeTest e
303       * addAll(null) throws NPE
304       */
305      public void testAddAll1() {
306 +        ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
307          try {
300            ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
308              q.addAll(null);
309              shouldThrow();
310          } catch (NullPointerException success) {}
# Line 307 | Line 314 | public class ConcurrentLinkedDequeTest e
314       * addAll(this) throws IAE
315       */
316      public void testAddAllSelf() {
317 +        ConcurrentLinkedDeque q = populatedDeque(SIZE);
318          try {
311            ConcurrentLinkedDeque q = populatedDeque(SIZE);
319              q.addAll(q);
320              shouldThrow();
321          } catch (IllegalArgumentException success) {}
# Line 318 | Line 325 | public class ConcurrentLinkedDequeTest e
325       * addAll of a collection with null elements throws NPE
326       */
327      public void testAddAll2() {
328 +        ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
329          try {
330 <            ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
323 <            Integer[] ints = new Integer[SIZE];
324 <            q.addAll(Arrays.asList(ints));
330 >            q.addAll(Arrays.asList(new Integer[SIZE]));
331              shouldThrow();
332          } catch (NullPointerException success) {}
333      }
# Line 331 | Line 337 | public class ConcurrentLinkedDequeTest e
337       * possibly adding some elements
338       */
339      public void testAddAll3() {
340 +        ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
341 +        Integer[] ints = new Integer[SIZE];
342 +        for (int i = 0; i < SIZE - 1; ++i)
343 +            ints[i] = new Integer(i);
344          try {
335            ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
336            Integer[] ints = new Integer[SIZE];
337            for (int i = 0; i < SIZE-1; ++i)
338                ints[i] = new Integer(i);
345              q.addAll(Arrays.asList(ints));
346              shouldThrow();
347          } catch (NullPointerException success) {}
# Line 372 | Line 378 | public class ConcurrentLinkedDequeTest e
378       */
379      public void testPollLast() {
380          ConcurrentLinkedDeque q = populatedDeque(SIZE);
381 <        for (int i = SIZE-1; i >= 0; --i) {
381 >        for (int i = SIZE - 1; i >= 0; --i) {
382              assertEquals(i, q.pollLast());
383          }
384          assertNull(q.pollLast());
# Line 441 | Line 447 | public class ConcurrentLinkedDequeTest e
447              assertTrue(q.contains(i));
448              assertTrue(q.remove(i));
449              assertFalse(q.contains(i));
450 <            assertTrue(q.contains(i-1));
450 >            assertTrue(q.contains(i - 1));
451          }
452          for (int i = 0; i < SIZE; i += 2) {
453              assertTrue(q.contains(i));
454              assertTrue(q.remove(i));
455              assertFalse(q.contains(i));
456 <            assertFalse(q.remove(i+1));
457 <            assertFalse(q.contains(i+1));
456 >            assertFalse(q.remove(i + 1));
457 >            assertFalse(q.contains(i + 1));
458          }
459          assertTrue(q.isEmpty());
460      }
# Line 472 | Line 478 | public class ConcurrentLinkedDequeTest e
478       */
479      public void testPeekLast() {
480          ConcurrentLinkedDeque q = populatedDeque(SIZE);
481 <        for (int i = SIZE-1; i >= 0; --i) {
481 >        for (int i = SIZE - 1; i >= 0; --i) {
482              assertEquals(i, q.peekLast());
483              assertEquals(i, q.pollLast());
484              assertTrue(q.peekLast() == null ||
# Line 501 | Line 507 | public class ConcurrentLinkedDequeTest e
507       */
508      public void testLastElement() {
509          ConcurrentLinkedDeque q = populatedDeque(SIZE);
510 <        for (int i = SIZE-1; i >= 0; --i) {
510 >        for (int i = SIZE - 1; i >= 0; --i) {
511              assertEquals(i, q.getLast());
512              assertEquals(i, q.pollLast());
513          }
# Line 552 | Line 558 | public class ConcurrentLinkedDequeTest e
558          }
559          for (int i = 0; i < SIZE; i += 2) {
560              assertTrue(q.removeFirstOccurrence(new Integer(i)));
561 <            assertFalse(q.removeFirstOccurrence(new Integer(i+1)));
561 >            assertFalse(q.removeFirstOccurrence(new Integer(i + 1)));
562          }
563          assertTrue(q.isEmpty());
564      }
# Line 567 | Line 573 | public class ConcurrentLinkedDequeTest e
573          }
574          for (int i = 0; i < SIZE; i += 2) {
575              assertTrue(q.removeLastOccurrence(new Integer(i)));
576 <            assertFalse(q.removeLastOccurrence(new Integer(i+1)));
576 >            assertFalse(q.removeLastOccurrence(new Integer(i + 1)));
577          }
578          assertTrue(q.isEmpty());
579      }
# Line 626 | Line 632 | public class ConcurrentLinkedDequeTest e
632                  assertTrue(changed);
633  
634              assertTrue(q.containsAll(p));
635 <            assertEquals(SIZE-i, q.size());
635 >            assertEquals(SIZE - i, q.size());
636              p.remove();
637          }
638      }
# Line 639 | Line 645 | public class ConcurrentLinkedDequeTest e
645              ConcurrentLinkedDeque q = populatedDeque(SIZE);
646              ConcurrentLinkedDeque p = populatedDeque(i);
647              assertTrue(q.removeAll(p));
648 <            assertEquals(SIZE-i, q.size());
648 >            assertEquals(SIZE - i, q.size());
649              for (int j = 0; j < i; ++j) {
650 <                Integer I = (Integer)(p.remove());
651 <                assertFalse(q.contains(I));
650 >                Integer x = (Integer)(p.remove());
651 >                assertFalse(q.contains(x));
652              }
653          }
654      }
# Line 696 | Line 702 | public class ConcurrentLinkedDequeTest e
702       */
703      public void testIterator() {
704          ConcurrentLinkedDeque q = populatedDeque(SIZE);
699        int i = 0;
705          Iterator it = q.iterator();
706 <        while (it.hasNext()) {
706 >        int i;
707 >        for (i = 0; it.hasNext(); i++)
708              assertTrue(q.contains(it.next()));
703            ++i;
704        }
709          assertEquals(i, SIZE);
710 +        assertIteratorExhausted(it);
711 +    }
712 +
713 +    /**
714 +     * iterator of empty collection has no elements
715 +     */
716 +    public void testEmptyIterator() {
717 +        Deque c = new ConcurrentLinkedDeque();
718 +        assertIteratorExhausted(c.iterator());
719 +        assertIteratorExhausted(c.descendingIterator());
720      }
721  
722      /**
# Line 747 | Line 761 | public class ConcurrentLinkedDequeTest e
761          final Random rng = new Random();
762          for (int iters = 0; iters < 100; ++iters) {
763              int max = rng.nextInt(5) + 2;
764 <            int split = rng.nextInt(max-1) + 1;
764 >            int split = rng.nextInt(max - 1) + 1;
765              for (int j = 1; j <= max; ++j)
766                  q.add(new Integer(j));
767              Iterator it = q.iterator();
768              for (int j = 1; j <= split; ++j)
769                  assertEquals(it.next(), new Integer(j));
770              it.remove();
771 <            assertEquals(it.next(), new Integer(split+1));
771 >            assertEquals(it.next(), new Integer(split + 1));
772              for (int j = 1; j <= split; ++j)
773                  q.remove(new Integer(j));
774              it = q.iterator();
775 <            for (int j = split+1; j <= max; ++j) {
775 >            for (int j = split + 1; j <= max; ++j) {
776                  assertEquals(it.next(), new Integer(j));
777                  it.remove();
778              }
# Line 815 | Line 829 | public class ConcurrentLinkedDequeTest e
829          final Random rng = new Random();
830          for (int iters = 0; iters < 100; ++iters) {
831              int max = rng.nextInt(5) + 2;
832 <            int split = rng.nextInt(max-1) + 1;
832 >            int split = rng.nextInt(max - 1) + 1;
833              for (int j = max; j >= 1; --j)
834                  q.add(new Integer(j));
835              Iterator it = q.descendingIterator();
836              for (int j = 1; j <= split; ++j)
837                  assertEquals(it.next(), new Integer(j));
838              it.remove();
839 <            assertEquals(it.next(), new Integer(split+1));
839 >            assertEquals(it.next(), new Integer(split + 1));
840              for (int j = 1; j <= split; ++j)
841                  q.remove(new Integer(j));
842              it = q.descendingIterator();
843 <            for (int j = split+1; j <= max; ++j) {
843 >            for (int j = split + 1; j <= max; ++j) {
844                  assertEquals(it.next(), new Integer(j));
845                  it.remove();
846              }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines