Commit 1ec2c1af authored by Chris Müller's avatar Chris Müller

test: add testcases for in-order traversal in red-black trees.

parent 3b9cef12
......@@ -113,6 +113,42 @@ test_red_black_tree_removal(const_pointer list)
}
static void
test_red_black_tree_traversal(const_pointer list)
{
struct RBTree* tree = rb_tree_new(cry_int_compare);
const int* keys = cry_cast(const int*, list);
struct RBNode* data = 0;
assert(tree->nodes == 0);
while(*keys > 0) {
assert(rb_tree_insert(tree, keys) != 0);
++keys;
}
assert(tree->nodes == 10);
keys = cry_cast(const int*, list);
data = rb_node_first(tree);
while(data != 0) {
data = rb_node_next(data);
}
data = rb_node_last(tree);
while(data != 0) {
data = rb_node_prev(data);
}
rb_tree_clear(tree, 0);
cry_free(tree);
}
void
cry_test_red_black_trees(void)
......@@ -121,5 +157,6 @@ cry_test_red_black_trees(void)
cry_unittest_run("structures.red_black_tree.insertion", test_red_black_tree_insertion, keys, 10);
cry_unittest_run("structures.red_black_tree.removal", test_red_black_tree_removal, keys, 10);
cry_unittest_run("structures.red_black_tree.initialization", test_red_black_tree_initialization, 0, 10);
cry_unittest_run("structures.red_black_tree.initialization", test_red_black_tree_initialization, 0, 10);
cry_unittest_run("structures.red_black_tree.traversal", test_red_black_tree_traversal, keys, 10);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment