In the current testing setup, tests for both tree_search() and infix_walk() defined by reftable/tree.{c, h} are performed by a single test function, test_tree(). Split tree_test() into test_tree_search() and test_infix_walk() responsible for independently testing tree_search() and infix_walk() respectively. This improves the overall readability of the test file as well as simplifies debugging. Mentored-by: Patrick Steinhardt <ps@xxxxxx> Mentored-by: Christian Couder <chriscool@xxxxxxxxxxxxx> Signed-off-by: Chandra Pratap <chandrapratap3519@xxxxxxxxx> --- t/unit-tests/t-reftable-tree.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/t/unit-tests/t-reftable-tree.c b/t/unit-tests/t-reftable-tree.c index 208e7b7874..78d5caafbe 100644 --- a/t/unit-tests/t-reftable-tree.c +++ b/t/unit-tests/t-reftable-tree.c @@ -26,7 +26,7 @@ static void check_increasing(void *arg, void *key) c->last = key; } -static void test_tree(void) +static void test_tree_search(void) { struct tree_node *root = NULL; void *values[11] = { 0 }; @@ -44,13 +44,29 @@ static void test_tree(void) check_pointer_eq(nodes[i], tree_search(values + i, &root, &test_compare, 0)); } - infix_walk(root, check_increasing, &c); + tree_free(root); +} + +static void test_infix_walk(void) +{ + struct tree_node *root = NULL; + void *values[13] = { 0 }; + struct curry c = { 0 }; + size_t i = 1; + + do { + tree_search(values + i, &root, &test_compare, 1); + i = (i * 5) % 13; + } while (i != 1); + + infix_walk(root, &check_increasing, &c); tree_free(root); } int cmd_main(int argc, const char *argv[]) { - TEST(test_tree(), "tree_search and infix_walk work"); + TEST(test_tree_search(), "tree_search works"); + TEST(test_infix_walk(), "infix_walk works"); return test_done(); } -- 2.45.2.404.g9eaef5822c