setup first test for bintree.c

This commit is contained in:
Simon Wiesend 2025-11-29 17:21:51 +01:00
parent fd51eef1fe
commit ab71a3dd74
Signed by: wiesendsi102436
GPG Key ID: C18A833054142CF0
2 changed files with 44 additions and 0 deletions

View File

@ -36,11 +36,16 @@ $(program_obj_filesobj_files): %.o: %.c
# Unit Tests
# --------------------------
TEST_STACK_SOURCES = stack.c test_stack.c $(unityfolder)/unity.c
TEST_BINTREE_SOURCES = bintree.c test_bintree.c stack.c $(unityfolder)/unity.c
stackTests: $(TEST_STACK_SOURCES) stack.h
$(CC) $(FLAGS) -I$(unityfolder) $(TEST_STACK_SOURCES) -o runStackTests
./runStackTests
bintreeTests: $(TEST_BINTREE_SOURCES) stack.h bintree.h
$(CC) $(FLAGS) -I$(unityfolder) $(TEST_BINTREE_SOURCES) -o runBintreeTests
./runBintreeTests
# --------------------------
# Clean
# --------------------------

39
test_bintree.c Normal file
View File

@ -0,0 +1,39 @@
#include "unity.h"
#include "bintree.h"
#include "string.h"
void setUp(void)
{
// set stuff up here
}
void tearDown(void)
{
// set stuff up here
}
// this adds some strings and checks if they are returned in the right order
void test_insert_and_retrieve(void)
{
char *data1 = "a_this";
char *data2 = "b_is";
char *data3 = "c_testdata";
TreeNode *root = addToTree(NULL, data1, strlen(data1) + 1, (CompareFctType)&strcmp, NULL);
addToTree(root, data2, strlen(data2) + 1, (CompareFctType)&strcmp, NULL);
addToTree(root, data3, strlen(data3) + 1, (CompareFctType)&strcmp, NULL);
TEST_ASSERT_EQUAL_STRING(data1, (char *)nextTreeData(root));
TEST_ASSERT_EQUAL_STRING(data2, (char *)nextTreeData(NULL));
TEST_ASSERT_EQUAL_STRING(data3, (char *)nextTreeData(NULL));
clearTree(root);
}
int main(void)
{
printf("============================\nBintree tests\n============================\n");
UNITY_BEGIN();
RUN_TEST(test_insert_and_retrieve);
return UNITY_END();
}