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.5 by dl, Sat Sep 20 18:20:08 2003 UTC vs.
Revision 1.7 by dl, Sun Oct 5 23:00:40 2003 UTC

# Line 11 | Line 11 | import java.util.concurrent.*;
11   import java.io.*;
12  
13   public class PriorityQueueTest extends JSR166TestCase {
14
14      public static void main(String[] args) {
15          junit.textui.TestRunner.run (suite());  
16      }
18
17      public static Test suite() {
18          return new TestSuite(PriorityQueueTest.class);
19      }
# Line 30 | Line 28 | public class PriorityQueueTest extends J
28          }
29      }
30  
33
31      /**
32       * Create a queue of given size containing consecutive
33       * Integers 0 ... n.
# Line 48 | Line 45 | public class PriorityQueueTest extends J
45      }
46  
47      /**
48 <     *
48 >     * A new queue has unbounded capacity
49       */
50      public void testConstructor1() {
51          assertEquals(0, new PriorityQueue(SIZE).size());
52      }
53  
54      /**
55 <     *
55 >     * Constructor throws IAE if  capacity argument nonpositive
56       */
57      public void testConstructor2() {
58          try {
# Line 66 | Line 63 | public class PriorityQueueTest extends J
63      }
64  
65      /**
66 <     *
66 >     * Initializing from null Collection throws NPE
67       */
68      public void testConstructor3() {
72
69          try {
70              PriorityQueue q = new PriorityQueue((Collection)null);
71              shouldThrow();
# Line 78 | Line 74 | public class PriorityQueueTest extends J
74      }
75  
76      /**
77 <     *
77 >     * Initializing from Collection of null elements throws NPE
78       */
79      public void testConstructor4() {
80          try {
# Line 90 | Line 86 | public class PriorityQueueTest extends J
86      }
87  
88      /**
89 <     *
89 >     * Initializing from Collection with some null elements throws NPE
90       */
91      public void testConstructor5() {
92          try {
# Line 104 | Line 100 | public class PriorityQueueTest extends J
100      }
101  
102      /**
103 <     *
103 >     * Queue contains all elements of collection used to initialize
104       */
105      public void testConstructor6() {
106          try {
# Line 119 | Line 115 | public class PriorityQueueTest extends J
115      }
116  
117      /**
118 <     *
118 >     * The comparator used in constructor is used
119       */
120      public void testConstructor7() {
121          try {
# Line 137 | Line 133 | public class PriorityQueueTest extends J
133      }
134  
135      /**
136 <     *
136 >     * isEmpty is true before add, false after
137       */
138      public void testEmpty() {
139          PriorityQueue q = new PriorityQueue(2);
# Line 151 | Line 147 | public class PriorityQueueTest extends J
147      }
148  
149      /**
150 <     *
150 >     * size changes when elements added and removed
151       */
152      public void testSize() {
153          PriorityQueue q = populatedQueue(SIZE);
# Line 166 | Line 162 | public class PriorityQueueTest extends J
162      }
163  
164      /**
165 <     *
165 >     * offer(null) throws NPE
166       */
167      public void testOfferNull() {
168          try {
# Line 177 | Line 173 | public class PriorityQueueTest extends J
173      }
174  
175      /**
176 <     *
176 >     * add(null) throws NPE
177 >     */
178 >    public void testAddNull() {
179 >        try {
180 >            PriorityQueue q = new PriorityQueue(1);
181 >            q.add(null);
182 >            shouldThrow();
183 >        } catch (NullPointerException success) { }  
184 >    }
185 >
186 >    /**
187 >     * Offer of comparable element succeeds
188       */
189      public void testOffer() {
190          PriorityQueue q = new PriorityQueue(1);
191 <        assertTrue(q.offer(new Integer(0)));
192 <        assertTrue(q.offer(new Integer(1)));
191 >        assertTrue(q.offer(zero));
192 >        assertTrue(q.offer(one));
193      }
194  
195      /**
196 <     *
196 >     * Offer of non-Comparable throws CCE
197       */
198      public void testOfferNonComparable() {
199          try {
# Line 200 | Line 207 | public class PriorityQueueTest extends J
207      }
208  
209      /**
210 <     *
210 >     * add of comparable succeeds
211       */
212      public void testAdd() {
213          PriorityQueue q = new PriorityQueue(SIZE);
# Line 211 | Line 218 | public class PriorityQueueTest extends J
218      }
219  
220      /**
221 <     *
221 >     * addAll(null) throws NPE
222       */
223      public void testAddAll1() {
224          try {
# Line 222 | Line 229 | public class PriorityQueueTest extends J
229          catch (NullPointerException success) {}
230      }
231      /**
232 <     *
232 >     * addAll of a collection with null elements throws NPE
233       */
234      public void testAddAll2() {
235          try {
# Line 234 | Line 241 | public class PriorityQueueTest extends J
241          catch (NullPointerException success) {}
242      }
243      /**
244 <     *
244 >     * addAll of a collection with any null elements throws NPE after
245 >     * possibly adding some elements
246       */
247      public void testAddAll3() {
248          try {
# Line 249 | Line 257 | public class PriorityQueueTest extends J
257      }
258  
259      /**
260 <     *
260 >     * Queue contains all elements of successful addAll
261       */
262      public void testAddAll5() {
263          try {
# Line 267 | Line 275 | public class PriorityQueueTest extends J
275      }
276  
277      /**
278 <     *
278 >     * poll succeeds unless empty
279       */
280      public void testPoll() {
281          PriorityQueue q = populatedQueue(SIZE);
# Line 278 | Line 286 | public class PriorityQueueTest extends J
286      }
287  
288      /**
289 <     *
289 >     * peek returns next element, or null if empty
290       */
291      public void testPeek() {
292          PriorityQueue q = populatedQueue(SIZE);
# Line 292 | Line 300 | public class PriorityQueueTest extends J
300      }
301  
302      /**
303 <     *
303 >     * element returns next element, or throws NSEE if empty
304       */
305      public void testElement() {
306          PriorityQueue q = populatedQueue(SIZE);
# Line 308 | Line 316 | public class PriorityQueueTest extends J
316      }
317  
318      /**
319 <     *
319 >     * remove removes next element, or throws NSEE if empty
320       */
321      public void testRemove() {
322          PriorityQueue q = populatedQueue(SIZE);
# Line 323 | Line 331 | public class PriorityQueueTest extends J
331      }
332  
333      /**
334 <     *
334 >     * remove(x) removes x and returns true if present
335       */
336      public void testRemoveElement() {
337          PriorityQueue q = populatedQueue(SIZE);
# Line 338 | Line 346 | public class PriorityQueueTest extends J
346      }
347          
348      /**
349 <     *
349 >     * contains(x) reports true when elements added but not yet removed
350       */
351      public void testContains() {
352          PriorityQueue q = populatedQueue(SIZE);
# Line 350 | Line 358 | public class PriorityQueueTest extends J
358      }
359  
360      /**
361 <     *
361 >     * clear removes all elements
362       */
363      public void testClear() {
364          PriorityQueue q = populatedQueue(SIZE);
# Line 364 | Line 372 | public class PriorityQueueTest extends J
372      }
373  
374      /**
375 <     *
375 >     * containsAll(c) is true when c contains a subset of elements
376       */
377      public void testContainsAll() {
378          PriorityQueue q = populatedQueue(SIZE);
# Line 378 | Line 386 | public class PriorityQueueTest extends J
386      }
387  
388      /**
389 <     *
389 >     * retainAll(c) retains only those elements of c and reports true if changed
390       */
391      public void testRetainAll() {
392          PriorityQueue q = populatedQueue(SIZE);
# Line 397 | Line 405 | public class PriorityQueueTest extends J
405      }
406  
407      /**
408 <     *
408 >     * removeAll(c) removes only those elements of c and reports true if changed
409       */
410      public void testRemoveAll() {
411          for (int i = 1; i < SIZE; ++i) {
# Line 413 | Line 421 | public class PriorityQueueTest extends J
421      }
422  
423      /**
424 <     *
424 >     * toArray contains all elements
425       */
426      public void testToArray() {
427          PriorityQueue q = populatedQueue(SIZE);
# Line 424 | Line 432 | public class PriorityQueueTest extends J
432      }
433  
434      /**
435 <     *
435 >     * toArray(a) contains all elements
436       */
437      public void testToArray2() {
438          PriorityQueue q = populatedQueue(SIZE);
# Line 436 | Line 444 | public class PriorityQueueTest extends J
444      }
445      
446      /**
447 <     *
447 >     * iterator iterates through all elements
448       */
449      public void testIterator() {
450          PriorityQueue q = populatedQueue(SIZE);
# Line 450 | Line 458 | public class PriorityQueueTest extends J
458      }
459  
460      /**
461 <     *
461 >     * iterator.remove removes current element
462       */
463      public void testIteratorRemove () {
464          final PriorityQueue q = new PriorityQueue(3);
# Line 470 | Line 478 | public class PriorityQueueTest extends J
478  
479  
480      /**
481 <     *
481 >     * toString contains toStrings of elements
482       */
483      public void testToString() {
484          PriorityQueue q = populatedQueue(SIZE);
# Line 481 | Line 489 | public class PriorityQueueTest extends J
489      }        
490  
491      /**
492 <     *
492 >     * A deserialized serialized queue has same elements
493       */
494      public void testSerialization() {
495          PriorityQueue q = populatedQueue(SIZE);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines