Template
Compare commits
4
Commits
main
..
simons_zweig
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4cfe6d9c50 | ||
|
|
82c72eaf81 | ||
|
|
a027c070d2 | ||
|
|
94517bf236 |
+4
-62
@@ -1,62 +1,4 @@
|
|||||||
# ---> C
|
doble_initial.exe
|
||||||
# Prerequisites
|
highscores.txt
|
||||||
*.d
|
runStackTest.exe
|
||||||
|
stack.o
|
||||||
# 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.
@@ -1,33 +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)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -29,14 +29,14 @@ 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_files): %.o: %.c
|
$(program_obj_filesobj_files): %.o: %.c
|
||||||
$(CC) -c $(FLAGS) $^ -o $@
|
$(CC) -c $(FLAGS) $^ -o $@
|
||||||
|
|
||||||
# --------------------------
|
# --------------------------
|
||||||
# Unit Tests
|
# Unit Tests
|
||||||
# --------------------------
|
# --------------------------
|
||||||
unitTests:
|
unitTests: stack.o test_stack.c $(unityfolder)/unity.c
|
||||||
echo "needs to be implemented"
|
$(CC) $(FLAGS) -I$(unityfolder) -o runStackTest test_stack.c stack.o $(unityfolder)/unity.c
|
||||||
|
|
||||||
# --------------------------
|
# --------------------------
|
||||||
# Clean
|
# Clean
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
#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 = *(int *)data;
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,10 @@ 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 Node {
|
||||||
|
int value;
|
||||||
|
struct Node* 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);
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "stack.h"
|
||||||
|
#include "unity.h"
|
||||||
|
|
||||||
|
void test_push(void)
|
||||||
|
{
|
||||||
|
StackNode *testNode;
|
||||||
|
int data = 1;
|
||||||
|
|
||||||
|
// Test für leeren Stack
|
||||||
|
testNode = push(NULL, &data);
|
||||||
|
TEST_ASSERT_NOT_NULL(&testNode);
|
||||||
|
TEST_ASSERT_NULL(testNode->next);
|
||||||
|
TEST_ASSERT_EQUAL_INT(1, testNode->value);
|
||||||
|
|
||||||
|
data = 2;
|
||||||
|
|
||||||
|
// Test für nicht leeren Stack
|
||||||
|
testNode = push(testNode, &data);
|
||||||
|
TEST_ASSERT_NOT_NULL(&testNode);
|
||||||
|
TEST_ASSERT_NOT_NULL(testNode->next);
|
||||||
|
TEST_ASSERT_NULL(testNode->next->next);
|
||||||
|
TEST_ASSERT_EQUAL_INT(1, testNode->value);
|
||||||
|
TEST_ASSERT_EQUAL_INT(2, testNode->next->value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_pop(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
TEST_ASSERT_NULL(pop(NULL));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_top(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
TEST_ASSERT_NULL(top(NULL));
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_clear(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
// TEST_ASSERT_NULL(clearStack(NULL));
|
||||||
|
}
|
||||||
|
|
||||||
|
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_push);
|
||||||
|
RUN_TEST(test_pop);
|
||||||
|
RUN_TEST(test_top);
|
||||||
|
RUN_TEST(test_clear);
|
||||||
|
|
||||||
|
return UNITY_END();
|
||||||
|
}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
#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