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.4 by dl, Sat Sep 20 00:31:57 2003 UTC vs.
Revision 1.5 by dl, Sat Sep 20 18:20:08 2003 UTC

# Line 47 | Line 47 | public class PriorityQueueTest extends J
47          return q;
48      }
49  
50 <    public void testConstructor1(){
50 >    /**
51 >     *
52 >     */
53 >    public void testConstructor1() {
54          assertEquals(0, new PriorityQueue(SIZE).size());
55      }
56  
57 <    public void testConstructor2(){
57 >    /**
58 >     *
59 >     */
60 >    public void testConstructor2() {
61          try {
62              PriorityQueue q = new PriorityQueue(0);
63 <            fail("Cannot make zero-sized");
63 >            shouldThrow();
64          }
65          catch (IllegalArgumentException success) {}
66      }
67  
68 +    /**
69 +     *
70 +     */
71      public void testConstructor3() {
72  
73          try {
74              PriorityQueue q = new PriorityQueue((Collection)null);
75 <            fail("Cannot make from null collection");
75 >            shouldThrow();
76          }
77          catch (NullPointerException success) {}
78      }
79  
80 <    public void testConstructor4(){
80 >    /**
81 >     *
82 >     */
83 >    public void testConstructor4() {
84          try {
85              Integer[] ints = new Integer[SIZE];
86              PriorityQueue q = new PriorityQueue(Arrays.asList(ints));
87 <            fail("Cannot make with null elements");
87 >            shouldThrow();
88          }
89          catch (NullPointerException success) {}
90      }
91  
92 <    public void testConstructor5(){
92 >    /**
93 >     *
94 >     */
95 >    public void testConstructor5() {
96          try {
97              Integer[] ints = new Integer[SIZE];
98              for (int i = 0; i < SIZE-1; ++i)
99                  ints[i] = new Integer(i);
100              PriorityQueue q = new PriorityQueue(Arrays.asList(ints));
101 <            fail("Cannot make with null elements");
101 >            shouldThrow();
102          }
103          catch (NullPointerException success) {}
104      }
105  
106 <    public void testConstructor6(){
106 >    /**
107 >     *
108 >     */
109 >    public void testConstructor6() {
110          try {
111              Integer[] ints = new Integer[SIZE];
112              for (int i = 0; i < SIZE; ++i)
# Line 100 | Line 118 | public class PriorityQueueTest extends J
118          finally {}
119      }
120  
121 <    public void testConstructor7(){
121 >    /**
122 >     *
123 >     */
124 >    public void testConstructor7() {
125          try {
126              MyReverseComparator cmp = new MyReverseComparator();
127              PriorityQueue q = new PriorityQueue(SIZE, cmp);
# Line 115 | Line 136 | public class PriorityQueueTest extends J
136          finally {}
137      }
138  
139 +    /**
140 +     *
141 +     */
142      public void testEmpty() {
143          PriorityQueue q = new PriorityQueue(2);
144          assertTrue(q.isEmpty());
# Line 126 | Line 150 | public class PriorityQueueTest extends J
150          assertTrue(q.isEmpty());
151      }
152  
153 +    /**
154 +     *
155 +     */
156      public void testSize() {
157          PriorityQueue q = populatedQueue(SIZE);
158          for (int i = 0; i < SIZE; ++i) {
# Line 138 | Line 165 | public class PriorityQueueTest extends J
165          }
166      }
167  
168 <    public void testOfferNull(){
168 >    /**
169 >     *
170 >     */
171 >    public void testOfferNull() {
172          try {
173              PriorityQueue q = new PriorityQueue(1);
174              q.offer(null);
175 <            fail("should throw NPE");
175 >            shouldThrow();
176          } catch (NullPointerException success) { }  
177      }
178  
179 +    /**
180 +     *
181 +     */
182      public void testOffer() {
183          PriorityQueue q = new PriorityQueue(1);
184          assertTrue(q.offer(new Integer(0)));
185          assertTrue(q.offer(new Integer(1)));
186      }
187  
188 +    /**
189 +     *
190 +     */
191      public void testOfferNonComparable() {
192          try {
193              PriorityQueue q = new PriorityQueue(1);
194              q.offer(new Object());
195              q.offer(new Object());
196              q.offer(new Object());
197 <            fail("should throw CCE");
197 >            shouldThrow();
198          }
199          catch(ClassCastException success) {}
200      }
201  
202 <    public void testAdd(){
202 >    /**
203 >     *
204 >     */
205 >    public void testAdd() {
206          PriorityQueue q = new PriorityQueue(SIZE);
207          for (int i = 0; i < SIZE; ++i) {
208              assertEquals(i, q.size());
# Line 171 | Line 210 | public class PriorityQueueTest extends J
210          }
211      }
212  
213 <    public void testAddAll1(){
213 >    /**
214 >     *
215 >     */
216 >    public void testAddAll1() {
217          try {
218              PriorityQueue q = new PriorityQueue(1);
219              q.addAll(null);
220 <            fail("Cannot add null collection");
220 >            shouldThrow();
221          }
222          catch (NullPointerException success) {}
223      }
224 <    public void testAddAll2(){
224 >    /**
225 >     *
226 >     */
227 >    public void testAddAll2() {
228          try {
229              PriorityQueue q = new PriorityQueue(SIZE);
230              Integer[] ints = new Integer[SIZE];
231              q.addAll(Arrays.asList(ints));
232 <            fail("Cannot add null elements");
232 >            shouldThrow();
233          }
234          catch (NullPointerException success) {}
235      }
236 <    public void testAddAll3(){
236 >    /**
237 >     *
238 >     */
239 >    public void testAddAll3() {
240          try {
241              PriorityQueue q = new PriorityQueue(SIZE);
242              Integer[] ints = new Integer[SIZE];
243              for (int i = 0; i < SIZE-1; ++i)
244                  ints[i] = new Integer(i);
245              q.addAll(Arrays.asList(ints));
246 <            fail("Cannot add null elements");
246 >            shouldThrow();
247          }
248          catch (NullPointerException success) {}
249      }
250  
251 <    public void testAddAll5(){
251 >    /**
252 >     *
253 >     */
254 >    public void testAddAll5() {
255          try {
256              Integer[] empty = new Integer[0];
257              Integer[] ints = new Integer[SIZE];
# Line 215 | Line 266 | public class PriorityQueueTest extends J
266          finally {}
267      }
268  
269 <    public void testPoll(){
269 >    /**
270 >     *
271 >     */
272 >    public void testPoll() {
273          PriorityQueue q = populatedQueue(SIZE);
274          for (int i = 0; i < SIZE; ++i) {
275              assertEquals(i, ((Integer)q.poll()).intValue());
# Line 223 | Line 277 | public class PriorityQueueTest extends J
277          assertNull(q.poll());
278      }
279  
280 <    public void testPeek(){
280 >    /**
281 >     *
282 >     */
283 >    public void testPeek() {
284          PriorityQueue q = populatedQueue(SIZE);
285          for (int i = 0; i < SIZE; ++i) {
286              assertEquals(i, ((Integer)q.peek()).intValue());
# Line 234 | Line 291 | public class PriorityQueueTest extends J
291          assertNull(q.peek());
292      }
293  
294 <    public void testElement(){
294 >    /**
295 >     *
296 >     */
297 >    public void testElement() {
298          PriorityQueue q = populatedQueue(SIZE);
299          for (int i = 0; i < SIZE; ++i) {
300              assertEquals(i, ((Integer)q.element()).intValue());
# Line 242 | Line 302 | public class PriorityQueueTest extends J
302          }
303          try {
304              q.element();
305 <            fail("no such element");
305 >            shouldThrow();
306          }
307          catch (NoSuchElementException success) {}
308      }
309  
310 <    public void testRemove(){
310 >    /**
311 >     *
312 >     */
313 >    public void testRemove() {
314          PriorityQueue q = populatedQueue(SIZE);
315          for (int i = 0; i < SIZE; ++i) {
316              assertEquals(i, ((Integer)q.remove()).intValue());
317          }
318          try {
319              q.remove();
320 <            fail("remove should throw");
320 >            shouldThrow();
321          } catch (NoSuchElementException success){
322          }  
323      }
324  
325 <    public void testRemoveElement(){
325 >    /**
326 >     *
327 >     */
328 >    public void testRemoveElement() {
329          PriorityQueue q = populatedQueue(SIZE);
330          for (int i = 1; i < SIZE; i+=2) {
331              assertTrue(q.remove(new Integer(i)));
# Line 271 | Line 337 | public class PriorityQueueTest extends J
337          assertTrue(q.isEmpty());
338      }
339          
340 <    public void testContains(){
340 >    /**
341 >     *
342 >     */
343 >    public void testContains() {
344          PriorityQueue q = populatedQueue(SIZE);
345          for (int i = 0; i < SIZE; ++i) {
346              assertTrue(q.contains(new Integer(i)));
# Line 280 | Line 349 | public class PriorityQueueTest extends J
349          }
350      }
351  
352 <    public void testClear(){
352 >    /**
353 >     *
354 >     */
355 >    public void testClear() {
356          PriorityQueue q = populatedQueue(SIZE);
357          q.clear();
358          assertTrue(q.isEmpty());
# Line 291 | Line 363 | public class PriorityQueueTest extends J
363          assertTrue(q.isEmpty());
364      }
365  
366 <    public void testContainsAll(){
366 >    /**
367 >     *
368 >     */
369 >    public void testContainsAll() {
370          PriorityQueue q = populatedQueue(SIZE);
371          PriorityQueue p = new PriorityQueue(SIZE);
372          for (int i = 0; i < SIZE; ++i) {
# Line 302 | Line 377 | public class PriorityQueueTest extends J
377          assertTrue(p.containsAll(q));
378      }
379  
380 <    public void testRetainAll(){
380 >    /**
381 >     *
382 >     */
383 >    public void testRetainAll() {
384          PriorityQueue q = populatedQueue(SIZE);
385          PriorityQueue p = populatedQueue(SIZE);
386          for (int i = 0; i < SIZE; ++i) {
# Line 318 | Line 396 | public class PriorityQueueTest extends J
396          }
397      }
398  
399 <    public void testRemoveAll(){
399 >    /**
400 >     *
401 >     */
402 >    public void testRemoveAll() {
403          for (int i = 1; i < SIZE; ++i) {
404              PriorityQueue q = populatedQueue(SIZE);
405              PriorityQueue p = populatedQueue(i);
# Line 331 | Line 412 | public class PriorityQueueTest extends J
412          }
413      }
414  
415 <    public void testToArray(){
415 >    /**
416 >     *
417 >     */
418 >    public void testToArray() {
419          PriorityQueue q = populatedQueue(SIZE);
420          Object[] o = q.toArray();
421          Arrays.sort(o);
# Line 339 | Line 423 | public class PriorityQueueTest extends J
423              assertEquals(o[i], q.poll());
424      }
425  
426 <    public void testToArray2(){
426 >    /**
427 >     *
428 >     */
429 >    public void testToArray2() {
430          PriorityQueue q = populatedQueue(SIZE);
431          Integer[] ints = new Integer[SIZE];
432          ints = (Integer[])q.toArray(ints);
# Line 348 | Line 435 | public class PriorityQueueTest extends J
435              assertEquals(ints[i], q.poll());
436      }
437      
438 <    public void testIterator(){
438 >    /**
439 >     *
440 >     */
441 >    public void testIterator() {
442          PriorityQueue q = populatedQueue(SIZE);
443          int i = 0;
444          Iterator it = q.iterator();
# Line 359 | Line 449 | public class PriorityQueueTest extends J
449          assertEquals(i, SIZE);
450      }
451  
452 +    /**
453 +     *
454 +     */
455      public void testIteratorRemove () {
363
456          final PriorityQueue q = new PriorityQueue(3);
365
457          q.add(new Integer(2));
458          q.add(new Integer(1));
459          q.add(new Integer(3));
# Line 378 | Line 469 | public class PriorityQueueTest extends J
469      }
470  
471  
472 <    public void testToString(){
472 >    /**
473 >     *
474 >     */
475 >    public void testToString() {
476          PriorityQueue q = populatedQueue(SIZE);
477          String s = q.toString();
478          for (int i = 0; i < SIZE; ++i) {
# Line 386 | Line 480 | public class PriorityQueueTest extends J
480          }
481      }        
482  
483 +    /**
484 +     *
485 +     */
486      public void testSerialization() {
487          PriorityQueue q = populatedQueue(SIZE);
488          try {
# Line 401 | Line 498 | public class PriorityQueueTest extends J
498              while (!q.isEmpty())
499                  assertEquals(q.remove(), r.remove());
500          } catch(Exception e){
501 <            fail("unexpected exception");
501 >            unexpectedException();
502          }
503      }
504   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines