From 409afc165bd581c9b7264295ae25b293a4677b90 Mon Sep 17 00:00:00 2001 From: Hofmann Jonas Date: Mon, 8 Dec 2025 08:24:30 +0100 Subject: [PATCH] wrote test_treeSizeWorkingLikeExpected(void) --- bintreeTests.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/bintreeTests.c b/bintreeTests.c index 68dc28a..ef35bef 100644 --- a/bintreeTests.c +++ b/bintreeTests.c @@ -126,8 +126,38 @@ void test_clearTreeworksLikeExpected(void) // tests if treeSize returns correct amount of nodes in Tree -// by using addNode a given number of times and testing to see if +// by using addToTree a given number of times and testing to see if // the treeSize matches the number of nodes added +void test_treeSizeWorkingLikeExpected(void) +{ + TreeNode *testRoot = NULL; + int nodeCount = 7; + unsigned int testTreeSize = 0; + int score1 = 12; + int score2 = 6; + int score3 = 18; + int score4 = 3; + int score5 = 9; + int score6 = 15; + int score7 = 21; + + + // Fill Tree + testRoot = addToTree(testRoot, &score1, sizeof(int), compareIntEntries, NULL); + testRoot = addToTree(testRoot, &score2, sizeof(int), compareIntEntries, NULL); + testRoot = addToTree(testRoot, &score3, sizeof(int), compareIntEntries, NULL); + testRoot = addToTree(testRoot, &score4, sizeof(int), compareIntEntries, NULL); + testRoot = addToTree(testRoot, &score5, sizeof(int), compareIntEntries, NULL); + testRoot = addToTree(testRoot, &score6, sizeof(int), compareIntEntries, NULL); + testRoot = addToTree(testRoot, &score7, sizeof(int), compareIntEntries, NULL); + testRoot = addToTree(testRoot, &score4, sizeof(int), compareIntEntries, NULL); + + testTreeSize = treeSize(testRoot); + + TEST_ASSERT_EQUAL(nodeCount, testTreeSize); + + clearTree(testRoot); +} // main, strings together all tests