generated from freudenreichan/info2Praktikum-DobleSpiel
Numbers Test erfolgreich ebstanden
This commit is contained in:
parent
dcc90edfa3
commit
37f38cbc7d
66
makefile
66
makefile
@ -1,66 +1,66 @@
|
|||||||
CC = gcc
|
CC = gcc
|
||||||
FLAGS = -g -Wall -lm
|
FLAGS = -g -Wall -I$(unityfolder)
|
||||||
|
|
||||||
|
|
||||||
ifeq ($(OS),Windows_NT)
|
ifeq ($(OS),Windows_NT)
|
||||||
include makefile_windows.variables
|
include makefile_windows.variables
|
||||||
else
|
else
|
||||||
UNAME = $(shell uname)
|
UNAME = $(shell uname)
|
||||||
ifeq ($(UNAME),Linux)
|
ifeq ($(UNAME),Linux)
|
||||||
include makefile_linux.variables
|
include makefile_linux.variables
|
||||||
else
|
else
|
||||||
include makefile_mac.variables
|
include makefile_mac.variables
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
raylibfolder = ./raylib
|
raylibfolder = ./raylib
|
||||||
unityfolder = ./unity
|
unityfolder = ./unity
|
||||||
|
|
||||||
# --------------------------
|
# --------------------------
|
||||||
# Initiales Programm bauen (zum ausprobieren)
|
# Initiales Programm
|
||||||
# --------------------------
|
# --------------------------
|
||||||
doble_initial:
|
doble_initial:
|
||||||
$(CC) -o doble_initial $(BINARIES)/libdoble_complete.a
|
$(CC) -o doble_initial $(BINARIES)/libdoble_complete.a
|
||||||
|
|
||||||
# --------------------------
|
# --------------------------
|
||||||
# Selbst implementiertes Programm bauen
|
# Objektdateien
|
||||||
# --------------------------
|
# --------------------------
|
||||||
program_obj_files = stack.o bintree.o numbers.o timer.o highscore.o
|
program_obj_files = stack.o bintree.o numbers.o timer.o highscore.o
|
||||||
|
|
||||||
doble : main.o $(program_obj_files)
|
# Generische Regel für alle .o-Dateien
|
||||||
$(CC) $(FLAGS) $^ -o doble
|
%.o: %.c
|
||||||
|
$(CC) $(FLAGS) -c $< -o $@
|
||||||
|
|
||||||
$(program_obj_filesobj_files): %.o: %.c
|
# --------------------------
|
||||||
$(CC) -c $(FLAGS) $^ -o $@
|
# Hauptprogramm
|
||||||
|
# --------------------------
|
||||||
|
doble: main.o $(program_obj_files)
|
||||||
|
$(CC) $(FLAGS) $^ -o doble
|
||||||
|
|
||||||
# --------------------------
|
# --------------------------
|
||||||
# Unit Tests
|
# Unit Tests
|
||||||
# --------------------------
|
# --------------------------
|
||||||
unity_src = $(unityfolder)/unity.c
|
unitTests:
|
||||||
|
@echo "needs to be implemented"
|
||||||
|
|
||||||
unitTests: numbersTest stackTest bintreeTest
|
# Bintree Tests
|
||||||
# ./runNumbersTest
|
binTreeTests: stack.o bintree.o binTreeTests.c $(unityfolder)/unity.c
|
||||||
# ./runStackTest
|
$(CC) $(FLAGS) -o runbintreeTests binTreeTests.c bintree.o stack.o $(unityfolder)/unity.c
|
||||||
./runBintreeTest
|
|
||||||
|
|
||||||
numbersTest: numbers.o bintree.o stack.o numbersTest.c $(unity_src)
|
# Numbers Tests
|
||||||
$(CC) $(CFLAGS) $(LDFLAGS) -I$(unityfolder) $^ -o runNumbersTest
|
test_numbers: numbers_no_tree.o bintree.o stack.o test_numbers.c $(unityfolder)/unity.c
|
||||||
|
$(CC) $(FLAGS) -o run_numbersTests test_numbers.c numbers_no_tree.o bintree.o stack.o $(unityfolder)/unity.c
|
||||||
stackTest: stack.o stackTest.c $(unity_src)
|
|
||||||
$(CC) $(CFLAGS) $(LDFLAGS) -I$(unityfolder) $^ -o runStackTests
|
|
||||||
|
|
||||||
binTreeTest: bintree.o binTreeTest.c $(unity_src) stack.o
|
|
||||||
$(CC) $(CFLAGS) $(LDFLAGS) -I$(unityfolder) $^ -o runBinTreeTest
|
|
||||||
|
|
||||||
%.o: %.c
|
|
||||||
$(CC) -c $(CFLAGS) $< -o $@
|
|
||||||
|
|
||||||
|
# Stack Tests
|
||||||
|
test_stack: stack.o test_stack.c $(unityfolder)/unity.c
|
||||||
|
$(CC) $(FLAGS) -o runstackTests test_stack.c stack.o $(unityfolder)/unity.c
|
||||||
|
|
||||||
# --------------------------
|
# --------------------------
|
||||||
# Clean
|
# Clean
|
||||||
# --------------------------
|
# --------------------------
|
||||||
clean:
|
clean:
|
||||||
ifeq ($(OS),Windows_NT)
|
ifeq ($(OS),Windows_NT)
|
||||||
del /f *.o doble
|
del /f *.o doble runstackTests run_numbersTests runbintreeTests
|
||||||
else
|
else
|
||||||
rm -f *.o doble
|
rm -f *.o doble runstackTests run_numbersTests runbintreeTests
|
||||||
endif
|
endif
|
||||||
|
|||||||
BIN
numbers_no_tree.o
Normal file
BIN
numbers_no_tree.o
Normal file
Binary file not shown.
BIN
run_numbersTests.exe
Normal file
BIN
run_numbersTests.exe
Normal file
Binary file not shown.
19
stack.c
19
stack.c
@ -10,7 +10,11 @@
|
|||||||
// Pushes data as pointer onto the stack.
|
// Pushes data as pointer onto the stack.
|
||||||
StackNode *push(StackNode *stack, void *data)
|
StackNode *push(StackNode *stack, void *data)
|
||||||
{
|
{
|
||||||
if(stack && data){
|
if (!data)
|
||||||
|
{
|
||||||
|
return stack; //Nichts pushen
|
||||||
|
}
|
||||||
|
//if(stack && data){
|
||||||
StackNode *t = (StackNode *)malloc(sizeof(StackNode));
|
StackNode *t = (StackNode *)malloc(sizeof(StackNode));
|
||||||
if(!t)
|
if(!t)
|
||||||
{
|
{
|
||||||
@ -19,7 +23,7 @@ StackNode *push(StackNode *stack, void *data)
|
|||||||
t->next = stack;
|
t->next = stack;
|
||||||
t->data = data;
|
t->data = data;
|
||||||
return t; //Gibt den ersten StackNode des Stacks zurueck
|
return t; //Gibt den ersten StackNode des Stacks zurueck
|
||||||
}
|
//}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,12 +31,11 @@ StackNode *push(StackNode *stack, void *data)
|
|||||||
// freed by caller.)
|
// freed by caller.)
|
||||||
StackNode *pop(StackNode *stack)
|
StackNode *pop(StackNode *stack)
|
||||||
{
|
{
|
||||||
if(stack)
|
if(stack == NULL)
|
||||||
{
|
{
|
||||||
StackNode *t = stack->next; //Naechstes Element im Stack wird erstes Element
|
return NULL;
|
||||||
free(stack);
|
|
||||||
return t;
|
|
||||||
}
|
}
|
||||||
|
return stack->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the data of the top element.
|
// Returns the data of the top element.
|
||||||
@ -50,8 +53,8 @@ void clearStack(StackNode *stack)
|
|||||||
{
|
{
|
||||||
while(stack)
|
while(stack)
|
||||||
{
|
{
|
||||||
StackNode *tmp = stack;
|
StackNode *tmp = stack; //merkt sich den momentanen obersten Knoten
|
||||||
stack = stack->next;
|
stack = stack->next; //setzt den obersten Knoten auf den Zweiten im Stack
|
||||||
free(tmp->data);
|
free(tmp->data);
|
||||||
free(tmp);
|
free(tmp);
|
||||||
}
|
}
|
||||||
|
|||||||
64
stack_test.c
Normal file
64
stack_test.c
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "stack.h"
|
||||||
|
|
||||||
|
//Testfunkionen zu push, pull, top & clearStack schreiben
|
||||||
|
|
||||||
|
void test(char *name, int condition) {
|
||||||
|
if (condition) {
|
||||||
|
printf("[OK] %s\n", name);
|
||||||
|
} else {
|
||||||
|
printf("[FAIL] %s\n", name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
|
||||||
|
StackNode *stack = NULL;
|
||||||
|
|
||||||
|
// Werte dynamisch anlegen
|
||||||
|
int *val1 = malloc(sizeof(int));
|
||||||
|
*val1 = 5;
|
||||||
|
stack = push(stack, val1);
|
||||||
|
test("push(5) legt 5 oben auf den Stack", *(int*)stack->data == 5);
|
||||||
|
|
||||||
|
int *val2 = malloc(sizeof(int));
|
||||||
|
*val2 = 6;
|
||||||
|
stack = push(stack, val2);
|
||||||
|
test("push(6) legt 6 oben auf den Stack", *(int*)stack->data == 6);
|
||||||
|
|
||||||
|
int *val3 = malloc(sizeof(int));
|
||||||
|
*val3 = 24;
|
||||||
|
stack = push(stack, val3);
|
||||||
|
test("push(24) legt 24 oben auf den Stack", *(int*)stack->data == 24);
|
||||||
|
|
||||||
|
// Test top()
|
||||||
|
int t = *(int*)top(stack);
|
||||||
|
test("top() liefert 24", t == 24);
|
||||||
|
|
||||||
|
// Test pop()
|
||||||
|
StackNode *tmp;
|
||||||
|
|
||||||
|
tmp = stack;
|
||||||
|
stack = pop(stack);
|
||||||
|
free(tmp->data); // Daten freigeben
|
||||||
|
free(tmp); // Knoten freigeben
|
||||||
|
test("pop() entfernt 24, 6 ist jetzt oben", *(int*)stack->data == 6);
|
||||||
|
|
||||||
|
tmp = stack;
|
||||||
|
stack = pop(stack);
|
||||||
|
free(tmp->data);
|
||||||
|
free(tmp);
|
||||||
|
test("pop() entfernt 6, 5 ist jetzt oben", *(int*)stack->data == 5);
|
||||||
|
|
||||||
|
tmp = stack;
|
||||||
|
stack = pop(stack);
|
||||||
|
free(tmp->data);
|
||||||
|
free(tmp);
|
||||||
|
test("pop() entfernt 5, Stack ist jetzt leer", stack == NULL);
|
||||||
|
|
||||||
|
// Am Ende Stack leeren (falls noch Elemente übrig)
|
||||||
|
clearStack(stack);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user