Implement first test

This commit is contained in:
D2A62006 2025-12-07 20:17:27 +01:00
parent 97a11d8ac6
commit c79a61e8ee

View File

@ -1,8 +1,22 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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();
}