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

Comparing jsr166/src/test/tck/LinkedListTest.java (file contents):
Revision 1.34 by jsr166, Wed Dec 31 20:17:39 2014 UTC vs.
Revision 1.42 by jsr166, Mon Oct 17 00:56:11 2016 UTC

# Line 17 | Line 17 | import junit.framework.TestSuite;
17  
18   public class LinkedListTest extends JSR166TestCase {
19      public static void main(String[] args) {
20 <        junit.textui.TestRunner.run(suite());
20 >        main(suite(), args);
21      }
22  
23      public static Test suite() {
24 <        return new TestSuite(LinkedListTest.class);
24 >        class Implementation implements CollectionImplementation {
25 >            public Class<?> klazz() { return LinkedList.class; }
26 >            public Collection emptyCollection() { return new LinkedList(); }
27 >            public Object makeElement(int i) { return i; }
28 >            public boolean isConcurrent() { return false; }
29 >            public boolean permitsNulls() { return true; }
30 >        }
31 >        return newTestSuite(LinkedListTest.class,
32 >                            CollectionTest.testSuite(new Implementation()));
33      }
34  
35      /**
36       * Returns a new queue of given size containing consecutive
37 <     * Integers 0 ... n.
37 >     * Integers 0 ... n - 1.
38       */
39      private LinkedList<Integer> populatedQueue(int n) {
40          LinkedList<Integer> q = new LinkedList<Integer>();
# Line 35 | Line 43 | public class LinkedListTest extends JSR1
43              assertTrue(q.offer(new Integer(i)));
44          assertFalse(q.isEmpty());
45          assertEquals(n, q.size());
46 +        assertEquals((Integer) 0, q.peekFirst());
47 +        assertEquals((Integer) (n - 1), q.peekLast());
48          return q;
49      }
50  
# Line 50 | Line 60 | public class LinkedListTest extends JSR1
60       */
61      public void testConstructor3() {
62          try {
63 <            LinkedList q = new LinkedList((Collection)null);
63 >            new LinkedList((Collection)null);
64              shouldThrow();
65          } catch (NullPointerException success) {}
66      }
# Line 87 | Line 97 | public class LinkedListTest extends JSR1
97      public void testSize() {
98          LinkedList q = populatedQueue(SIZE);
99          for (int i = 0; i < SIZE; ++i) {
100 <            assertEquals(SIZE-i, q.size());
100 >            assertEquals(SIZE - i, q.size());
101              q.remove();
102          }
103          for (int i = 0; i < SIZE; ++i) {
# Line 102 | Line 112 | public class LinkedListTest extends JSR1
112      public void testOfferNull() {
113          LinkedList q = new LinkedList();
114          q.offer(null);
115 +        assertNull(q.get(0));
116 +        assertTrue(q.contains(null));
117      }
118  
119      /**
# Line 128 | Line 140 | public class LinkedListTest extends JSR1
140       * addAll(null) throws NPE
141       */
142      public void testAddAll1() {
143 +        LinkedList q = new LinkedList();
144          try {
132            LinkedList q = new LinkedList();
145              q.addAll(null);
146              shouldThrow();
147          } catch (NullPointerException success) {}
# Line 241 | Line 253 | public class LinkedListTest extends JSR1
253              assertTrue(q.contains(i));
254              assertTrue(q.remove((Integer)i));
255              assertFalse(q.contains(i));
256 <            assertTrue(q.contains(i-1));
256 >            assertTrue(q.contains(i - 1));
257          }
258          for (int i = 0; i < SIZE; i += 2) {
259              assertTrue(q.contains(i));
260              assertTrue(q.remove((Integer)i));
261              assertFalse(q.contains(i));
262 <            assertFalse(q.remove((Integer)(i+1)));
263 <            assertFalse(q.contains(i+1));
262 >            assertFalse(q.remove((Integer)(i + 1)));
263 >            assertFalse(q.contains(i + 1));
264          }
265          assertTrue(q.isEmpty());
266      }
# Line 307 | Line 319 | public class LinkedListTest extends JSR1
319                  assertTrue(changed);
320  
321              assertTrue(q.containsAll(p));
322 <            assertEquals(SIZE-i, q.size());
322 >            assertEquals(SIZE - i, q.size());
323              p.remove();
324          }
325      }
# Line 320 | Line 332 | public class LinkedListTest extends JSR1
332              LinkedList q = populatedQueue(SIZE);
333              LinkedList p = populatedQueue(i);
334              assertTrue(q.removeAll(p));
335 <            assertEquals(SIZE-i, q.size());
335 >            assertEquals(SIZE - i, q.size());
336              for (int j = 0; j < i; ++j) {
337                  Integer x = (Integer)(p.remove());
338                  assertFalse(q.contains(x));
# Line 379 | Line 391 | public class LinkedListTest extends JSR1
391       */
392      public void testIterator() {
393          LinkedList q = populatedQueue(SIZE);
382        int i = 0;
394          Iterator it = q.iterator();
395 <        while (it.hasNext()) {
395 >        int i;
396 >        for (i = 0; it.hasNext(); i++)
397              assertTrue(q.contains(it.next()));
386            ++i;
387        }
398          assertEquals(i, SIZE);
399 +        assertIteratorExhausted(it);
400 +    }
401 +
402 +    /**
403 +     * iterator of empty collection has no elements
404 +     */
405 +    public void testEmptyIterator() {
406 +        assertIteratorExhausted(new LinkedList().iterator());
407      }
408  
409      /**
# Line 539 | Line 557 | public class LinkedListTest extends JSR1
557       */
558      public void testPollLast() {
559          LinkedList q = populatedQueue(SIZE);
560 <        for (int i = SIZE-1; i >= 0; --i) {
560 >        for (int i = SIZE - 1; i >= 0; --i) {
561              assertEquals(i, q.pollLast());
562          }
563          assertNull(q.pollLast());
# Line 564 | Line 582 | public class LinkedListTest extends JSR1
582       */
583      public void testPeekLast() {
584          LinkedList q = populatedQueue(SIZE);
585 <        for (int i = SIZE-1; i >= 0; --i) {
585 >        for (int i = SIZE - 1; i >= 0; --i) {
586              assertEquals(i, q.peekLast());
587              assertEquals(i, q.pollLast());
588              assertTrue(q.peekLast() == null ||
# Line 590 | Line 608 | public class LinkedListTest extends JSR1
608       */
609      public void testLastElement() {
610          LinkedList q = populatedQueue(SIZE);
611 <        for (int i = SIZE-1; i >= 0; --i) {
611 >        for (int i = SIZE - 1; i >= 0; --i) {
612              assertEquals(i, q.getLast());
613              assertEquals(i, q.pollLast());
614          }
# Line 611 | Line 629 | public class LinkedListTest extends JSR1
629          }
630          for (int i = 0; i < SIZE; i += 2) {
631              assertTrue(q.removeFirstOccurrence(new Integer(i)));
632 <            assertFalse(q.removeFirstOccurrence(new Integer(i+1)));
632 >            assertFalse(q.removeFirstOccurrence(new Integer(i + 1)));
633          }
634          assertTrue(q.isEmpty());
635      }
# Line 626 | Line 644 | public class LinkedListTest extends JSR1
644          }
645          for (int i = 0; i < SIZE; i += 2) {
646              assertTrue(q.removeLastOccurrence(new Integer(i)));
647 <            assertFalse(q.removeLastOccurrence(new Integer(i+1)));
647 >            assertFalse(q.removeLastOccurrence(new Integer(i + 1)));
648          }
649          assertTrue(q.isEmpty());
650      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines