Add toArray to bintree.c

This commit is contained in:
Tobias Linz committed 2026-11-18 22:06:47 +01:00
1 parent a062691967
commit 6ec27077c8
3 files changed
+29 -1

No files matched your search

+9
View File
@@ -29,6 +29,14 @@ static void test_addToTreeAllNullReturnsNull(void)
TEST_ASSERT_NULL(addToTree(NULL, NULL, 0, NULL, NULL));
}
static void test_toArrayWorks(void)
{
TreeNode *const tree = buildTree();
const int *array = toArray(tree, sizeof(int));
const int expected[4] = {1, 2, 3, 4,};
TEST_ASSERT_EQUAL_INT_ARRAY(expected, array, 4);
}
static void test_addToTreeBuildsTreeInOrder(void)
{
const TreeNode *const tree = buildTree();
@@ -141,6 +149,7 @@ int main()
printf("\n============================\nbinary tree tests\n============================\n");
RUN_TEST(test_addToTreeAllNullReturnsNull);
RUN_TEST(test_toArrayWorks);
RUN_TEST(test_addToTreeBuildsTreeInOrder);
RUN_TEST(test_addToTreeReportsNoDuplicates);
RUN_TEST(test_addToTreeReportsDuplicates);