diff --git a/makefile b/makefile index 75e302c..542b37c 100644 --- a/makefile +++ b/makefile @@ -50,6 +50,11 @@ bintree: bintree.c bintreeTests: bintree.o bintreeTests.c $(unityfolder)/unity.c $(CC) $(FLAGS) -o runbintreeTests bintreeTests.c bintree.o $(unityfolder)/unity.c +stack: stack.c + $(CC) $(FLAGS) -c stack stack.c + +test_stack: stack.o test_stack.c $(unityfolder)/unity.c + $(CC) $(FLAGS) -o runstackTests test_stack.c stack.o $(unityfolder)/unity.c # -------------------------- # Clean # -------------------------- diff --git a/test_stack.c b/test_stack.c index 26a219f..2576f65 100644 --- a/test_stack.c +++ b/test_stack.c @@ -1,24 +1,30 @@ #include #include +#include "unity.h" #include "stack.h" +void setUp(void) { + // Falls notwendig, kann hier Vorbereitungsarbeit gemacht werden +} + +void tearDown(void) { + // Hier kann Bereinigungsarbeit nach jedem Test durchgeführt werden +} + + + void testeStackBeschreiben() { - printf("=== Test: push() ===\n"); + //printf("=== Test: push() ===\n"); StackNode *stack = NULL; int wert1 = 42; stack = push(stack, &wert1); int *topValue = (int *)(stack->data); - if(topValue != NULL && *topValue == 42) - { - printf("Test 1: Erstes Element erfolgreich gepusht!\n"); - } - else - { - printf("Test 1: FEHLGESCHLAGEN!\n"); - } + + TEST_ASSERT_NOT_NULL(topValue); + TEST_ASSERT_EQUAL_INT(42, *topValue); int wert2 = 12; @@ -27,23 +33,19 @@ void testeStackBeschreiben() topValue = (int *)(stack->data); int *secondValue = (int *)((stack->next)->data); - if(topValue != NULL && *topValue == 12.25 && secondValue != NULL && *secondValue == 42) - { - printf("Test 2: Zweites Element erfolgreich gepusht!\n"); - } - else - { - printf("Test 2: FEHLGESCHLAGEN!\n"); - } + TEST_ASSERT_NOT_NULL(topValue); + TEST_ASSERT_EQUAL_INT(12, *topValue); + TEST_ASSERT_NOT_NULL(secondValue); + TEST_ASSERT_EQUAL_INT(42, *secondValue); - printf("=== Ende Test: push() ===\n\n"); + //printf("=== Ende Test: push() ===\n\n"); return; } void testepop() { - printf("=== Test: pop() ===\n"); + //printf("=== Test: pop() ===\n"); StackNode *stack = NULL; int wert1 = 20; @@ -56,21 +58,15 @@ void testepop() int *topValue = (int *)(stack->data); - if(topValue != NULL && *topValue == 20) - { - printf("Test: Erstes Element erfolgreich gelöscht!\n"); - } - else - { - printf("Test 1: FEHLGESCHLAGEN!\n"); - } + TEST_ASSERT_NOT_NULL(topValue); + TEST_ASSERT_EQUAL_INT(20, *topValue); - printf("=== Ende Test: pop() ===\n\n"); + //printf("=== Ende Test: pop() ===\n\n"); } void testetop() { - printf("=== Test: top() ===\n"); + //printf("=== Test: top() ===\n"); StackNode *stack = NULL; int wert1 = 20; @@ -81,21 +77,15 @@ void testetop() int *topValue = top(stack); - if(topValue != NULL && *topValue == 74) - { - printf("Test: top() gibt korrektes Element zurück!\n"); - } - else - { - printf("Test: FEHLGESCHLAGEN!\n"); - } + TEST_ASSERT_NOT_NULL(topValue); + TEST_ASSERT_EQUAL_INT(74, *topValue); - printf("=== Ende Test: top() ===\n\n"); + //printf("=== Ende Test: top() ===\n\n"); } void testeclearStack() { - printf("=== Test: clearStack() ===\n"); + //printf("=== Test: clearStack() ===\n"); StackNode *stack = NULL; int wert1 = 20; @@ -106,16 +96,25 @@ void testeclearStack() clearStack(stack); - printf("Test: clearStack() aufgerufen. Speicher freigegeben.\n"); - printf("=== Ende Test: clearStack() ===\n\n"); + //printf("Test: clearStack() aufgerufen. Speicher freigegeben.\n"); + //printf("=== Ende Test: clearStack() ===\n\n"); } int main() { - testeStackBeschreiben(); + UNITY_BEGIN(); + + //printf("..."); + + RUN_TEST(testeStackBeschreiben); + RUN_TEST(testepop); + RUN_TEST(testetop); + RUN_TEST(testeclearStack); + + /*testeStackBeschreiben(); testepop(); testetop(); - testeclearStack(); + testeclearStack();*/ - return 0; + return UNITY_END(); } \ No newline at end of file