diff --git a/makefile b/makefile index 84878ed..0b03bab 100644 --- a/makefile +++ b/makefile @@ -49,7 +49,7 @@ stackTests: stack.o stackTests.c $(unityfolder)/unity.c # Clean # -------------------------- clean: -ifeq ($(OS),Windows_NT) +ifeq ($(OS),!Windows_NT) del /f *.o doble *.exe else rm -f *.o doble *runNumbersTests diff --git a/stack.c b/stack.c index c78727b..d6735c9 100644 --- a/stack.c +++ b/stack.c @@ -20,17 +20,28 @@ StackNode *push(StackNode *stack, void *data) // freed by caller.) StackNode *pop(StackNode *stack) { - + if(stack == NULL) + return NULL; + StackNode *next = stack->next; + free(stack); + return next; } // Returns the data of the top element. void *top(StackNode *stack) { - + if(stack == NULL) + return NULL; + return stack->data; } // Clears stack and releases all memory. void clearStack(StackNode *stack) { - -} \ No newline at end of file + while(stack != NULL) + { + StackNode *next = stack->next; + free(stack); + stack = next; + } +} diff --git a/stackTests.c b/stackTests.c index 55dcedd..a70ff14 100644 --- a/stackTests.c +++ b/stackTests.c @@ -9,34 +9,20 @@ void tearDown(void){} void test_push_created_new_stacknode(void) { - StackNode test = {111,NULL}; - int testdata = 222; - void *data =&testdata; + int testdata1 = 111; + StackNode test = {&testdata1,NULL}; + int testdata2 = 222; - StackNode test1 = push(&test,data); - unsigned int n = 50; - unsigned int* arr = createNumbers(n); - - TEST_ASSERT_NOT_NULL(arr); - - // Ein paar Werte prüfen (dürfen alles sein, nur kein Segfault) - for (unsigned int i = 0; i < n; i++) - TEST_ASSERT_TRUE(arr[i] >= 0); - - free(arr); + StackNode *test1 = push(&test,&testdata2); + TEST_ASSERT_NOT_NULL(test1); + TEST_ASSERT_EQUAL_PTR(&testdata2,test1->data); + TEST_ASSERT_EQUAL_PTR(&test,test1->next); } - - - - int main(void) { UNITY_BEGIN(); - RUN_TEST(test_createNumbers_returns_valid_array); - RUN_TEST(test_createNumbers_contains_exactly_one_duplicate); - RUN_TEST(test_getDuplicated_finds_correct_duplicate); - + RUN_TEST(test_push_created_new_stacknode); return UNITY_END(); } \ No newline at end of file