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