public void testClear() { PriorityQueue pq = new IntegerQueue(3); pq.put(new Integer(2)); pq.put(new Integer(3)); pq.put(new Integer(1)); assertEquals(3, pq.size()); pq.clear(); assertEquals(0, pq.size()); }
public static void testPQ(int count) { PriorityQueue pq = new IntegerQueue(count); Random gen = new Random(); int sum = 0, sum2 = 0; for (int i = 0; i < count; i++) { int next = gen.nextInt(); sum += next; pq.put(new Integer(next)); } // Date end = new Date(); // System.out.print(((float)(end.getTime()-start.getTime()) / count) * 1000); // System.out.println(" microseconds/put"); // start = new Date(); int last = Integer.MIN_VALUE; for (int i = 0; i < count; i++) { Integer next = (Integer) pq.pop(); assertTrue(next.intValue() >= last); last = next.intValue(); sum2 += last; } assertEquals(sum, sum2); // end = new Date(); // System.out.print(((float)(end.getTime()-start.getTime()) / count) * 1000); // System.out.println(" microseconds/pop"); }