generated from freudenreichan/info2Praktikum-DobleSpiel
Implement stack + unit tests
This commit is contained in:
parent
ce66b2546e
commit
e1ef9ac76b
13
makefile
13
makefile
@ -29,14 +29,19 @@ program_obj_files = stack.o bintree.o numbers.o timer.o highscore.o
|
|||||||
doble : main.o $(program_obj_files)
|
doble : main.o $(program_obj_files)
|
||||||
$(CC) $(FLAGS) $^ -o doble
|
$(CC) $(FLAGS) $^ -o doble
|
||||||
|
|
||||||
$(program_obj_filesobj_files): %.o: %.c
|
%.o: %.c
|
||||||
$(CC) -c $(FLAGS) $^ -o $@
|
$(CC) -c $(FLAGS) $< -o $@
|
||||||
|
|
||||||
|
|
||||||
# --------------------------
|
# --------------------------
|
||||||
# Unit Tests
|
# Unit Tests
|
||||||
# --------------------------
|
# --------------------------
|
||||||
unitTests:
|
test_stack: test_stack.c stack.o
|
||||||
echo "needs to be implemented"
|
$(CC) $(FLAGS) test_stack.c stack.o -o test_stack.exe
|
||||||
|
|
||||||
|
unitTests: test_stack
|
||||||
|
./test_stack.exe
|
||||||
|
|
||||||
|
|
||||||
# --------------------------
|
# --------------------------
|
||||||
# Clean
|
# Clean
|
||||||
|
|||||||
21
test_stack.c
21
test_stack.c
@ -5,6 +5,9 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "stack.h"
|
#include "stack.h"
|
||||||
|
|
||||||
|
#define TEST(description, condition) \
|
||||||
|
printf("%-40s: %s\n", description, (condition) ? "OK" : "FAIL")
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
StackNode *stack = NULL;
|
StackNode *stack = NULL;
|
||||||
@ -17,21 +20,33 @@ int main(void)
|
|||||||
*a = 10;
|
*a = 10;
|
||||||
*b = 20;
|
*b = 20;
|
||||||
|
|
||||||
|
|
||||||
|
printf("Starte Unit Tests fuer Stack\n");
|
||||||
stack = push(stack, a);
|
stack = push(stack, a);
|
||||||
stack = push(stack, b);
|
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
|
// pop test
|
||||||
stack = pop(stack);
|
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
|
// clearStack test
|
||||||
printf("fuehre ClearStack aus...\n");
|
|
||||||
|
|
||||||
clearStack(stack);
|
clearStack(stack);
|
||||||
|
stack = NULL;
|
||||||
|
|
||||||
|
TEST("clearStack ausgefuehrt (kein crash)", 1);
|
||||||
|
|
||||||
free(a);
|
free(a);
|
||||||
free(b);
|
free(b);
|
||||||
|
|||||||
BIN
test_stack.exe
BIN
test_stack.exe
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user