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

Comparing jsr166/src/test/tck/LinkedBlockingDequeTest.java (file contents):
Revision 1.51 by jsr166, Wed Dec 31 19:05:42 2014 UTC vs.
Revision 1.57 by jsr166, Sat Apr 25 04:55:31 2015 UTC

# Line 37 | Line 37 | public class LinkedBlockingDequeTest ext
37      }
38  
39      public static void main(String[] args) {
40 <        junit.textui.TestRunner.run(suite());
40 >        main(suite(), args);
41      }
42  
43      public static Test suite() {
# Line 276 | Line 276 | public class LinkedBlockingDequeTest ext
276       */
277      public void testRemoveFirstOccurrence() {
278          LinkedBlockingDeque q = populatedDeque(SIZE);
279 <        for (int i = 1; i < SIZE; i+=2) {
279 >        for (int i = 1; i < SIZE; i += 2) {
280              assertTrue(q.removeFirstOccurrence(new Integer(i)));
281          }
282 <        for (int i = 0; i < SIZE; i+=2) {
282 >        for (int i = 0; i < SIZE; i += 2) {
283              assertTrue(q.removeFirstOccurrence(new Integer(i)));
284              assertFalse(q.removeFirstOccurrence(new Integer(i+1)));
285          }
# Line 291 | Line 291 | public class LinkedBlockingDequeTest ext
291       */
292      public void testRemoveLastOccurrence() {
293          LinkedBlockingDeque q = populatedDeque(SIZE);
294 <        for (int i = 1; i < SIZE; i+=2) {
294 >        for (int i = 1; i < SIZE; i += 2) {
295              assertTrue(q.removeLastOccurrence(new Integer(i)));
296          }
297 <        for (int i = 0; i < SIZE; i+=2) {
297 >        for (int i = 0; i < SIZE; i += 2) {
298              assertTrue(q.removeLastOccurrence(new Integer(i)));
299              assertFalse(q.removeLastOccurrence(new Integer(i+1)));
300          }
# Line 407 | Line 407 | public class LinkedBlockingDequeTest ext
407       * remainingCapacity decreases on add, increases on remove
408       */
409      public void testRemainingCapacity() {
410 <        LinkedBlockingDeque q = populatedDeque(SIZE);
410 >        BlockingQueue q = populatedDeque(SIZE);
411          for (int i = 0; i < SIZE; ++i) {
412              assertEquals(i, q.remainingCapacity());
413 <            assertEquals(SIZE-i, q.size());
414 <            q.remove();
413 >            assertEquals(SIZE, q.size() + q.remainingCapacity());
414 >            assertEquals(i, q.remove());
415          }
416          for (int i = 0; i < SIZE; ++i) {
417              assertEquals(SIZE-i, q.remainingCapacity());
418 <            assertEquals(i, q.size());
419 <            q.add(new Integer(i));
418 >            assertEquals(SIZE, q.size() + q.remainingCapacity());
419 >            assertTrue(q.add(i));
420          }
421      }
422  
# Line 438 | Line 438 | public class LinkedBlockingDequeTest ext
438          try {
439              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
440              for (int i = 0; i < SIZE; ++i) {
441 <                Integer I = new Integer(i);
442 <                q.push(I);
443 <                assertEquals(I, q.peek());
441 >                Integer x = new Integer(i);
442 >                q.push(x);
443 >                assertEquals(x, q.peek());
444              }
445              assertEquals(0, q.remainingCapacity());
446              q.push(new Integer(SIZE));
# Line 558 | Line 558 | public class LinkedBlockingDequeTest ext
558      public void testPut() throws InterruptedException {
559          LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
560          for (int i = 0; i < SIZE; ++i) {
561 <            Integer I = new Integer(i);
562 <            q.put(I);
563 <            assertTrue(q.contains(I));
561 >            Integer x = new Integer(i);
562 >            q.put(x);
563 >            assertTrue(q.contains(x));
564          }
565          assertEquals(0, q.remainingCapacity());
566      }
# Line 790 | Line 790 | public class LinkedBlockingDequeTest ext
790      public void testPutFirst() throws InterruptedException {
791          LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
792          for (int i = 0; i < SIZE; ++i) {
793 <            Integer I = new Integer(i);
794 <            q.putFirst(I);
795 <            assertTrue(q.contains(I));
793 >            Integer x = new Integer(i);
794 >            q.putFirst(x);
795 >            assertTrue(q.contains(x));
796          }
797          assertEquals(0, q.remainingCapacity());
798      }
# Line 1137 | Line 1137 | public class LinkedBlockingDequeTest ext
1137      public void testPutLast() throws InterruptedException {
1138          LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
1139          for (int i = 0; i < SIZE; ++i) {
1140 <            Integer I = new Integer(i);
1141 <            q.putLast(I);
1142 <            assertTrue(q.contains(I));
1140 >            Integer x = new Integer(i);
1141 >            q.putLast(x);
1142 >            assertTrue(q.contains(x));
1143          }
1144          assertEquals(0, q.remainingCapacity());
1145      }
# Line 1473 | Line 1473 | public class LinkedBlockingDequeTest ext
1473              assertTrue(q.removeAll(p));
1474              assertEquals(SIZE-i, q.size());
1475              for (int j = 0; j < i; ++j) {
1476 <                Integer I = (Integer)(p.remove());
1477 <                assertFalse(q.contains(I));
1476 >                Integer x = (Integer)(p.remove());
1477 >                assertFalse(q.contains(x));
1478              }
1479          }
1480      }
# Line 1518 | Line 1518 | public class LinkedBlockingDequeTest ext
1518      public void testIterator() throws InterruptedException {
1519          LinkedBlockingDeque q = populatedDeque(SIZE);
1520          Iterator it = q.iterator();
1521 <        while (it.hasNext()) {
1521 >        int i;
1522 >        for (i = 0; it.hasNext(); i++)
1523 >            assertTrue(q.contains(it.next()));
1524 >        assertEquals(i, SIZE);
1525 >        assertIteratorExhausted(it);
1526 >
1527 >        it = q.iterator();
1528 >        for (i = 0; it.hasNext(); i++)
1529              assertEquals(it.next(), q.take());
1530 <        }
1530 >        assertEquals(i, SIZE);
1531 >        assertIteratorExhausted(it);
1532 >    }
1533 >
1534 >    /**
1535 >     * iterator of empty collection has no elements
1536 >     */
1537 >    public void testEmptyIterator() {
1538 >        Deque c = new LinkedBlockingDeque();
1539 >        assertIteratorExhausted(c.iterator());
1540 >        assertIteratorExhausted(c.descendingIterator());
1541      }
1542  
1543      /**
# Line 1773 | Line 1790 | public class LinkedBlockingDequeTest ext
1790              assertEquals(SIZE-k, q.size());
1791              for (int j = 0; j < k; ++j)
1792                  assertEquals(l.get(j), new Integer(j));
1793 <            while (q.poll() != null) ;
1793 >            do {} while (q.poll() != null);
1794          }
1795      }
1796  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines