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.13 by jsr166, Sat Nov 21 10:25:05 2009 UTC vs.
Revision 1.16 by jsr166, Wed Aug 25 00:07:03 2010 UTC

# Line 13 | Line 13 | import java.io.*;
13  
14   public class PriorityQueueTest extends JSR166TestCase {
15      public static void main(String[] args) {
16 <        junit.textui.TestRunner.run (suite());
16 >        junit.textui.TestRunner.run(suite());
17      }
18      public static Test suite() {
19          return new TestSuite(PriorityQueueTest.class);
# Line 21 | Line 21 | public class PriorityQueueTest extends J
21  
22      static class MyReverseComparator implements Comparator {
23          public int compare(Object x, Object y) {
24 <            int i = ((Integer)x).intValue();
25 <            int j = ((Integer)y).intValue();
26 <            if (i < j) return 1;
27 <            if (i > j) return -1;
28 <            return 0;
24 >            return ((Comparable)y).compareTo(x);
25          }
26      }
27  
# Line 100 | Line 96 | public class PriorityQueueTest extends J
96       * Queue contains all elements of collection used to initialize
97       */
98      public void testConstructor6() {
99 <        try {
100 <            Integer[] ints = new Integer[SIZE];
101 <            for (int i = 0; i < SIZE; ++i)
102 <                ints[i] = new Integer(i);
103 <            PriorityQueue q = new PriorityQueue(Arrays.asList(ints));
104 <            for (int i = 0; i < SIZE; ++i)
109 <                assertEquals(ints[i], q.poll());
110 <        }
111 <        finally {}
99 >        Integer[] ints = new Integer[SIZE];
100 >        for (int i = 0; i < SIZE; ++i)
101 >            ints[i] = new Integer(i);
102 >        PriorityQueue q = new PriorityQueue(Arrays.asList(ints));
103 >        for (int i = 0; i < SIZE; ++i)
104 >            assertEquals(ints[i], q.poll());
105      }
106  
107      /**
108       * The comparator used in constructor is used
109       */
110      public void testConstructor7() {
111 <        try {
112 <            MyReverseComparator cmp = new MyReverseComparator();
113 <            PriorityQueue q = new PriorityQueue(SIZE, cmp);
114 <            assertEquals(cmp, q.comparator());
115 <            Integer[] ints = new Integer[SIZE];
116 <            for (int i = 0; i < SIZE; ++i)
117 <                ints[i] = new Integer(i);
118 <            q.addAll(Arrays.asList(ints));
119 <            for (int i = SIZE-1; i >= 0; --i)
127 <                assertEquals(ints[i], q.poll());
128 <        }
129 <        finally {}
111 >        MyReverseComparator cmp = new MyReverseComparator();
112 >        PriorityQueue q = new PriorityQueue(SIZE, cmp);
113 >        assertEquals(cmp, q.comparator());
114 >        Integer[] ints = new Integer[SIZE];
115 >        for (int i = 0; i < SIZE; ++i)
116 >            ints[i] = new Integer(i);
117 >        q.addAll(Arrays.asList(ints));
118 >        for (int i = SIZE-1; i >= 0; --i)
119 >            assertEquals(ints[i], q.poll());
120      }
121  
122      /**
# Line 253 | Line 243 | public class PriorityQueueTest extends J
243       * Queue contains all elements of successful addAll
244       */
245      public void testAddAll5() {
246 <        try {
247 <            Integer[] empty = new Integer[0];
248 <            Integer[] ints = new Integer[SIZE];
249 <            for (int i = 0; i < SIZE; ++i)
250 <                ints[i] = new Integer(SIZE-1-i);
251 <            PriorityQueue q = new PriorityQueue(SIZE);
252 <            assertFalse(q.addAll(Arrays.asList(empty)));
253 <            assertTrue(q.addAll(Arrays.asList(ints)));
254 <            for (int i = 0; i < SIZE; ++i)
265 <                assertEquals(new Integer(i), q.poll());
266 <        }
267 <        finally {}
246 >        Integer[] empty = new Integer[0];
247 >        Integer[] ints = new Integer[SIZE];
248 >        for (int i = 0; i < SIZE; ++i)
249 >            ints[i] = new Integer(SIZE-1-i);
250 >        PriorityQueue q = new PriorityQueue(SIZE);
251 >        assertFalse(q.addAll(Arrays.asList(empty)));
252 >        assertTrue(q.addAll(Arrays.asList(ints)));
253 >        for (int i = 0; i < SIZE; ++i)
254 >            assertEquals(new Integer(i), q.poll());
255      }
256  
257      /**
# Line 273 | Line 260 | public class PriorityQueueTest extends J
260      public void testPoll() {
261          PriorityQueue q = populatedQueue(SIZE);
262          for (int i = 0; i < SIZE; ++i) {
263 <            assertEquals(i, ((Integer)q.poll()).intValue());
263 >            assertEquals(i, q.poll());
264          }
265          assertNull(q.poll());
266      }
# Line 284 | Line 271 | public class PriorityQueueTest extends J
271      public void testPeek() {
272          PriorityQueue q = populatedQueue(SIZE);
273          for (int i = 0; i < SIZE; ++i) {
274 <            assertEquals(i, ((Integer)q.peek()).intValue());
275 <            q.poll();
274 >            assertEquals(i, q.peek());
275 >            assertEquals(i, q.poll());
276              assertTrue(q.peek() == null ||
277 <                       i != ((Integer)q.peek()).intValue());
277 >                       !q.peek().equals(i));
278          }
279          assertNull(q.peek());
280      }
# Line 298 | Line 285 | public class PriorityQueueTest extends J
285      public void testElement() {
286          PriorityQueue q = populatedQueue(SIZE);
287          for (int i = 0; i < SIZE; ++i) {
288 <            assertEquals(i, ((Integer)q.element()).intValue());
289 <            q.poll();
288 >            assertEquals(i, q.element());
289 >            assertEquals(i, q.poll());
290          }
291          try {
292              q.element();
# Line 313 | Line 300 | public class PriorityQueueTest extends J
300      public void testRemove() {
301          PriorityQueue q = populatedQueue(SIZE);
302          for (int i = 0; i < SIZE; ++i) {
303 <            assertEquals(i, ((Integer)q.remove()).intValue());
303 >            assertEquals(i, q.remove());
304          }
305          try {
306              q.remove();
# Line 451 | Line 438 | public class PriorityQueueTest extends J
438      /**
439       * iterator.remove removes current element
440       */
441 <    public void testIteratorRemove () {
441 >    public void testIteratorRemove() {
442          final PriorityQueue q = new PriorityQueue(3);
443          q.add(new Integer(2));
444          q.add(new Integer(1));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines