This is the continuation of the first round of refactoring the Priority Heap
code from Data Structures Spring 2005. I just separated out the
other few tests to save time (Elena).
public class TestPriorityHeap {
final static PriorityHeap ph = new PriorityHeap();
public static void main(String [] args) {
testEnqueue();
testDequeueOneElement();
testEnqueueAfterDequeue();
testEmptyTheQueue();
testAddTwoAndDequeue();
testAddTwo();
}
private static void testEnqueue(){
ph.enqueue(3);
ph.enqueue(4);
ph.enqueue(2);
ph.enqueue(4);
ph.enqueue(5);
ph.print();
}
private static void testDequeueOneElement(){
int fromqueue = ph.dequeue();
ph.print();
}
private static void testEnqueueAfterDequeue(){
testDequeueOneElement();
ph.enqueue(9);
ph.print();
}
private static void testEmptyTheQueue() {
while (!ph.isEmpty()) {
ph.dequeue();
}
ph.print();
}
private static void testAddTwoAndDequeue() {
ph.enqueue(55);
ph.enqueue(1);
int fromqueue = ph.dequeue();
ph.print();
}
private static void testAddTwo() {
ph.enqueue(3);
ph.enqueue(0);
ph.print();
}
}
Some issues remaning with the tests: print messages in the beginning of
each method need to be added, the print() method of the
PriorityHeap needs to be made more user-friendly (prinited data is
very confusing). Possible other things to do for test refactoring:
change variable names? Add more tests?
This is an example from CSci 3601 course.