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.8 by dl, Sat Dec 27 19:26:43 2003 UTC vs.
Revision 1.11 by jsr166, Mon Nov 16 05:30:08 2009 UTC

# Line 2 | Line 2
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3   * Expert Group and released to the public domain, as explained at
4   * http://creativecommons.org/licenses/publicdomain
5 < * Other contributors include Andrew Wright, Jeffrey Hayes,
6 < * Pat Fisher, Mike Judd.
5 > * Other contributors include Andrew Wright, Jeffrey Hayes,
6 > * Pat Fisher, Mike Judd.
7   */
8  
9   import junit.framework.*;
# 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);
20      }
21  
22 <    static class MyReverseComparator implements Comparator {
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();
# Line 36 | Line 36 | public class PriorityQueueTest extends J
36      private PriorityQueue populatedQueue(int n) {
37          PriorityQueue q = new PriorityQueue(n);
38          assertTrue(q.isEmpty());
39 <        for(int i = n-1; i >= 0; i-=2)
39 >        for (int i = n-1; i >= 0; i-=2)
40              assertTrue(q.offer(new Integer(i)));
41 <        for(int i = (n & 1); i < n; i+=2)
41 >        for (int i = (n & 1); i < n; i+=2)
42              assertTrue(q.offer(new Integer(i)));
43          assertFalse(q.isEmpty());
44          assertEquals(n, q.size());
45          return q;
46      }
47 <
47 >
48      /**
49       * A new queue has unbounded capacity
50       */
# Line 170 | Line 170 | public class PriorityQueueTest extends J
170              PriorityQueue q = new PriorityQueue(1);
171              q.offer(null);
172              shouldThrow();
173 <        } catch (NullPointerException success) { }  
173 >        } catch (NullPointerException success) { }
174      }
175  
176      /**
# Line 181 | Line 181 | public class PriorityQueueTest extends J
181              PriorityQueue q = new PriorityQueue(1);
182              q.add(null);
183              shouldThrow();
184 <        } catch (NullPointerException success) { }  
184 >        } catch (NullPointerException success) { }
185      }
186  
187      /**
# Line 204 | Line 204 | public class PriorityQueueTest extends J
204              q.offer(new Object());
205              shouldThrow();
206          }
207 <        catch(ClassCastException success) {}
207 >        catch (ClassCastException success) {}
208      }
209  
210      /**
# Line 327 | Line 327 | public class PriorityQueueTest extends J
327          try {
328              q.remove();
329              shouldThrow();
330 <        } catch (NoSuchElementException success){
331 <        }  
330 >        } catch (NoSuchElementException success) {
331 >        }
332      }
333  
334      /**
# Line 345 | Line 345 | public class PriorityQueueTest extends J
345          }
346          assertTrue(q.isEmpty());
347      }
348 <        
348 >
349      /**
350       * contains(x) reports true when elements added but not yet removed
351       */
# Line 428 | Line 428 | public class PriorityQueueTest extends J
428          PriorityQueue q = populatedQueue(SIZE);
429          Object[] o = q.toArray();
430          Arrays.sort(o);
431 <        for(int i = 0; i < o.length; i++)
431 >        for (int i = 0; i < o.length; i++)
432              assertEquals(o[i], q.poll());
433      }
434  
# Line 440 | Line 440 | public class PriorityQueueTest extends J
440          Integer[] ints = new Integer[SIZE];
441          ints = (Integer[])q.toArray(ints);
442          Arrays.sort(ints);
443 <        for(int i = 0; i < ints.length; i++)
443 >        for (int i = 0; i < ints.length; i++)
444              assertEquals(ints[i], q.poll());
445      }
446 <    
446 >
447      /**
448       * iterator iterates through all elements
449       */
# Line 451 | Line 451 | public class PriorityQueueTest extends J
451          PriorityQueue q = populatedQueue(SIZE);
452          int i = 0;
453          Iterator it = q.iterator();
454 <        while(it.hasNext()) {
454 >        while (it.hasNext()) {
455              assertTrue(q.contains(it.next()));
456              ++i;
457          }
# Line 487 | Line 487 | public class PriorityQueueTest extends J
487          for (int i = 0; i < SIZE; ++i) {
488              assertTrue(s.indexOf(String.valueOf(i)) >= 0);
489          }
490 <    }        
490 >    }
491  
492      /**
493 <     * A deserialized serialized queue has same elements
493 >     * A deserialized serialized queue has same elements
494       */
495      public void testSerialization() {
496          PriorityQueue q = populatedQueue(SIZE);
# Line 504 | Line 504 | public class PriorityQueueTest extends J
504              ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
505              PriorityQueue r = (PriorityQueue)in.readObject();
506              assertEquals(q.size(), r.size());
507 <            while (!q.isEmpty())
507 >            while (!q.isEmpty())
508                  assertEquals(q.remove(), r.remove());
509 <        } catch(Exception e){
509 >        } catch (Exception e) {
510              unexpectedException();
511          }
512      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines