diff options
| author | mo khan <mo.khan@gmail.com> | 2020-08-31 11:35:13 -0600 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2020-08-31 11:35:13 -0600 |
| commit | 02f04d08acd1d64d22607e5387766130c5da80e5 (patch) | |
| tree | 06b7d029fc9b92b44dbd2c310da5caa98dd39ee7 /src | |
| parent | 00b9cfeabb70cd3db932273ddf96f705844fdf06 (diff) | |
fix: ensure equals checks for colour
Diffstat (limited to 'src')
| -rw-r--r-- | src/03/rb_tree.c | 1 | ||||
| -rw-r--r-- | src/03/rb_tree_test.c | 11 |
2 files changed, 12 insertions, 0 deletions
diff --git a/src/03/rb_tree.c b/src/03/rb_tree.c index 3b7b8b1..60b5c1a 100644 --- a/src/03/rb_tree.c +++ b/src/03/rb_tree.c @@ -188,6 +188,7 @@ bool rb_equals(RBTree *tree, RBTree *other_tree) { return tree == other_tree; return tree->value == other_tree->value + && tree->colour == other_tree->colour && rb_equals(tree->left, other_tree->left) && rb_equals(tree->right, other_tree->right); } diff --git a/src/03/rb_tree_test.c b/src/03/rb_tree_test.c index 120f80f..5ffff22 100644 --- a/src/03/rb_tree_test.c +++ b/src/03/rb_tree_test.c @@ -158,6 +158,16 @@ Ensure(equals_returns_false_when_tree_has_one_node) { assert_that(rb_equals(tree, other_tree), is_equal_to(false)); } +Ensure(equals_returns_false_when_tree_has_one_node_with_different_colours) { + RBTree *tree = rb_tree_initialize(20); + RBTree *other_tree = rb_tree_initialize(20); + + tree->colour = black; + other_tree->colour = red; + + assert_that(rb_equals(tree, other_tree), is_equal_to(false)); +} + Ensure(equals_returns_true_when_tree_has_one_node) { RBTree *tree = rb_tree_initialize(20); RBTree *other_tree = rb_tree_initialize(20); @@ -211,6 +221,7 @@ TestSuite *rb_tree_tests() { add_test(x, equals_returns_false_when_other_tree_is_NULL); add_test(x, equals_returns_true_when_both_trees_are_NULL); add_test(x, equals_returns_false_when_tree_has_one_node); + add_test(x, equals_returns_false_when_tree_has_one_node_with_different_colours); add_test(x, equals_returns_true_when_tree_has_one_node); add_test(x, equals_returns_true_when_root_and_left_subtree_are_equal); add_test(x, equals_returns_false_when_root_and_left_subtree_are_not_equal); |
