280 |
280 |
281 UCX_TEST_END |
281 UCX_TEST_END |
282 |
282 |
283 ucx_avl_free(tree); |
283 ucx_avl_free(tree); |
284 } |
284 } |
|
285 |
|
286 UCX_TEST(test_ucx_avl_traverse) { |
|
287 UcxAVLTree *tree = ucx_avl_new(ucx_ptrcmp); |
|
288 |
|
289 size_t len = 12; |
|
290 |
|
291 int val[] = {10, 15, 3, 4, -30, 20, 14, -11, 12, -5, 1, 13}; |
|
292 int val_ordered[] = {-30, -11, -5, 1, 3, 4, 10, 12, 13, 14, 15, 20}; |
|
293 |
|
294 for (size_t i = 0 ; i < len ; i++) { |
|
295 ucx_avl_put(tree, val[i], &(val[i])); |
|
296 } |
|
297 |
|
298 UCX_TEST_BEGIN |
|
299 |
|
300 UcxAVLNode* node = ucx_avl_get_node(tree, (intptr_t) val_ordered[0]); |
|
301 for (size_t i = 0 ; i < len ; i++) { |
|
302 UCX_TEST_ASSERT(node->key == val_ordered[i], "AVL successor failed"); |
|
303 node = ucx_avl_succ(node); |
|
304 } |
|
305 UCX_TEST_ASSERT(!node, "AVL maximum incorrectly has a successor"); |
|
306 |
|
307 node = ucx_avl_get_node(tree, (intptr_t) val_ordered[len-1]); |
|
308 for (size_t i = len ; i > 0 ; i--) { |
|
309 UCX_TEST_ASSERT(node->key == val_ordered[i-1],"AVL predecessor failed"); |
|
310 node = ucx_avl_pred(node); |
|
311 } |
|
312 UCX_TEST_ASSERT(!node, "AVL minimum incorrectly has a predecessor"); |
|
313 |
|
314 UCX_TEST_END |
|
315 |
|
316 ucx_avl_free(tree); |
|
317 } |