From c79a61e8ee34c40176670d4d2754210b52feef8e Mon Sep 17 00:00:00 2001 From: D2A62006 Date: Sun, 7 Dec 2025 20:17:27 +0100 Subject: [PATCH] Implement first test --- bintreeTest.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/bintreeTest.c b/bintreeTest.c index 3ad1b25..75daf8a 100644 --- a/bintreeTest.c +++ b/bintreeTest.c @@ -1,8 +1,22 @@ #include #include +#include #include "unity.h" #include "bintree.h" +int compareInts(const void *arg1, const void *arg2){ + int val1 = *(int *)arg1; + int val2 = *(int *)arg2; + + if(val1 < val2) return 1; + if(val1 > val2) return -1; + return 0; +} + +int compareStrings(const void *arg1, const void *arg2){ + return -strcmp((const char *)arg1, (const char *)arg2); +} + void setUp(void){ //Use if needed @@ -11,9 +25,24 @@ void tearDown(void){ //Use if needed } +void test_addToTree_singleElement(void){ + int value = 42; + TreeNode *tree = NULL; + + tree = addToTree(tree, &value, sizeof(int), compareInts, NULL); + + TEST_ASSERT_NOT_NULL(tree); + TEST_ASSERT_EQUAL_INT(value, *(int *)tree->data); + TEST_ASSERT_NULL(tree->left); + TEST_ASSERT_NULL(tree->right); +} int main(){ UNITY_BEGIN(); printf("\n============================\nBintree tests\n============================\n"); + + RUN_TEST(test_addToTree_singleElement); + + return UNITY_END(); } \ No newline at end of file