diff --git a/makefile b/makefile index e0626fb..c4c6314 100644 --- a/makefile +++ b/makefile @@ -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 # -------------------------- diff --git a/test_bintree.c b/test_bintree.c new file mode 100644 index 0000000..3ca280d --- /dev/null +++ b/test_bintree.c @@ -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(); +} \ No newline at end of file