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.34 by jsr166, Fri May 15 18:21:19 2015 UTC vs.
Revision 1.38 by jsr166, Sun Oct 16 20:44:18 2016 UTC

# Line 33 | Line 33 | public class PriorityQueueTest extends J
33  
34      /**
35       * Returns a new queue of given size containing consecutive
36 <     * Integers 0 ... n.
36 >     * Integers 0 ... n - 1.
37       */
38      private PriorityQueue<Integer> populatedQueue(int n) {
39          PriorityQueue<Integer> q = new PriorityQueue<Integer>(n);
40          assertTrue(q.isEmpty());
41 <        for (int i = n-1; i >= 0; i -= 2)
41 >        for (int i = n - 1; i >= 0; i -= 2)
42              assertTrue(q.offer(new Integer(i)));
43          for (int i = (n & 1); i < n; i += 2)
44              assertTrue(q.offer(new Integer(i)));
45          assertFalse(q.isEmpty());
46          assertEquals(n, q.size());
47 +        assertEquals((Integer) 0, q.peek());
48          return q;
49      }
50  
# Line 89 | Line 90 | public class PriorityQueueTest extends J
90       */
91      public void testConstructor5() {
92          Integer[] ints = new Integer[SIZE];
93 <        for (int i = 0; i < SIZE-1; ++i)
93 >        for (int i = 0; i < SIZE - 1; ++i)
94              ints[i] = new Integer(i);
95          try {
96              new PriorityQueue(Arrays.asList(ints));
# Line 120 | Line 121 | public class PriorityQueueTest extends J
121          for (int i = 0; i < SIZE; ++i)
122              ints[i] = new Integer(i);
123          q.addAll(Arrays.asList(ints));
124 <        for (int i = SIZE-1; i >= 0; --i)
124 >        for (int i = SIZE - 1; i >= 0; --i)
125              assertEquals(ints[i], q.poll());
126      }
127  
# Line 144 | Line 145 | public class PriorityQueueTest extends J
145      public void testSize() {
146          PriorityQueue q = populatedQueue(SIZE);
147          for (int i = 0; i < SIZE; ++i) {
148 <            assertEquals(SIZE-i, q.size());
148 >            assertEquals(SIZE - i, q.size());
149              q.remove();
150          }
151          for (int i = 0; i < SIZE; ++i) {
# Line 191 | Line 192 | public class PriorityQueueTest extends J
192          PriorityQueue q = new PriorityQueue(1);
193          try {
194              q.offer(new Object());
194            q.offer(new Object());
195              shouldThrow();
196 <        } catch (ClassCastException success) {}
196 >        } catch (ClassCastException success) {
197 >            assertTrue(q.isEmpty());
198 >            assertEquals(0, q.size());
199 >            assertNull(q.poll());
200 >        }
201      }
202  
203      /**
# Line 236 | Line 240 | public class PriorityQueueTest extends J
240      public void testAddAll3() {
241          PriorityQueue q = new PriorityQueue(SIZE);
242          Integer[] ints = new Integer[SIZE];
243 <        for (int i = 0; i < SIZE-1; ++i)
243 >        for (int i = 0; i < SIZE - 1; ++i)
244              ints[i] = new Integer(i);
245          try {
246              q.addAll(Arrays.asList(ints));
# Line 251 | Line 255 | public class PriorityQueueTest extends J
255          Integer[] empty = new Integer[0];
256          Integer[] ints = new Integer[SIZE];
257          for (int i = 0; i < SIZE; ++i)
258 <            ints[i] = new Integer(SIZE-1-i);
258 >            ints[i] = new Integer(SIZE - 1 - i);
259          PriorityQueue q = new PriorityQueue(SIZE);
260          assertFalse(q.addAll(Arrays.asList(empty)));
261          assertTrue(q.addAll(Arrays.asList(ints)));
# Line 322 | Line 326 | public class PriorityQueueTest extends J
326              assertTrue(q.contains(i));
327              assertTrue(q.remove(i));
328              assertFalse(q.contains(i));
329 <            assertTrue(q.contains(i-1));
329 >            assertTrue(q.contains(i - 1));
330          }
331          for (int i = 0; i < SIZE; i += 2) {
332              assertTrue(q.contains(i));
333              assertTrue(q.remove(i));
334              assertFalse(q.contains(i));
335 <            assertFalse(q.remove(i+1));
336 <            assertFalse(q.contains(i+1));
335 >            assertFalse(q.remove(i + 1));
336 >            assertFalse(q.contains(i + 1));
337          }
338          assertTrue(q.isEmpty());
339      }
# Line 388 | Line 392 | public class PriorityQueueTest extends J
392                  assertTrue(changed);
393  
394              assertTrue(q.containsAll(p));
395 <            assertEquals(SIZE-i, q.size());
395 >            assertEquals(SIZE - i, q.size());
396              p.remove();
397          }
398      }
# Line 401 | Line 405 | public class PriorityQueueTest extends J
405              PriorityQueue q = populatedQueue(SIZE);
406              PriorityQueue p = populatedQueue(i);
407              assertTrue(q.removeAll(p));
408 <            assertEquals(SIZE-i, q.size());
408 >            assertEquals(SIZE - i, q.size());
409              for (int j = 0; j < i; ++j) {
410                  Integer x = (Integer)(p.remove());
411                  assertFalse(q.contains(x));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines