diff --git a/makefile b/makefile index 1f15f75..84d7bb4 100644 --- a/makefile +++ b/makefile @@ -29,14 +29,19 @@ program_obj_files = stack.o bintree.o numbers.o timer.o highscore.o doble : main.o $(program_obj_files) $(CC) $(FLAGS) $^ -o doble -$(program_obj_filesobj_files): %.o: %.c - $(CC) -c $(FLAGS) $^ -o $@ +%.o: %.c + $(CC) -c $(FLAGS) $< -o $@ + # -------------------------- # Unit Tests # -------------------------- -unitTests: - echo "needs to be implemented" +test_stack: test_stack.c stack.o + $(CC) $(FLAGS) test_stack.c stack.o -o test_stack.exe + +unitTests: test_stack + ./test_stack.exe + # -------------------------- # Clean diff --git a/stack.o b/stack.o new file mode 100644 index 0000000..6d7ac52 Binary files /dev/null and b/stack.o differ diff --git a/test_stack.c b/test_stack.c index 792657f..f6f1377 100644 --- a/test_stack.c +++ b/test_stack.c @@ -5,6 +5,9 @@ #include #include "stack.h" +#define TEST(description, condition) \ + printf("%-40s: %s\n", description, (condition) ? "OK" : "FAIL") + int main(void) { StackNode *stack = NULL; @@ -17,21 +20,33 @@ int main(void) *a = 10; *b = 20; + + printf("Starte Unit Tests fuer Stack\n"); stack = push(stack, a); stack = push(stack, b); - printf("Top sollte 20 sein, es kommt %d raus\n", *(int*)top(stack)); + TEST("Top nach zwei Pushes == 20", *(int*)top(stack) == 20); // pop test stack = pop(stack); - printf("Top sollte jetzt 10 sein, es kommt %d raus\n", *(int*)top(stack)); + TEST("Top == 10 nach Pop", *(int*)top(stack) == 10); + stack = pop(stack); + TEST("Stack leer nach zwei Pops", stack == NULL); + + + + stack = push(stack, a); + stack = push(stack, b); + // clearStack test - printf("fuehre ClearStack aus...\n"); clearStack(stack); + stack = NULL; + + TEST("clearStack ausgefuehrt (kein crash)", 1); free(a); free(b); diff --git a/test_stack.exe b/test_stack.exe index 87c27a3..f931938 100644 Binary files a/test_stack.exe and b/test_stack.exe differ