Skip to content

Commit abf1a96

Browse files
Chandra Pratapgitster
authored andcommitted
t-reftable-tree: split test_tree() into two sub-test functions
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. Note that the last parameter in the tree_search() functiom is 'int insert' which when set, inserts the key if it is not found in the tree. Otherwise, the function returns NULL for such cases. While at it, use 'func' to pass function pointers and not '&func'. Mentored-by: Patrick Steinhardt <[email protected]> Mentored-by: Christian Couder <[email protected]> Signed-off-by: Chandra Pratap <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ec9c070 commit abf1a96

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

t/unit-tests/t-reftable-tree.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,12 @@ static void check_increasing(void *arg, void *key)
2626
c->last = key;
2727
}
2828

29-
static void t_tree(void)
29+
static void t_tree_search(void)
3030
{
3131
struct tree_node *root = NULL;
3232
void *values[11] = { 0 };
3333
struct tree_node *nodes[11] = { 0 };
3434
size_t i = 1;
35-
struct curry c = { 0 };
3635

3736
/*
3837
* Pseudo-randomly insert the pointers for elements between
@@ -48,13 +47,29 @@ static void t_tree(void)
4847
check_pointer_eq(nodes[i], tree_search(&values[i], &root, &t_compare, 0));
4948
}
5049

51-
infix_walk(root, check_increasing, &c);
50+
tree_free(root);
51+
}
52+
53+
static void t_infix_walk(void)
54+
{
55+
struct tree_node *root = NULL;
56+
void *values[11] = { 0 };
57+
struct curry c = { 0 };
58+
size_t i = 1;
59+
60+
do {
61+
tree_search(&values[i], &root, t_compare, 1);
62+
i = (i * 7) % 11;
63+
} while (i != 1);
64+
65+
infix_walk(root, &check_increasing, &c);
5266
tree_free(root);
5367
}
5468

5569
int cmd_main(int argc, const char *argv[])
5670
{
57-
TEST(t_tree(), "tree_search and infix_walk work");
71+
TEST(t_tree_search(), "tree_search works");
72+
TEST(t_infix_walk(), "infix_walk works");
5873

5974
return test_done();
6075
}

0 commit comments

Comments
 (0)