adds some additional avl tree tests

Fri, 28 Sep 2018 21:47:30 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Fri, 28 Sep 2018 21:47:30 +0200
changeset 330
d2bbf907a189
parent 329
71e9a60abfb4
child 331
3b985a4eb05b

adds some additional avl tree tests

test/avl_tests.c file | annotate | diff | comparison | revisions
--- a/test/avl_tests.c	Wed Aug 22 14:39:24 2018 +0200
+++ b/test/avl_tests.c	Fri Sep 28 21:47:30 2018 +0200
@@ -230,6 +230,8 @@
 
 UCX_TEST(test_ucx_avl_find) {
     UcxAVLTree *tree = ucx_avl_new(ucx_cmp_ptr);
+    UcxAVLTree *tree2 = ucx_avl_new(ucx_cmp_ptr);
+    UcxAVLTree *tree3 = ucx_avl_new(ucx_cmp_ptr);
     
     size_t len = 12;
     int val[] = {10, 15, 3, 4, -30, 20, 14, -11, 12, -5, 1, 13};
@@ -278,9 +280,25 @@
     ret = ucx_avl_find(tree,(intptr_t)7, dist_int, UCX_AVL_FIND_UPPER_BOUNDED);
     UCX_TEST_ASSERT(ret && *((int*)ret) == 4, "AVL find UB failed");
     
+    int val2[] = { 10, 15 };
+    ucx_avl_put(tree2, val2[0], &(val2[0]));
+    ucx_avl_put(tree2, val2[1], &(val2[1]));
+    ret = ucx_avl_find(tree2,(intptr_t)11, dist_int, UCX_AVL_FIND_UPPER_BOUNDED);
+    UCX_TEST_ASSERT(ret && *((int*)ret) == 10, "AVL find LB failed");
+    
+    int val3[] = { 15, 16, 1 };
+    ucx_avl_put(tree3, val3[0], &(val3[0]));
+    ucx_avl_put(tree3, val3[1], &(val3[1]));
+    ucx_avl_put(tree3, val3[2], &(val3[2]));
+   
+    ret = ucx_avl_find(tree3, (intptr_t)13, dist_int, UCX_AVL_FIND_CLOSEST);
+    UCX_TEST_ASSERT(ret && *((int*)ret) == 15, "AVL find closest failed");
+    
     UCX_TEST_END
     
     ucx_avl_free(tree);
+    ucx_avl_free(tree2);
+    ucx_avl_free(tree3);
 }
 
 UCX_TEST(test_ucx_avl_traverse) {

mercurial