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

Comparing jsr166/src/test/tck/PriorityQueueTest.java (file contents):
Revision 1.35 by jsr166, Sat May 23 00:53:08 2015 UTC vs.
Revision 1.44 by jsr166, Fri Aug 4 03:30:21 2017 UTC

# Line 15 | Line 15 | import java.util.PriorityQueue;
15   import java.util.Queue;
16  
17   import junit.framework.Test;
18 import junit.framework.TestSuite;
18  
19   public class PriorityQueueTest extends JSR166TestCase {
20      public static void main(String[] args) {
21          main(suite(), args);
22      }
23      public static Test suite() {
24 <        return new TestSuite(PriorityQueueTest.class);
24 >        class Implementation implements CollectionImplementation {
25 >            public Class<?> klazz() { return PriorityQueue.class; }
26 >            public Collection emptyCollection() { return new PriorityQueue(); }
27 >            public Object makeElement(int i) { return i; }
28 >            public boolean isConcurrent() { return false; }
29 >            public boolean permitsNulls() { return false; }
30 >        }
31 >        return newTestSuite(PriorityQueueTest.class,
32 >                            CollectionTest.testSuite(new Implementation()));
33      }
34  
35      static class MyReverseComparator implements Comparator {
# Line 33 | Line 40 | public class PriorityQueueTest extends J
40  
41      /**
42       * Returns a new queue of given size containing consecutive
43 <     * Integers 0 ... n.
43 >     * Integers 0 ... n - 1.
44       */
45 <    private PriorityQueue<Integer> populatedQueue(int n) {
46 <        PriorityQueue<Integer> q = new PriorityQueue<Integer>(n);
45 >    private static PriorityQueue<Integer> populatedQueue(int n) {
46 >        PriorityQueue<Integer> q = new PriorityQueue<>(n);
47          assertTrue(q.isEmpty());
48 <        for (int i = n-1; i >= 0; i -= 2)
48 >        for (int i = n - 1; i >= 0; i -= 2)
49              assertTrue(q.offer(new Integer(i)));
50          for (int i = (n & 1); i < n; i += 2)
51              assertTrue(q.offer(new Integer(i)));
52          assertFalse(q.isEmpty());
53          assertEquals(n, q.size());
54 +        assertEquals((Integer) 0, q.peek());
55          return q;
56      }
57  
# Line 55 | Line 63 | public class PriorityQueueTest extends J
63      }
64  
65      /**
66 <     * Constructor throws IAE if capacity argument nonpositive
66 >     * Constructor throws IllegalArgumentException if capacity argument nonpositive
67       */
68      public void testConstructor2() {
69          try {
# Line 191 | Line 199 | public class PriorityQueueTest extends J
199          PriorityQueue q = new PriorityQueue(1);
200          try {
201              q.offer(new Object());
194            q.offer(new Object());
202              shouldThrow();
203 <        } catch (ClassCastException success) {}
203 >        } catch (ClassCastException success) {
204 >            assertTrue(q.isEmpty());
205 >            assertEquals(0, q.size());
206 >            assertNull(q.poll());
207 >        }
208      }
209  
210      /**
# Line 322 | Line 333 | public class PriorityQueueTest extends J
333              assertTrue(q.contains(i));
334              assertTrue(q.remove(i));
335              assertFalse(q.contains(i));
336 <            assertTrue(q.contains(i-1));
336 >            assertTrue(q.contains(i - 1));
337          }
338          for (int i = 0; i < SIZE; i += 2) {
339              assertTrue(q.contains(i));
340              assertTrue(q.remove(i));
341              assertFalse(q.contains(i));
342 <            assertFalse(q.remove(i+1));
343 <            assertFalse(q.contains(i+1));
342 >            assertFalse(q.remove(i + 1));
343 >            assertFalse(q.contains(i + 1));
344          }
345          assertTrue(q.isEmpty());
346      }
# Line 484 | Line 495 | public class PriorityQueueTest extends J
495      }
496  
497      /**
498 <     * A deserialized serialized queue has same elements
498 >     * A deserialized/reserialized queue has same elements
499       */
500      public void testSerialization() throws Exception {
501          Queue x = populatedQueue(SIZE);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines