erste tests stack.c

This commit is contained in:
Max-R 2025-12-05 10:41:30 +01:00
parent e7423f0a20
commit ddd4132e1f
3 changed files with 67 additions and 1 deletions

View File

@ -36,7 +36,13 @@ $(program_obj_filesobj_files): %.o: %.c
# Unit Tests
# --------------------------
unitTests:
echo "needs to be implemented"
TEST_BIN = runTests
unitTests: stack.o test_stack.o
$(CC) $(FLAGS) -I$(unityfolder) -o $(TEST_BIN) stack.o test_stack.o $(unityfolder)/unity.c
test_stack.o: test_stack.c
$(CC) $(FLAGS) -I$(unityfolder) -c test_stack.c -o test_stack.o
# --------------------------
# Clean

View File

@ -13,6 +13,7 @@ typedef struct StackNode {
void *data;
struct StackNode *next;
struct StackNode *prev;
} StackNode;

59
test_stack.c Normal file
View File

@ -0,0 +1,59 @@
#include "unity.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "stack.h"
void test_createNode(void) {
int testInt = 26;
StackNode *testNode = createNode(&testInt);
TEST_ASSERT_NOT_NULL(testNode);
TEST_ASSERT_EQUAL_PTR(&testInt, testNode->data);
TEST_ASSERT_NULL(testNode->next);
free(testNode);
}
void test_pushDataToStack(void) {}
void test_deleteTopElement(void) {}
void test_returnData(void) {}
void test_clearStack(void) {
int testInts[] = {1, 2, 3, 4, 5};
StackNode *testStack = NULL;
for (int i = 0; i < 5; i++) {
testStack = push(testStack, &testInts[i]);
}
clearStack(testStack);
TEST_ASSERT_NULL(testStack);
}
void setUp(void) {}
void tearDown(void) {}
int main(void) {
UNITY_BEGIN();
printf("------------------------stack test------------------------\n");
RUN_TEST(test_createNode);
RUN_TEST(test_pushDataToStack);
RUN_TEST(test_deleteTopElement);
RUN_TEST(test_returnData);
RUN_TEST(test_clearStack);
RUN_TEST(test_clearStack);
return UNITY_END();
}