generated from freudenreichan/info2Praktikum-DobleSpiel
Compare commits
No commits in common. "850c7ed7989e3371afb4c6e61ddb34d8988b66f8" and "510edf85859637799b1b334b2bf6c5deff0adb80" have entirely different histories.
850c7ed798
...
510edf8585
@ -1,7 +1,3 @@
|
|||||||
<<<<<<< HEAD
|
|
||||||
Alex;14964
|
|
||||||
=======
|
|
||||||
player_name;7977
|
player_name;7977
|
||||||
player_name;7952
|
player_name;7952
|
||||||
>>>>>>> 510edf85859637799b1b334b2bf6c5deff0adb80
|
|
||||||
player1;3999
|
player1;3999
|
||||||
|
|||||||
34
makefile
34
makefile
@ -1,5 +1,5 @@
|
|||||||
CC = gcc
|
CC = gcc
|
||||||
CFLAGS = -g -Wall -lm
|
FLAGS = -g -Wall -lm
|
||||||
|
|
||||||
ifeq ($(OS),Windows_NT)
|
ifeq ($(OS),Windows_NT)
|
||||||
include makefile_windows.variables
|
include makefile_windows.variables
|
||||||
@ -24,40 +24,26 @@ doble_initial:
|
|||||||
# --------------------------
|
# --------------------------
|
||||||
# Selbst implementiertes Programm bauen
|
# Selbst implementiertes Programm bauen
|
||||||
# --------------------------
|
# --------------------------
|
||||||
program_obj_files = main.o stack.o bintree.o numbers.o timer.o highscore.o
|
program_obj_files = stack.o bintree.o numbers.o timer.o highscore.o
|
||||||
|
|
||||||
doble : $(program_obj_files)
|
doble : main.o $(program_obj_files)
|
||||||
$(CC) $(CFLAGS) $^ -o doble
|
$(CC) $(FLAGS) $^ -o doble
|
||||||
|
|
||||||
|
$(program_obj_filesobj_files): %.o: %.c
|
||||||
|
$(CC) -c $(FLAGS) $^ -o $@
|
||||||
|
|
||||||
# --------------------------
|
# --------------------------
|
||||||
# Unit Tests
|
# Unit Tests
|
||||||
# --------------------------
|
# --------------------------
|
||||||
TEST_STACK_EXEC = runtest_stack.exe
|
unitTests:
|
||||||
|
echo "needs to be implemented"
|
||||||
unitTests: $(TEST_STACK_EXEC)
|
|
||||||
@echo "--- Starte Stack Unit Tests ---"
|
|
||||||
@echo "Versuche auszuführen: $(TEST_STACK_EXEC)"
|
|
||||||
$(TEST_STACK_EXEC)
|
|
||||||
@echo "--- Stack Unit Tests abgeschlossen ---"
|
|
||||||
|
|
||||||
$(TEST_STACK_EXEC): test_stack.o stack.o
|
|
||||||
$(CC) $(CFLAGS) -I$(unityfolder) test_stack.o stack.o $(unityfolder)/unity.c -o $@ $(BINARIES)/libdoble_complete.a
|
|
||||||
|
|
||||||
test_stack.o: test_stack.c
|
|
||||||
$(CC) -c $(CFLAGS) -I$(unityfolder) $< -o $@
|
|
||||||
|
|
||||||
%.o: %.c
|
|
||||||
$(CC) -c $(CFLAGS) $< -o $@
|
|
||||||
|
|
||||||
# --------------------------
|
# --------------------------
|
||||||
# Clean
|
# Clean
|
||||||
# --------------------------
|
# --------------------------
|
||||||
clean:
|
clean:
|
||||||
ifeq ($(OS),Windows_NT)
|
ifeq ($(OS),Windows_NT)
|
||||||
del /f *.o *.exe doble $(TEST_STACK_EXEC)
|
del /f *.o doble
|
||||||
else
|
else
|
||||||
rm -f *.o *.exe doble $(TEST_STACK_EXEC)
|
rm -f *.o doble
|
||||||
endif
|
endif
|
||||||
|
|
||||||
.PHONY: doble_initial doble unitTests $(TEST_STACK_EXEC) clean
|
|
||||||
41
stack.c
41
stack.c
@ -10,59 +10,24 @@
|
|||||||
// 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)
|
||||||
{
|
{
|
||||||
StackNode *newNode = (StackNode *)malloc(sizeof(StackNode));
|
|
||||||
|
|
||||||
if(!newNode) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
newNode->data = data;
|
|
||||||
|
|
||||||
newNode->next = stack;
|
|
||||||
|
|
||||||
return newNode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deletes the top element of the stack (latest added element) and releases its memory.
|
// Deletes the top element of the stack (latest added element) and releases its memory. (Pointer to data has to be
|
||||||
// (Pointer to data has to be freed by caller.)
|
// freed by caller.)
|
||||||
StackNode *pop(StackNode *stack)
|
StackNode *pop(StackNode *stack)
|
||||||
{
|
{
|
||||||
if(!stack) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
StackNode *topNode = stack;
|
|
||||||
|
|
||||||
stack = stack->next;
|
|
||||||
|
|
||||||
free(topNode);
|
|
||||||
|
|
||||||
return stack;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the data of the top element.
|
// Returns the data of the top element.
|
||||||
void *top(StackNode *stack)
|
void *top(StackNode *stack)
|
||||||
{
|
{
|
||||||
if(!stack){
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return stack->data;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clears stack and releases all memory.
|
// Clears stack and releases all memory.
|
||||||
StackNode *clearStack(StackNode *stack)
|
void clearStack(StackNode *stack)
|
||||||
{
|
{
|
||||||
StackNode *current = stack;
|
|
||||||
StackNode *next_node;
|
|
||||||
|
|
||||||
|
|
||||||
while(current){
|
|
||||||
next_node = current->next;
|
|
||||||
free(current);
|
|
||||||
current = next_node;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
7
stack.h
7
stack.h
@ -8,10 +8,6 @@ The latest element is taken from the stack. */
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
//TODO: passenden Datentyp als struct anlegen
|
//TODO: passenden Datentyp als struct anlegen
|
||||||
typedef struct StackNode {
|
|
||||||
void *data;
|
|
||||||
struct StackNode *next;
|
|
||||||
}StackNode;
|
|
||||||
|
|
||||||
// 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);
|
||||||
@ -24,7 +20,6 @@ StackNode *pop(StackNode *stack);
|
|||||||
void *top(StackNode *stack);
|
void *top(StackNode *stack);
|
||||||
|
|
||||||
// Clears stack and releases all memory.
|
// Clears stack and releases all memory.
|
||||||
StackNode *clearStack(StackNode *stack);
|
void clearStack(StackNode *stack);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
67
test_stack.c
67
test_stack.c
@ -1,67 +0,0 @@
|
|||||||
#include <stdlib.h>
|
|
||||||
#include "unity/unity.h"
|
|
||||||
#include "stack.h"
|
|
||||||
|
|
||||||
void setUp(void) {}
|
|
||||||
void tearDown(void) {}
|
|
||||||
|
|
||||||
static StackNode *stack = NULL; // Für gemeinsame Benutzung in Tests
|
|
||||||
|
|
||||||
void test_push_and_top_should_return_last_integer(void) {
|
|
||||||
int *v1 = malloc(sizeof(int));
|
|
||||||
int *v2 = malloc(sizeof(int));
|
|
||||||
int *v3 = malloc(sizeof(int));
|
|
||||||
*v1 = 12; *v2 = 34; *v3 = 56;
|
|
||||||
|
|
||||||
// Push Werte auf Stack
|
|
||||||
stack = push(stack, v1);
|
|
||||||
TEST_ASSERT_NOT_NULL(stack);
|
|
||||||
TEST_ASSERT_EQUAL_INT(12, *(int *)top(stack));
|
|
||||||
|
|
||||||
stack = push(stack, v2);
|
|
||||||
TEST_ASSERT_EQUAL_INT(34, *(int *)top(stack));
|
|
||||||
|
|
||||||
stack = push(stack, v3);
|
|
||||||
TEST_ASSERT_EQUAL_INT(56, *(int *)top(stack));
|
|
||||||
|
|
||||||
// Ressourcen werden in anderem Test wieder entfernt!
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_pop_should_remove_and_free_integers(void) {
|
|
||||||
// Gibt die gleichen Werte wie im vorherigen Push-Test frei
|
|
||||||
int *val;
|
|
||||||
|
|
||||||
val = top(stack);
|
|
||||||
TEST_ASSERT_EQUAL_INT(56, *val);
|
|
||||||
free(val);
|
|
||||||
stack = pop(stack);
|
|
||||||
|
|
||||||
val = top(stack);
|
|
||||||
TEST_ASSERT_EQUAL_INT(34, *val);
|
|
||||||
free(val);
|
|
||||||
stack = pop(stack);
|
|
||||||
|
|
||||||
val = top(stack);
|
|
||||||
TEST_ASSERT_EQUAL_INT(12, *val);
|
|
||||||
free(val);
|
|
||||||
stack = pop(stack);
|
|
||||||
|
|
||||||
TEST_ASSERT_NULL(stack);
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_stack_empty_behavior(void) {
|
|
||||||
// Nach allen pops/clear-Operationen sollte Stack NULL sein
|
|
||||||
TEST_ASSERT_NULL(top(stack));
|
|
||||||
StackNode *tmp = pop(stack);
|
|
||||||
TEST_ASSERT_NULL(tmp);
|
|
||||||
stack = clearStack(stack); // Sollte NULL bleiben
|
|
||||||
TEST_ASSERT_NULL(stack);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(void) {
|
|
||||||
UNITY_BEGIN();
|
|
||||||
RUN_TEST(test_push_and_top_should_return_last_integer);
|
|
||||||
RUN_TEST(test_pop_should_remove_and_free_integers);
|
|
||||||
RUN_TEST(test_stack_empty_behavior);
|
|
||||||
return UNITY_END();
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user