import java.lang.*; import java.util.*; /* * Class that tests the MyPriorityQueue class * Fall 2012 * * @author Bruce Maxwell */ public class MPQTest { // Comparator class that tests Integers public static class Comp> implements Comparator { public int compare( Integer a, Integer b ) { return a.compareTo( b ); } } // Main test function public static void main(String[] argv) { MyPriorityQueue a = new MyPriorityQueue(30, new Comp() ); Random gen = new Random(); a.add(5); a.add(20); a.add(10); // Should be 20, 10, 5 System.out.printf("\nAfter setup %d\n", a.getSize()); for(Integer item: a) { System.out.printf("thing %d\n", item); } a.clear(); // Should be empty System.out.printf("\nAfter clearing %d\n", a.getSize()); for(Integer item: a) { System.out.printf("thing %d\n", item); } for(int i=0;i<10;i++) { a.add( new Integer(gen.nextInt( 20 ) ) ); } // Should have 10 integers in order from largest to smallest System.out.printf("\nAfter setting %d\n", a.getSize()); for(Integer item: a) { System.out.printf("thing %d\n", item); } a.remove(); a.remove(); a.remove(); a.remove(); // Should have 6 integers, with the top 4 removed System.out.printf("\nAfter removing the top 4 items: size %d\n", a.getSize()); for(Integer item: a) { System.out.printf("thing %d\n", item); } int count = a.getSize(); for(int i=0;i