/***** * heap_test.c * * Make sure the routines defined in heap.c work. * See heap.h for the API. * * $ ./heap_test * --- test heap --- * 1 ok node creation * 2 ok node data * 3 ok node weight * 4 ok heap creation descending=FALSE * 5 ok heap size * 6 ok heapify worked * 7 ok push worked * 8 ok pop works * 9 ok repeated pop sorts 'em * 10 ok heap creation descending=TRUE * 11 ok heap size * 12 ok heapify worked * 13 ok push worked * 14 ok pop works * 15 ok repeated pop sorts 'em * 1..15 * All tests successful. * * The descending heap formed from (0 1 2 3 4 5 6 7 8 9) * is (9 8 6 7 4 5 2 0 3 1 ), which you can see by uncommented * the print_heap() statement below. * Layed out in its binary tree this is * 9 * 8 6 * 7 4 5 2 * 0 3 1 . . . . . * * $Id: heap_test.c 12570 2007-04-09 16:44:25Z mahoney $ ******/ #include #include #include #include "test_framework.h" #include "heap.h" #define NODE_LIST_SIZE 128 int main(){ int i; bool descending; heap h = NULL; node n5 = NULL; int n_nodes = 10; node nodes[NODE_LIST_SIZE]; char* five = "five"; char* string; int last_weight, n_popped; node popped_node; bool in_order; int status; printf("--- test heap ---\n"); // // See if test framework does what it should. // ok(1==2, "one is two"); // ok(1==1, "one is one"); // Node n5 = new_node(5, five); ok(!(n5==NULL), "node creation"); ok(0==strcmp(five, get_node_data(n5)), "node data"); ok(get_node_weight(n5) == 5, "node weight"); for (descending=FALSE; descending<=TRUE; descending++){ // Heap for (i=0; i= last_weight)); last_weight = get_node_weight(popped_node); } } ok(in_order && (n_popped == n_nodes+1), "repeated pop sorts 'em"); } // ok(1==2, "one is two"); // Just for testing - a test designed to fail. print_test_summary(); exit(test_status()); }