From 370c89d0f313840bfc8307cc0130920d34268fa0 Mon Sep 17 00:00:00 2001 From: Ben Skuppin Date: Wed, 3 Dec 2025 22:28:51 +0100 Subject: [PATCH] =?UTF-8?q?stack=20Testdatei=20und=20stack.h=20StackNode?= =?UTF-8?q?=20=C3=84nderung?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- stack.h | 6 ++++-- stackTests.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 stackTests.c diff --git a/stack.h b/stack.h index 3f8746e..eb29c06 100644 --- a/stack.h +++ b/stack.h @@ -8,10 +8,12 @@ The latest element is taken from the stack. */ #include //TODO: passenden Datentyp als struct anlegen -typedef struct { +typedef struct StackNode StackNode; + +typedef struct StackNode { void* value; StackNode* prev; -} StackNode; +}StackNode; // Pushes data as pointer onto the stack. StackNode *push(StackNode *stack, void *data); diff --git a/stackTests.c b/stackTests.c new file mode 100644 index 0000000..c64a925 --- /dev/null +++ b/stackTests.c @@ -0,0 +1,60 @@ +#include +#include "unity/unity.h" +#include "stack.h" + + + +void setUp(void){} +void tearDown(void){} + +void TEST_CREATE_STACK(){ + + int value = 4; + int* ptr = &value; + StackNode* stack = push(NULL,ptr); + + TEST_ASSERT_NOT_NULL(stack); + TEST_ASSERT_EQUAL_INT(value, *(int*)(stack->value)); + +} + + +void TEST_STACK_POP() { + + int value1 = 4, value2 = 2; + int* ptr = &value1; + int* ptr2 = &value2; + StackNode* stack = push(NULL,ptr); + stack = push(stack,ptr2); + stack = pop(stack); + + TEST_ASSERT_EQUAL_INT(value1, *(int*)(stack->value)); + +} + + +void TEST_STACK_PUSH() { + + int value1 = 4, value2 = 2; + int* ptr = &value1; + int* ptr2 = &value2; + StackNode* stack = push(NULL,ptr); + stack = push(stack,ptr2); + + TEST_ASSERT_EQUAL_INT(value2, *(int*)(stack->value)); +} + + +int main(){ + UNITY_BEGIN(); + + printf("\n============================\nstack tests\n============================\n"); + + RUN_TEST(TEST_CREATE_STACK); + RUN_TEST(TEST_STACK_POP); + RUN_TEST(TEST_STACK_PUSH); + + return UNITY_END(); +} + +//Befehl zum Kompilieren: gcc stack.c stackTests.c unity/unity.c \ No newline at end of file