This is the first round of refactoring the Priority Heap
code from Data Structures Spring 2005. The team started by
refactoring the testing file. Note that this was done in the
classroom, without using Eclipse or Junit testing.
public class TestPriorityHeap {
final static PriorityHeap ph = new PriorityHeap();
public static void main(String [] args) {
testEnqueue();
testDequeueOneElement();
testEnqueueAfterDequeue();
// flush the queue
while (!ph.isEmpty()) {
ph.dequeue();
}
ph.print();
// start all over
ph.enqueue(55);
ph.enqueue(1);
int fromqueue = ph.dequeue();
ph.print();
ph.enqueue(3);
ph.enqueue(0);
ph.print();
}
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();
}
}
Some issues remaning with the tests: more tests need to be separated
out, 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.