exercism / exercism/c

Binary Search Tree: Test root node with value == 0 is allowed

Open
#810 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
383
Forks
215
PR merge metrics
No merged PRs in 30d

Description

In my attempt to solve the Binary Search Tree exercise, I first came up wit a solution that would have overwritte it's root node when building a tree if the value of the root node was 0. This behaviour was not cought by the provided tests, but by @siebenschlaefer, who did a great job providing mentoring and feedback.

I would suggest to add a test for the tree to allow zero as the value of the root node to the testsuite. I have already written such a test for the C track and am happy to open a PR to add it.

in case you deem this an issue applicable to all language tracks, I'm happy to also open a PR in https://github.com/exercism/problem-specifications.

The test I propose to add is as follows:

``` c
static void test_data_can_have_zero_as_first_node(void)
{
int tree_data[] = { 0, 0, 1, 2, 3 };
node_t *tree = build_tree(tree_data, ARRAY_SIZE(tree_data));

TEST_ASSERT_NOT_NULL(tree);
TEST_ASSERT_EQUAL_INT(0, tree->data);
TEST_ASSERT_NOT_NULL(tree->left);
TEST_ASSERT_NOT_NULL(tree->right);

TEST_ASSERT_EQUAL_INT(0, tree->left->data);
TEST_ASSERT_NULL(tree->left->left);
TEST_ASSERT_NULL(tree->left->right);

TEST_ASSERT_EQUAL_INT(1, tree->right->data);
TEST_ASSERT_NULL(tree->right->left);
TEST_ASSERT_NOT_NULL(tree->right->right);

TEST_ASSERT_EQUAL_INT(2, tree->right->right->data);
TEST_ASSERT_NULL(tree->right->right->left);
TEST_ASSERT_NOT_NULL(tree->right->right->right);

TEST_ASSERT_EQUAL_INT(3, tree->right->right->right->data);
TEST_ASSERT_NULL(tree->right->right->right->left);
TEST_ASSERT_NULL(tree->right->right->right->right);

free_tree(tree);
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.