--- a/test/avl_tests.c Sat Jul 15 20:46:18 2017 +0200 +++ b/test/avl_tests.c Sat Jul 15 22:36:29 2017 +0200 @@ -282,3 +282,36 @@ ucx_avl_free(tree); } + +UCX_TEST(test_ucx_avl_traverse) { + UcxAVLTree *tree = ucx_avl_new(ucx_ptrcmp); + + size_t len = 12; + + int val[] = {10, 15, 3, 4, -30, 20, 14, -11, 12, -5, 1, 13}; + int val_ordered[] = {-30, -11, -5, 1, 3, 4, 10, 12, 13, 14, 15, 20}; + + for (size_t i = 0 ; i < len ; i++) { + ucx_avl_put(tree, val[i], &(val[i])); + } + + UCX_TEST_BEGIN + + UcxAVLNode* node = ucx_avl_get_node(tree, (intptr_t) val_ordered[0]); + for (size_t i = 0 ; i < len ; i++) { + UCX_TEST_ASSERT(node->key == val_ordered[i], "AVL successor failed"); + node = ucx_avl_succ(node); + } + UCX_TEST_ASSERT(!node, "AVL maximum incorrectly has a successor"); + + node = ucx_avl_get_node(tree, (intptr_t) val_ordered[len-1]); + for (size_t i = len ; i > 0 ; i--) { + UCX_TEST_ASSERT(node->key == val_ordered[i-1],"AVL predecessor failed"); + node = ucx_avl_pred(node); + } + UCX_TEST_ASSERT(!node, "AVL minimum incorrectly has a predecessor"); + + UCX_TEST_END + + ucx_avl_free(tree); +}