static void test_dsync_mailbox_tree_sync_random(void) { struct dsync_mailbox_tree *tree1, *tree2; test_begin("dsync mailbox tree sync random"); tree1 = create_random_tree(); tree2 = create_random_tree(); test_trees(tree1, tree2); test_end(); }
// test predecessor & successor of a BST void test6(int n, int min, int max) { test("Test predecessor: ",6); tree *t = create_random_tree(n, min, max); print_ascii_tree(t); int i; for ( i = min; i <= max ; i = i+10) { tree *predecessor = find_predecessor(t, i); printf("%d's predecessor: ", i); if( predecessor == NULL) printf(" not found\n"); else printf(" %d\n", predecessor->data); } test("Test successor: ",6); for ( i = min; i <= max ; i = i+10) { tree *successor = find_successor(t, i); printf("%d's successor: ", i); if( successor == NULL) printf(" not found\n"); else printf(" %d\n", successor->data); } free_tree(t); }
// create random tree and print test1(int n, int min, int max) { test("create random tree and print",1); tree *t = 0; t = create_random_tree(n, min, max); print_ascii_tree(t); free_tree(t); }
// test balancing of a binary tree void test5(int n, int min, int max) { test("balance binary tree ", 5); tree *t = create_random_tree(n, min, max); printf("Binary Tree: \n"); print_ascii_tree(t); printf("Balanced Tree: \n"); balance_tree(&t, n); print_ascii_tree(t); free_tree(t); }
// test binary tree to linked list conversion void test4(int n, int min, int max) { test("convert binary tree to linked list",4); tree *t = create_random_tree(n,min,max); print_ascii_tree(t); printf("Binary Tree to Linked List: \n"); create_backbone(&t); print_ascii_tree(t); free_tree(t); }
// search from min to max void test2(int n, int min, int max) { test("search elements between min & max",2); int i; tree *result; tree *t = create_random_tree(n, min, max); print_ascii_tree(t); for( i = min ; i < max; ++i) { result = search(t,i); if( result != NULL ) printf("%d found \n", i); } free_tree(t); }
// delete within min and max void test3(int n, int min, int max) { test("delete elements between min & max",3); int i, size ; tree *t = create_random_tree(n, min, max); size = max - min; int *a = (int *) malloc(size*sizeof(int)); for( i = 0 ; i < size; ++i) a[i] = i; shuffle(a, size); for(i = 0 ; i < size; ++i) { printf("Delete : %d\n", a[i]); delete_by_copying(&t, a[i]); print_ascii_tree(t); } free(a); free_tree(t); }