7 #define NUM_ELEMENTS 1e5
9 int cmp_int(const void *ia, const void *ib)
11 return *(const int *) ia - *(const int *) ib;
14 void clear_callback(void *ia, void *ib)
16 assert(*(int *) ia > *(int *) ib);
24 printf("------------\n");
25 printf("Testing Tree\n");
26 printf("------------\n");
30 printf("testing ini\n");
39 printf("testing add\n");
40 assert(tree_add(&tree, &a, &cmp_int, NULL) == &a);
41 assert(tree_add(&tree, &b, &cmp_int, NULL) == &b);
42 assert(tree_add(&tree, &c, &cmp_int, NULL) == &c);
43 assert(tree_add(&tree, &d, &cmp_int, NULL) == &c);
45 printf("testing get\n");
46 assert(tree_get(&tree, &a, &cmp_int, NULL) == &a);
47 assert(tree_get(&tree, &b, &cmp_int, NULL) == &b);
48 assert(tree_get(&tree, &c, &cmp_int, NULL) == &c);
49 assert(tree_get(&tree, &d, &cmp_int, NULL) == &c);
50 assert(tree_get(&tree, &e, &cmp_int, NULL) == NULL);
52 printf("testing del\n");
53 assert(tree_del(&tree, &a, &cmp_int, NULL) == &a);
54 assert(tree_get(&tree, &a, &cmp_int, NULL) == NULL);
56 printf("testing clr\n");
57 tree_clr(&tree, NULL, NULL, 0);
58 assert(tree_get(&tree, &b, &cmp_int, NULL) == NULL);
60 printf("testing order and speed with %d elements\n", (int) NUM_ELEMENTS);
61 for (int i = 0; i < NUM_ELEMENTS; i++) {
62 int *n = malloc(sizeof *n);
65 if (tree_add(&tree, n, &cmp_int, NULL) != n)
70 tree_clr(&tree, &clear_callback, &last, TRAVERSION_INORDER);