diff --git a/tests/test_tree.c b/tests/test_tree.c index 0210c1e..339fb1b 100644 --- a/tests/test_tree.c +++ b/tests/test_tree.c @@ -413,6 +413,40 @@ static int test_tree_deeper_than_the_cap_is_out_of_bounds(void) AKSL_CHECK_OK(aksl_tree_iterate(&chain[0], &record_visit, NULL, NULL, AKSL_TREE_SEARCH_DFS_PREORDER, &log)); AKSL_CHECK(log.count == AKSL_TREE_MAX_DEPTH); + + /* + * And again leaning right. The recursion counts depth separately for each + * child, so a chain that only ever goes left says nothing about whether the + * right-hand descent counts at all -- mutation testing found exactly that: + * changing the right child's `depth + 1` to `depth + 0` survived the whole + * suite, because nothing here had ever recursed right more than three deep. + */ + for ( i = 0; i < AKSL_TREE_MAX_DEPTH + 2; i++ ) { + AKSL_CHECK_OK(aksl_tree_node_init(&chain[i], NULL)); + } + for ( i = 0; i < AKSL_TREE_MAX_DEPTH + 1; i++ ) { + chain[i].right = &chain[i + 1]; + } + visitlog_init(&log); + AKSL_CHECK_STATUS(aksl_tree_iterate(&chain[0], &record_visit, NULL, NULL, + AKSL_TREE_SEARCH_DFS_PREORDER, &log), + AKERR_OUTOFBOUNDS); + + /* Both orders that descend right, so in-order and post-order count too. */ + visitlog_init(&log); + AKSL_CHECK_STATUS(aksl_tree_iterate(&chain[0], &record_visit, NULL, NULL, + AKSL_TREE_SEARCH_DFS_INORDER, &log), + AKERR_OUTOFBOUNDS); + visitlog_init(&log); + AKSL_CHECK_STATUS(aksl_tree_iterate(&chain[0], &record_visit, NULL, NULL, + AKSL_TREE_SEARCH_DFS_POSTORDER, &log), + AKERR_OUTOFBOUNDS); + + /* And breadth-first, whose depth is carried on the queue entry instead. */ + visitlog_init(&log); + AKSL_CHECK_STATUS(aksl_tree_iterate(&chain[0], &record_visit, NULL, NULL, + AKSL_TREE_SEARCH_BFS, &log), + AKERR_OUTOFBOUNDS); return 0; }