wrote test_nextTreeDataReturnsNextDataCorrectly()

This commit is contained in:
Jonas Hofmann 2025-12-09 21:48:43 +01:00
parent 9d08970513
commit e4a8afabdd
3 changed files with 36 additions and 0 deletions

BIN
bintree.o

Binary file not shown.

View File

@ -3,6 +3,7 @@
#include <stdlib.h>
#include "unity.h"
#include "bintree.h"
#include "stack.h"
#define MAX_TEST_NAME_LEN 10
@ -89,7 +90,42 @@ void test_addToTreeExpandsTreeCorrectly(void)
// needs Stack!!!
void test_nextTreeDataReturnsNextDataCorrectly(void)
{
TreeNode *testRoot = NULL;
int score1 = 12;
int score2 = 6;
int score3 = 18;
int score4 = 3;
int score5 = 9;
int score6 = 15;
int score7 = 21;
// Prepare a 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);
// Create Stack
StackNode *entry = nextTreeData(testRoot);
// check if nextTreeData returns Data correctly
TEST_ASSERT_NOT_NULL(entry);
TEST_ASSERT_EQUAL(score7, *(int *)nextTreeData(NULL));
TEST_ASSERT_EQUAL(score3, *(int *)nextTreeData(NULL));
TEST_ASSERT_EQUAL(score6, *(int *)nextTreeData(NULL));
TEST_ASSERT_EQUAL(score1, *(int *)nextTreeData(NULL));
TEST_ASSERT_EQUAL(score5, *(int *)nextTreeData(NULL));
TEST_ASSERT_EQUAL(score2, *(int *)nextTreeData(NULL));
TEST_ASSERT_EQUAL(score4, *(int *)nextTreeData(NULL));
clearStack(entry);
clearTree(testRoot);
}

Binary file not shown.