forked from freudenreichan/info2Praktikum-DobleSpiel
Compare commits
6
Commits
nick_branch
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e7a872252a | ||
|
|
de9e0a3357 | ||
|
|
746b9b7219 | ||
|
|
1f3fba80ec | ||
|
|
1d363980f6 | ||
|
|
4ce3a6aac0
|
No files matched your search
+62
-4
@@ -1,4 +1,62 @@
|
||||
doble_initial.exe
|
||||
highscores.txt
|
||||
runStackTest.exe
|
||||
stack.o
|
||||
# ---> C
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
||||
# Object files
|
||||
*.o
|
||||
*.ko
|
||||
*.obj
|
||||
*.elf
|
||||
|
||||
# Linker output
|
||||
*.ilk
|
||||
*.map
|
||||
*.exp
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Libraries
|
||||
*.lib
|
||||
*.la
|
||||
*.lo
|
||||
|
||||
# Shared objects (inc. Windows DLLs)
|
||||
*.dll
|
||||
*.so
|
||||
*.so.*
|
||||
*.dylib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
*.i*86
|
||||
*.x86_64
|
||||
*.hex
|
||||
Startcode/doble_initial
|
||||
Startcode/doble
|
||||
Startcode/unitTests
|
||||
|
||||
# Debug files
|
||||
*.dSYM/
|
||||
*.su
|
||||
*.idb
|
||||
*.pdb
|
||||
|
||||
# Kernel Module Compile Results
|
||||
*.mod*
|
||||
*.cmd
|
||||
.tmp_versions/
|
||||
modules.order
|
||||
Module.symvers
|
||||
Mkfile.old
|
||||
dkms.conf
|
||||
|
||||
# IDE folders
|
||||
.vscode/
|
||||
.idea/
|
||||
|
||||
# macOS
|
||||
.DS_Store
|
||||
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -1,49 +1,49 @@
|
||||
CC = gcc
|
||||
FLAGS = -g -Wall -lm
|
||||
|
||||
ifeq ($(OS),Windows_NT)
|
||||
include makefile_windows.variables
|
||||
else
|
||||
UNAME = $(shell uname)
|
||||
ifeq ($(UNAME),Linux)
|
||||
include makefile_linux.variables
|
||||
else
|
||||
include makefile_mac.variables
|
||||
endif
|
||||
endif
|
||||
|
||||
raylibfolder = ./raylib
|
||||
unityfolder = ./unity
|
||||
|
||||
# --------------------------
|
||||
# Initiales Programm bauen (zum ausprobieren)
|
||||
# --------------------------
|
||||
doble_initial:
|
||||
$(CC) -o doble_initial $(BINARIES)/libdoble_complete.a
|
||||
|
||||
# --------------------------
|
||||
# Selbst implementiertes Programm bauen
|
||||
# --------------------------
|
||||
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 $@
|
||||
|
||||
# --------------------------
|
||||
# Unit Tests
|
||||
# --------------------------
|
||||
unitTests: stack.o test_stack.c $(unityfolder)/unity.c
|
||||
$(CC) $(FLAGS) -I$(unityfolder) -o runStackTest test_stack.c stack.o $(unityfolder)/unity.c
|
||||
|
||||
# --------------------------
|
||||
# Clean
|
||||
# --------------------------
|
||||
clean:
|
||||
ifeq ($(OS),Windows_NT)
|
||||
del /f *.o doble
|
||||
else
|
||||
rm -f *.o doble
|
||||
CC = gcc
|
||||
FLAGS = -g -Wall -lm
|
||||
|
||||
ifeq ($(OS),Windows_NT)
|
||||
include makefile_windows.variables
|
||||
else
|
||||
UNAME = $(shell uname)
|
||||
ifeq ($(UNAME),Linux)
|
||||
include makefile_linux.variables
|
||||
else
|
||||
include makefile_mac.variables
|
||||
endif
|
||||
endif
|
||||
|
||||
raylibfolder = ./raylib
|
||||
unityfolder = ./unity
|
||||
|
||||
# --------------------------
|
||||
# Initiales Programm bauen (zum ausprobieren)
|
||||
# --------------------------
|
||||
doble_initial:
|
||||
$(CC) -o doble_initial $(BINARIES)/libdoble_complete.a
|
||||
|
||||
# --------------------------
|
||||
# Selbst implementiertes Programm bauen
|
||||
# --------------------------
|
||||
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_files): %.o: %.c
|
||||
$(CC) -c $(FLAGS) $^ -o $@
|
||||
|
||||
# --------------------------
|
||||
# Unit Tests
|
||||
# --------------------------
|
||||
unitTests:
|
||||
echo "needs to be implemented"
|
||||
|
||||
# --------------------------
|
||||
# Clean
|
||||
# --------------------------
|
||||
clean:
|
||||
ifeq ($(OS),Windows_NT)
|
||||
del /f *.o doble
|
||||
else
|
||||
rm -f *.o doble
|
||||
endif
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,33 @@
|
||||
#include <stdlib.h>
|
||||
#include "stack.h"
|
||||
|
||||
//TODO: grundlegende Stackfunktionen implementieren:
|
||||
/* * `push`: legt ein Element oben auf den Stack,
|
||||
* `pop`: entfernt das oberste Element,
|
||||
* `top`: liefert das oberste Element zurück,
|
||||
* `clearStack`: gibt den gesamten Speicher frei. */
|
||||
|
||||
// Pushes data as pointer onto the stack.
|
||||
StackNode *push(StackNode *stack, void *data)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Deletes the top element of the stack (latest added element) and releases its memory. (Pointer to data has to be
|
||||
// freed by caller.)
|
||||
StackNode *pop(StackNode *stack)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Returns the data of the top element.
|
||||
void *top(StackNode *stack)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Clears stack and releases all memory.
|
||||
void clearStack(StackNode *stack)
|
||||
{
|
||||
|
||||
}
|
||||
+25
-29
@@ -1,29 +1,25 @@
|
||||
#ifndef STACK_H
|
||||
#define STACK_H
|
||||
|
||||
/* A stack is a special type of queue which uses the LIFO (last in, first out) principle.
|
||||
This means that with each new element all other elements are pushed deeper into the stack.
|
||||
The latest element is taken from the stack. */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
//TODO: passenden Datentyp als struct anlegen
|
||||
typedef struct Node {
|
||||
int value;
|
||||
struct Node* next;
|
||||
} StackNode;
|
||||
|
||||
// Pushes data as pointer onto the stack.
|
||||
StackNode *push(StackNode *stack, void *data);
|
||||
|
||||
// Deletes the top element of the stack (latest added element) and releases its memory. (Pointer to data has to be
|
||||
// freed by caller.)
|
||||
StackNode *pop(StackNode *stack);
|
||||
|
||||
// Returns the data of the top element.
|
||||
void *top(StackNode *stack);
|
||||
|
||||
// Clears stack and releases all memory.
|
||||
void clearStack(StackNode *stack);
|
||||
|
||||
#endif
|
||||
#ifndef STACK_H
|
||||
#define STACK_H
|
||||
|
||||
/* A stack is a special type of queue which uses the LIFO (last in, first out) principle.
|
||||
This means that with each new element all other elements are pushed deeper into the stack.
|
||||
The latest element is taken from the stack. */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
//TODO: passenden Datentyp als struct anlegen
|
||||
|
||||
// Pushes data as pointer onto the stack.
|
||||
StackNode *push(StackNode *stack, void *data);
|
||||
|
||||
// Deletes the top element of the stack (latest added element) and releases its memory. (Pointer to data has to be
|
||||
// freed by caller.)
|
||||
StackNode *pop(StackNode *stack);
|
||||
|
||||
// Returns the data of the top element.
|
||||
void *top(StackNode *stack);
|
||||
|
||||
// Clears stack and releases all memory.
|
||||
void clearStack(StackNode *stack);
|
||||
|
||||
#endif
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -1,91 +0,0 @@
|
||||
#include <stdlib.h>
|
||||
#include "stack.h"
|
||||
|
||||
// TODO: grundlegende Stackfunktionen implementieren:
|
||||
/* * `push`: legt ein Element oben auf den Stack,
|
||||
* `pop`: entfernt das oberste Element,
|
||||
* `top`: liefert das oberste Element zurück,
|
||||
* `clearStack`: gibt den gesamten Speicher frei. */
|
||||
|
||||
// Pushes data as pointer onto the stack.
|
||||
StackNode *push(StackNode *stack, void *data)
|
||||
{
|
||||
StackNode *tempNode, *newNode;
|
||||
|
||||
newNode = malloc(sizeof(StackNode));
|
||||
newNode->value = 3;
|
||||
newNode->next = NULL;
|
||||
|
||||
if (stack == NULL)
|
||||
{
|
||||
stack = newNode;
|
||||
return stack;
|
||||
}
|
||||
|
||||
tempNode = stack;
|
||||
while (tempNode->next != NULL)
|
||||
{
|
||||
tempNode = tempNode->next;
|
||||
}
|
||||
tempNode->next = newNode;
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
// Deletes the top element of the stack (latest added element) and releases its memory. (Pointer to data has to be
|
||||
// freed by caller.)
|
||||
StackNode *pop(StackNode *stack)
|
||||
{
|
||||
StackNode *tempNode;
|
||||
|
||||
if (stack == NULL)
|
||||
{
|
||||
return stack;
|
||||
}
|
||||
|
||||
tempNode = stack;
|
||||
while (tempNode->next->next != NULL)
|
||||
{
|
||||
tempNode = tempNode->next;
|
||||
}
|
||||
free(tempNode->next);
|
||||
tempNode->next = NULL;
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
// Returns the data of the top element.
|
||||
void *top(StackNode *stack)
|
||||
{
|
||||
StackNode *tempNode;
|
||||
|
||||
if (stack == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tempNode = stack;
|
||||
while (tempNode->next != NULL)
|
||||
{
|
||||
tempNode = tempNode->next;
|
||||
}
|
||||
|
||||
return &tempNode->value;
|
||||
}
|
||||
|
||||
// Clears stack and releases all memory.
|
||||
void clearStack(StackNode *stack)
|
||||
{
|
||||
StackNode *tempNode;
|
||||
|
||||
if (stack == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
tempNode = stack;
|
||||
while (tempNode != NULL)
|
||||
{
|
||||
tempNode = pop(tempNode);
|
||||
}
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "stack.h"
|
||||
#include "unity.h"
|
||||
|
||||
StackNode* setup(int value, StackNode* next) {
|
||||
StackNode* node = malloc(sizeof(StackNode)); // allocate memory on heap
|
||||
if (node == NULL) {
|
||||
perror("malloc failed");
|
||||
exit(EXIT_FAILURE); // or handle the error differently
|
||||
}
|
||||
node->value = value;
|
||||
node->next = next;
|
||||
return node;
|
||||
}
|
||||
|
||||
void test_pop(void)
|
||||
{
|
||||
StackNode* node2 = setup(3, NULL);
|
||||
StackNode* node1 = setup(2, node2);
|
||||
StackNode* header = setup(1, node1);
|
||||
StackNode* temp;
|
||||
|
||||
temp = pop(header);
|
||||
int after = 0;
|
||||
while(temp)
|
||||
{
|
||||
after++;
|
||||
temp = temp->next;
|
||||
}
|
||||
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(2, after);
|
||||
TEST_ASSERT_NULL(node1->next);
|
||||
}
|
||||
|
||||
void test_top(void)
|
||||
{
|
||||
StackNode* node2 = setup(3, NULL);
|
||||
StackNode* node1 = setup(2, node2);
|
||||
StackNode* header = setup(1, node1);
|
||||
|
||||
int data = *(int *)top(header);
|
||||
TEST_ASSERT_EQUAL_INT(node2->value, data);
|
||||
}
|
||||
|
||||
void test_clear()
|
||||
{
|
||||
StackNode* node2 = setup(3, NULL);
|
||||
StackNode* node1 = setup(2, node2);
|
||||
StackNode* header = setup(1, node1);
|
||||
StackNode* temp;
|
||||
|
||||
clearStack(header);
|
||||
temp = header;
|
||||
|
||||
int after = 0;
|
||||
while(temp)
|
||||
{
|
||||
after++;
|
||||
temp = temp->next;
|
||||
}
|
||||
|
||||
|
||||
TEST_ASSERT_NULL(after);
|
||||
}
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
// Falls notwendig, kann hier Vorbereitungsarbeit gemacht werden
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
// Hier kann Bereinigungsarbeit nach jedem Test durchgeführt werden
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
UNITY_BEGIN();
|
||||
|
||||
printf("============================\nStack tests\n============================\n");
|
||||
|
||||
RUN_TEST(test_pop);
|
||||
RUN_TEST(test_top);
|
||||
RUN_TEST(test_clear);
|
||||
|
||||
return UNITY_END();
|
||||
}
|
||||
-10
@@ -1,10 +0,0 @@
|
||||
#ifndef UNITTTESTS_H
|
||||
#define UNITTTESTS_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
typedef int (*UnitTestType)(void);
|
||||
|
||||
#define RUN_UNIT_TEST(fct) printf("%80s: %d\n", #fct, fct())
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user