Add test for tree destruction
This commit is contained in:
parent
e8ab0ab9c0
commit
710ca112e3
@ -212,6 +212,15 @@ remove_reverse_iterate_cb(tree_t *tree, node_t *node, void *data)
|
|||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
destroy_cb(node_t *node, void *data)
|
||||||
|
{
|
||||||
|
unsigned *nnodes = (unsigned *)data;
|
||||||
|
|
||||||
|
assert_u_gt(*nnodes, 0, "Destruction removed too many nodes");
|
||||||
|
(*nnodes)--;
|
||||||
|
}
|
||||||
|
|
||||||
TEST_BEGIN(test_rb_random)
|
TEST_BEGIN(test_rb_random)
|
||||||
{
|
{
|
||||||
#define NNODES 25
|
#define NNODES 25
|
||||||
@ -278,7 +287,7 @@ TEST_BEGIN(test_rb_random)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Remove nodes. */
|
/* Remove nodes. */
|
||||||
switch (i % 4) {
|
switch (i % 5) {
|
||||||
case 0:
|
case 0:
|
||||||
for (k = 0; k < j; k++)
|
for (k = 0; k < j; k++)
|
||||||
node_remove(&tree, &nodes[k], j - k);
|
node_remove(&tree, &nodes[k], j - k);
|
||||||
@ -314,6 +323,12 @@ TEST_BEGIN(test_rb_random)
|
|||||||
assert_u_eq(nnodes, 0,
|
assert_u_eq(nnodes, 0,
|
||||||
"Removal terminated early");
|
"Removal terminated early");
|
||||||
break;
|
break;
|
||||||
|
} case 4: {
|
||||||
|
unsigned nnodes = j;
|
||||||
|
tree_destroy(&tree, destroy_cb, &nnodes);
|
||||||
|
assert_u_eq(nnodes, 0,
|
||||||
|
"Destruction terminated early");
|
||||||
|
break;
|
||||||
} default:
|
} default:
|
||||||
not_reached();
|
not_reached();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user