generated from freudenreichan/info2Praktikum-DobleSpiel
Compare commits
10
Commits
833dd6b20c
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7e75758d1f | ||
|
|
593a86acaa | ||
|
|
74e2421312 | ||
|
|
ecd873b47c | ||
|
|
deb68dd71a | ||
|
|
d27b558ddc | ||
|
|
ef6946fa0b | ||
|
|
b7882d9e71 | ||
|
|
19b9fec1bf | ||
|
|
ec0909f4c9 |
No files matched your search
Binary file not shown.
@@ -14,13 +14,14 @@ static TreeNode *createNode(const void *data, size_t dataSize)
|
|||||||
if (!newNode)
|
if (!newNode)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
newNode->data = malloc(dataSize);
|
newNode->data = malloc(dataSize); // hier kein malloc -> nur data pointer?
|
||||||
if (!newNode->data)
|
if (!newNode->data)
|
||||||
{
|
{
|
||||||
free(newNode);
|
free(newNode);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
newNode->data = data;
|
// newNode->data = data;
|
||||||
|
memcpy(newNode->data, data, dataSize);
|
||||||
|
|
||||||
return newNode;
|
return newNode;
|
||||||
}
|
}
|
||||||
@@ -35,12 +36,11 @@ TreeNode *addToTree(TreeNode *root, const void *data, size_t dataSize, CompareFc
|
|||||||
*isDuplicate = 0;
|
*isDuplicate = 0;
|
||||||
}
|
}
|
||||||
if (!root)
|
if (!root)
|
||||||
{ // wurzerl == 0;
|
{ // wurzel == 0;
|
||||||
TreeNode *newNode = createNode(data, dataSize);
|
TreeNode *newNode = createNode(data, dataSize);
|
||||||
return newNode;
|
return newNode;
|
||||||
}
|
}
|
||||||
// wenn duplicate NUll -> doppelt hinzufügen
|
// wenn duplicate NUll -> doppelt hinzufügen
|
||||||
//
|
|
||||||
|
|
||||||
if (compareFct(data, root->data) < 0)
|
if (compareFct(data, root->data) < 0)
|
||||||
{
|
{
|
||||||
@@ -61,6 +61,8 @@ TreeNode *addToTree(TreeNode *root, const void *data, size_t dataSize, CompareFc
|
|||||||
root->right = addToTree(root->right, data, dataSize, compareFct, isDuplicate);
|
root->right = addToTree(root->right, data, dataSize, compareFct, isDuplicate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterates over the tree given by root. Follows the usage of strtok. If tree is NULL,
|
// Iterates over the tree given by root. Follows the usage of strtok. If tree is NULL,
|
||||||
@@ -123,12 +125,11 @@ void clearTree(TreeNode *root)
|
|||||||
// Returns the number of entries in the tree given by root.
|
// Returns the number of entries in the tree given by root.
|
||||||
unsigned int treeSize(const TreeNode *root)
|
unsigned int treeSize(const TreeNode *root)
|
||||||
{
|
{
|
||||||
unsigned int treeSize = 0;
|
if (root == NULL)
|
||||||
TreeNode* data = nextTreeData(root);
|
|
||||||
while (data != NULL)
|
|
||||||
{
|
{
|
||||||
treeSize++;
|
return 0;
|
||||||
data = nextTreeData(NULL);
|
|
||||||
}
|
}
|
||||||
return treeSize;
|
|
||||||
|
return 1 + treeSize(root->left) + treeSize(root->right);
|
||||||
|
/// ich + alles links + alles rechts
|
||||||
}
|
}
|
||||||
@@ -5,18 +5,19 @@
|
|||||||
|
|
||||||
typedef int (*CompareFctType)(const void *arg1, const void *arg2); // ganz zahlen
|
typedef int (*CompareFctType)(const void *arg1, const void *arg2); // ganz zahlen
|
||||||
|
|
||||||
void foo(void* ptr) {
|
/*void foo(void* ptr) {
|
||||||
unsigned int* casted_pointer = ptr;
|
unsigned int* casted_pointer = ptr;
|
||||||
unsigned int** a = &casted_pointer; //pointer pointer
|
unsigned int** a = &casted_pointer; //pointer pointer
|
||||||
unsigned int* b = casted_pointer; //pointer
|
unsigned int* b = casted_pointer; //pointer
|
||||||
unsigned int c = *casted_pointer; //wert
|
unsigned int c = *casted_pointer; //wert
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
typedef struct node
|
typedef struct nodeT
|
||||||
{
|
{
|
||||||
void *data;
|
void *data;
|
||||||
struct node *left;
|
struct nodeT *left;
|
||||||
struct node *right;
|
struct nodeT *right;
|
||||||
} TreeNode;
|
} TreeNode;
|
||||||
|
|
||||||
// Adds a copy of data's pointer destination to the tree using compareFct for ordering. Accepts duplicates
|
// Adds a copy of data's pointer destination to the tree using compareFct for ordering. Accepts duplicates
|
||||||
|
|||||||
+3
-5
@@ -1,5 +1,3 @@
|
|||||||
player2;17901
|
ÐÀ;1
|
||||||
player_name2;14920
|
ðÀ;0
|
||||||
player2;14844
|
°À;0
|
||||||
player_name;6977
|
|
||||||
player1;3999
|
|
||||||
@@ -14,7 +14,9 @@ int inputNumber(const char *promptText)
|
|||||||
{
|
{
|
||||||
printf("%s", promptText);
|
printf("%s", promptText);
|
||||||
numberOfInputs = scanf("%u", &number);
|
numberOfInputs = scanf("%u", &number);
|
||||||
while(getchar() != '\n') {} // clear input buffer
|
while (getchar() != '\n')
|
||||||
|
{
|
||||||
|
} // clear input buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
return number;
|
return number;
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
CC = gcc
|
CC = gcc
|
||||||
FLAGS = -g -Wall -lm
|
CFLAGS = -g -Wall
|
||||||
|
LIBS = -lm
|
||||||
|
|
||||||
ifeq ($(OS),Windows_NT)
|
ifeq ($(OS),Windows_NT)
|
||||||
include makefile_windows.variables
|
include makefile_windows.variables
|
||||||
|
RM_CMD = del /f
|
||||||
|
EXT = .exe
|
||||||
else
|
else
|
||||||
UNAME = $(shell uname)
|
UNAME = $(shell uname)
|
||||||
ifeq ($(UNAME),Linux)
|
ifeq ($(UNAME),Linux)
|
||||||
@@ -10,53 +13,67 @@ else
|
|||||||
else
|
else
|
||||||
include makefile_mac.variables
|
include makefile_mac.variables
|
||||||
endif
|
endif
|
||||||
|
RM_CMD = rm -f
|
||||||
|
EXT =
|
||||||
endif
|
endif
|
||||||
|
|
||||||
raylibfolder = ./raylib
|
raylibfolder = ./raylib
|
||||||
unityfolder = ./unity
|
unityfolder = ./unity
|
||||||
|
|
||||||
# --------------------------
|
# --------------------------
|
||||||
# Initiales Programm bauen (zum ausprobieren)
|
# Objekt-Dateien Definition
|
||||||
# --------------------------
|
|
||||||
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
|
program_obj_files = stack.o bintree.o numbers.o timer.o highscore.o
|
||||||
|
# main.o separat oder hier hinzufügen
|
||||||
|
OBJ = main.o $(program_obj_files)
|
||||||
|
|
||||||
doble : main.o $(program_obj_files)
|
# --------------------------
|
||||||
$(CC) $(FLAGS) $^ -o doble
|
# Initiales Programm
|
||||||
|
# --------------------------
|
||||||
|
doble_initial:
|
||||||
|
# Hinweis: $(BINARIES) muss in den include-Dateien definiert sein!
|
||||||
|
$(CC) -o doble_initial$(EXT) $(BINARIES)/libdoble_complete.a $(LIBS)
|
||||||
|
|
||||||
# HINWEIS: Hier war ein Tippfehler im Original (obj_filesobj_files), ich habe ihn korrigiert:
|
# --------------------------
|
||||||
$(program_obj_files): %.o: %.c
|
# Hauptprogramm (doble)
|
||||||
$(CC) -c $(FLAGS) $^ -o $@
|
# --------------------------
|
||||||
|
doble: $(OBJ)
|
||||||
|
# WICHTIG: $(LIBS) ganz am Ende!
|
||||||
|
$(CC) $(CFLAGS) $^ -o doble$(EXT) $(LIBS)
|
||||||
|
|
||||||
|
%.o: %.c
|
||||||
|
$(CC) -c $(CFLAGS) $< -o $@
|
||||||
|
|
||||||
# --------------------------
|
# --------------------------
|
||||||
# Unit Tests
|
# Unit Tests
|
||||||
# --------------------------
|
# --------------------------
|
||||||
# Name des Test-Programms
|
TEST_BIN = test_runner$(EXT)
|
||||||
TEST_BIN = test_runner
|
|
||||||
|
|
||||||
# Das Target 'unitTests' baut das Test-Programm und führt es aus
|
TEST_STACK_BIN = test_stack$(EXT)
|
||||||
# Es benötigt unittest.o und stack.o (damit der Stack getestet werden kann)
|
TEST_NUMBERS_BIN = test_numbers$(EXT)
|
||||||
unitTests: unittest.o stack.o
|
|
||||||
@echo "--- Erstelle Test-Executable ---"
|
testStack: unittest.o stack.o unity/unity.o
|
||||||
$(CC) $(FLAGS) unittest.o stack.o -o $(TEST_BIN)
|
@echo "--- Baue und starte Stack Tests ---"
|
||||||
@echo "--- Starte Tests ---"
|
$(CC) $(CFLAGS) unittest.o stack.o unity/unity.o -o $(TEST_STACK_BIN) $(LIBS)
|
||||||
./$(TEST_BIN)
|
./$(TEST_STACK_BIN)
|
||||||
|
|
||||||
|
testNumbers: unittestTree.o numbers.o bintree.o stack.o unity/unity.o
|
||||||
|
@echo "--- Baue und starte Numbers Tests ---"
|
||||||
|
$(CC) $(CFLAGS) unittestTree.o numbers.o bintree.o stack.o unity/unity.o -o $(TEST_NUMBERS_BIN) $(LIBS)
|
||||||
|
./$(TEST_NUMBERS_BIN)
|
||||||
|
|
||||||
# Regel, um unittest.c zu kompilieren
|
|
||||||
unittest.o: test_stack.c
|
unittest.o: test_stack.c
|
||||||
$(CC) -c $(FLAGS) test_stack.c -o unittest.o
|
$(CC) -c $(CFLAGS) test_stack.c -o unittest.o
|
||||||
|
|
||||||
|
unittestTree.o: test_numbers.c
|
||||||
|
$(CC) -c $(CFLAGS) test_numbers.c -o unittestTree.o
|
||||||
|
|
||||||
|
unity/unity.o: unity/unity.c
|
||||||
|
$(CC) -c $(CFLAGS) unity/unity.c -o unity/unity.o
|
||||||
|
|
||||||
|
|
||||||
# --------------------------
|
# --------------------------
|
||||||
# Clean
|
# Clean
|
||||||
# --------------------------
|
# --------------------------
|
||||||
clean:
|
clean:
|
||||||
ifeq ($(OS),Windows_NT)
|
$(RM_CMD) *.o doble$(EXT) doble_initial$(EXT) $(TEST_BIN)
|
||||||
del /f *.o doble $(TEST_BIN)
|
|
||||||
else
|
|
||||||
rm -f *.o doble $(TEST_BIN)
|
|
||||||
endif
|
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
#include "numbers.h"
|
#include "numbers.h"
|
||||||
#include "bintree.h"
|
#include "bintree.h"
|
||||||
|
|
||||||
CompareFctType compareFct(const void *arg1, const void *arg2)
|
int compareFct(const void *arg1, const void *arg2)
|
||||||
{
|
{
|
||||||
const unsigned int *entry1 = arg1;
|
const unsigned int *entry1 = arg1;
|
||||||
const unsigned int *entry2 = arg2;
|
const unsigned int *entry2 = arg2;
|
||||||
@@ -28,18 +28,21 @@ unsigned int *createNumbers(unsigned int len)
|
|||||||
{
|
{
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
|
|
||||||
TreeNode *numbers;
|
|
||||||
|
|
||||||
int isDuplicate = 0;
|
int isDuplicate = 0;
|
||||||
unsigned int number = rand() % (2 * len) + 1;
|
unsigned int number = rand() % (2 * len) + 1;
|
||||||
unsigned int *array = malloc(len * sizeof(int));
|
unsigned int *array = malloc(len * sizeof(unsigned int));
|
||||||
|
if (array == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
numbers = addToTree(NULL, &number, sizeof(int), compareFct, &isDuplicate);
|
TreeNode *numbers = addToTree(NULL, &number, sizeof(unsigned int), compareFct, &isDuplicate);
|
||||||
array[0] = number;
|
array[0] = number;
|
||||||
for (int i = 1; i < len; i++)
|
|
||||||
|
for (unsigned int i = 1; i < len; i++)
|
||||||
{
|
{
|
||||||
number = rand() % (2 * len) + 1;
|
number = rand() % (2 * len) + 1;
|
||||||
addToTree(numbers, &number, sizeof(int), compareFct, &isDuplicate);
|
|
||||||
|
numbers = addToTree(numbers, &number, sizeof(unsigned int), compareFct, &isDuplicate);
|
||||||
|
|
||||||
if (isDuplicate == 1)
|
if (isDuplicate == 1)
|
||||||
{
|
{
|
||||||
isDuplicate = 0;
|
isDuplicate = 0;
|
||||||
@@ -53,8 +56,8 @@ unsigned int *createNumbers(unsigned int len)
|
|||||||
|
|
||||||
clearTree(numbers);
|
clearTree(numbers);
|
||||||
|
|
||||||
int duplicatePosition1 = rand() % len;
|
unsigned int duplicatePosition1 = rand() % len;
|
||||||
int duplicatePosition2 = rand() % len;
|
unsigned int duplicatePosition2 = rand() % len;
|
||||||
|
|
||||||
while (duplicatePosition2 == duplicatePosition1)
|
while (duplicatePosition2 == duplicatePosition1)
|
||||||
{
|
{
|
||||||
@@ -69,21 +72,28 @@ unsigned int *createNumbers(unsigned int len)
|
|||||||
// Returns only the only number in numbers which is present twice. Returns zero on errors.
|
// Returns only the only number in numbers which is present twice. Returns zero on errors.
|
||||||
unsigned int getDuplicate(const unsigned int numbers[], unsigned int len)
|
unsigned int getDuplicate(const unsigned int numbers[], unsigned int len)
|
||||||
{
|
{
|
||||||
unsigned int *copyNumbers = malloc(sizeof(int) * len);
|
unsigned int *copyNumbers = malloc(sizeof(unsigned int) * len);
|
||||||
for (int i = 0; i < len; i++)
|
if (copyNumbers == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
unsigned int duplicateValue = 0;
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
copyNumbers[i] = numbers[i];
|
copyNumbers[i] = numbers[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
qsort(copyNumbers, len, sizeof(int), compareFct);
|
qsort(copyNumbers, len, sizeof(unsigned int), compareFct);
|
||||||
|
|
||||||
for (int i = 0; i < len - 1; i++)
|
for (unsigned int i = 0; i < len - 1; i++)
|
||||||
{
|
{
|
||||||
if (copyNumbers[i] == copyNumbers[i + 1])
|
if (copyNumbers[i] == copyNumbers[i + 1])
|
||||||
{
|
{
|
||||||
return copyNumbers[i];
|
duplicateValue = copyNumbers[i];
|
||||||
|
free(copyNumbers);
|
||||||
|
return duplicateValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
free(copyNumbers);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -8,7 +8,8 @@ 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 {
|
typedef struct node
|
||||||
|
{
|
||||||
void *data;
|
void *data;
|
||||||
struct node *prev;
|
struct node *prev;
|
||||||
} StackNode;
|
} StackNode;
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "numbers.h"
|
||||||
|
#include "bintree.h"
|
||||||
|
#include "unity/unity.h"
|
||||||
|
|
||||||
|
void test_getDuplicateLogic()
|
||||||
|
{
|
||||||
|
unsigned int test1[] = {1, 9, 3, 5, 2, 5, 8};
|
||||||
|
unsigned int len1 = 7;
|
||||||
|
unsigned int res1 = getDuplicate(test1, len1);
|
||||||
|
TEST_ASSERT_EQUAL_UINT32(5, res1);
|
||||||
|
|
||||||
|
unsigned int test2[] = {10, 1, 2, 3, 10};
|
||||||
|
unsigned int len2 = 5;
|
||||||
|
unsigned int res2 = getDuplicate(test2, len2);
|
||||||
|
TEST_ASSERT_EQUAL_UINT32(10, res2);
|
||||||
|
|
||||||
|
unsigned int test3[] = {1, 2, 3, 4, 5};
|
||||||
|
unsigned int len3 = 5;
|
||||||
|
unsigned int res3 = getDuplicate(test3, len3);
|
||||||
|
TEST_ASSERT_EQUAL_UINT32(0, res3);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_Integration(unsigned int len)
|
||||||
|
{
|
||||||
|
unsigned int *arr = createNumbers(len);
|
||||||
|
TEST_ASSERT_NOT_NULL(arr);
|
||||||
|
unsigned int duplicate = getDuplicate(arr, len);
|
||||||
|
TEST_ASSERT_NOT_EQUAL_UINT32(0, duplicate);
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
for (unsigned int i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
if (arr[i] == duplicate)
|
||||||
|
{
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_UINT32(2, count);
|
||||||
|
|
||||||
|
free(arr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_IntegrationVar()
|
||||||
|
{
|
||||||
|
test_Integration(10);
|
||||||
|
test_Integration(100);
|
||||||
|
test_Integration(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
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("============================\nNumbers tests\n============================\n");
|
||||||
|
RUN_TEST(test_getDuplicateLogic);
|
||||||
|
RUN_TEST(test_IntegrationVar);
|
||||||
|
|
||||||
|
return UNITY_END();
|
||||||
|
}
|
||||||
Binary file not shown.
+37
-14
@@ -2,17 +2,22 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "stack.h"
|
#include "stack.h"
|
||||||
|
#include "unity/unity.h"
|
||||||
|
|
||||||
void test_pushFailsOnNullPointer(StackNode *stack, void *data) {
|
void test_pushFailsOnNullPointer(StackNode *stack, void *data)
|
||||||
|
{
|
||||||
|
|
||||||
StackNode *test = push(NULL, data);
|
StackNode *test = push(NULL, data);
|
||||||
if (test != 0) {
|
if (test != 0)
|
||||||
|
{
|
||||||
printf("Pass test_pushFailsOnNullPointerStack\n");
|
printf("Pass test_pushFailsOnNullPointerStack\n");
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
printf("Did Not Pass test_pushFailsOnNullPointerStack EXPECTED StackNode\n");
|
printf("Did Not Pass test_pushFailsOnNullPointerStack EXPECTED StackNode\n");
|
||||||
|
|
||||||
test = push(stack, NULL);
|
test = push(stack, NULL);
|
||||||
if (test == 0) {
|
if (test == 0)
|
||||||
|
{
|
||||||
printf("Pass test_pushFailsOnNullPointerData\n");
|
printf("Pass test_pushFailsOnNullPointerData\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -20,10 +25,12 @@ void test_pushFailsOnNullPointer(StackNode *stack, void *data) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_popFailsOnNullPointer() { //pop on null returns NULL
|
void test_popFailsOnNullPointer()
|
||||||
|
{ // pop on null returns NULL
|
||||||
|
|
||||||
StackNode *test = pop(NULL);
|
StackNode *test = pop(NULL);
|
||||||
if (test == 0) {
|
if (test == 0)
|
||||||
|
{
|
||||||
printf("Pass test_popFailsOnNullPointerStack\n");
|
printf("Pass test_popFailsOnNullPointerStack\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -32,10 +39,12 @@ void test_popFailsOnNullPointer() { //pop on null returns NULL
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_topFailsOnNullPointer() {
|
void test_topFailsOnNullPointer()
|
||||||
|
{
|
||||||
|
|
||||||
int *test = (int *)top(NULL);
|
int *test = (int *)top(NULL);
|
||||||
if (test == 0) {
|
if (test == 0)
|
||||||
|
{
|
||||||
printf("Pass test_topFailsOnNullPointerStack\n");
|
printf("Pass test_topFailsOnNullPointerStack\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -44,6 +53,14 @@ void test_topFailsOnNullPointer() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setUp(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void tearDown(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -63,23 +80,29 @@ int main()
|
|||||||
test_topFailsOnNullPointer();
|
test_topFailsOnNullPointer();
|
||||||
|
|
||||||
StackNode *stack1 = push(stack0, dataTest1);
|
StackNode *stack1 = push(stack0, dataTest1);
|
||||||
if(strcmp(stack1->data ,dataTest1) == 0) {
|
if (strcmp(stack1->data, dataTest1) == 0)
|
||||||
|
{
|
||||||
printf("Pass test_pushString\n");
|
printf("Pass test_pushString\n");
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
printf("Fails test_pushString\n expected: %s\n was: %s\n", dataTest1, (char *)(stack1->data));
|
printf("Fails test_pushString\n expected: %s\n was: %s\n", dataTest1, (char *)(stack1->data));
|
||||||
|
|
||||||
StackNode *stack2 = push(stack1, dataTest2);
|
StackNode *stack2 = push(stack1, dataTest2);
|
||||||
if(stack2->data == dataTest2) {
|
if (stack2->data == dataTest2)
|
||||||
|
{
|
||||||
printf("Pass test_pushFloat\n");
|
printf("Pass test_pushFloat\n");
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
printf("Fails test_pushFloat\n expected: %f\n was: %f\n", *dataTest2, *(float *)(stack2->data));
|
printf("Fails test_pushFloat\n expected: %f\n was: %f\n", *dataTest2, *(float *)(stack2->data));
|
||||||
|
|
||||||
int array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
|
int array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
|
||||||
|
|
||||||
for(size_t i = 0; i<10; i++) {
|
for (size_t i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
stack2 = push(stack2, &array[i]);
|
stack2 = push(stack2, &array[i]);
|
||||||
}
|
}
|
||||||
for(size_t i = 0; i<10; i++) {
|
for (size_t i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
int *data = (int *)top(stack2);
|
int *data = (int *)top(stack2);
|
||||||
printf("%d\n", *data);
|
printf("%d\n", *data);
|
||||||
stack2 = pop(stack2);
|
stack2 = pop(stack2);
|
||||||
|
|||||||
Binary file not shown.
@@ -21,7 +21,8 @@ double stopTimer()
|
|||||||
|
|
||||||
double measuredSeconds = (double)delta_us / 1000000.;
|
double measuredSeconds = (double)delta_us / 1000000.;
|
||||||
|
|
||||||
if(start.tv_nsec > 0) {
|
if (start.tv_nsec > 0)
|
||||||
|
{
|
||||||
start.tv_nsec = 0;
|
start.tv_nsec = 0;
|
||||||
start.tv_sec = 0;
|
start.tv_sec = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
Binary file not shown.
Binary file not shown.
+4
-3
@@ -4,7 +4,6 @@
|
|||||||
#include "stack.h"
|
#include "stack.h"
|
||||||
#include "unity.h"
|
#include "unity.h"
|
||||||
|
|
||||||
|
|
||||||
void test_createMatrixFailsOnZeroDimensions(void)
|
void test_createMatrixFailsOnZeroDimensions(void)
|
||||||
{
|
{
|
||||||
Matrix matrixToTest1 = createMatrix(0, 1);
|
Matrix matrixToTest1 = createMatrix(0, 1);
|
||||||
@@ -167,11 +166,13 @@ void test_setMatrixAtFailsOnIndicesOutOfRange(void)
|
|||||||
TEST_ASSERT_EQUAL_FLOAT_ARRAY(expectedResults, matrixToTest.buffer, sizeof(buffer) / sizeof(MatrixType));
|
TEST_ASSERT_EQUAL_FLOAT_ARRAY(expectedResults, matrixToTest.buffer, sizeof(buffer) / sizeof(MatrixType));
|
||||||
}
|
}
|
||||||
|
|
||||||
void setUp(void) {
|
void setUp(void)
|
||||||
|
{
|
||||||
// Falls notwendig, kann hier Vorbereitungsarbeit gemacht werden
|
// Falls notwendig, kann hier Vorbereitungsarbeit gemacht werden
|
||||||
}
|
}
|
||||||
|
|
||||||
void tearDown(void) {
|
void tearDown(void)
|
||||||
|
{
|
||||||
// Hier kann Bereinigungsarbeit nach jedem Test durchgeführt werden
|
// Hier kann Bereinigungsarbeit nach jedem Test durchgeführt werden
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-4
@@ -112,7 +112,12 @@ void verifyTest(void);
|
|||||||
/* It is not necessary for you to call PASS. A PASS condition is assumed if nothing fails.
|
/* It is not necessary for you to call PASS. A PASS condition is assumed if nothing fails.
|
||||||
* This method allows you to abort a test immediately with a PASS state, ignoring the remainder of the test. */
|
* This method allows you to abort a test immediately with a PASS state, ignoring the remainder of the test. */
|
||||||
#define TEST_PASS() TEST_ABORT()
|
#define TEST_PASS() TEST_ABORT()
|
||||||
#define TEST_PASS_MESSAGE(message) do { UnityMessage((message), __LINE__); TEST_ABORT(); } while (0)
|
#define TEST_PASS_MESSAGE(message) \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
UnityMessage((message), __LINE__); \
|
||||||
|
TEST_ABORT(); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
/*-------------------------------------------------------
|
/*-------------------------------------------------------
|
||||||
* Build Directives
|
* Build Directives
|
||||||
@@ -295,7 +300,6 @@ void verifyTest(void);
|
|||||||
#define TEST_ASSERT_HEX64_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_HEX64_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL)
|
#define TEST_ASSERT_HEX64_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_HEX64_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL)
|
||||||
#define TEST_ASSERT_CHAR_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_CHAR_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL)
|
#define TEST_ASSERT_CHAR_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_CHAR_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL)
|
||||||
|
|
||||||
|
|
||||||
/* Structs and Strings */
|
/* Structs and Strings */
|
||||||
#define TEST_ASSERT_EQUAL_PTR(expected, actual) UNITY_TEST_ASSERT_EQUAL_PTR((expected), (actual), __LINE__, NULL)
|
#define TEST_ASSERT_EQUAL_PTR(expected, actual) UNITY_TEST_ASSERT_EQUAL_PTR((expected), (actual), __LINE__, NULL)
|
||||||
#define TEST_ASSERT_EQUAL_STRING(expected, actual) UNITY_TEST_ASSERT_EQUAL_STRING((expected), (actual), __LINE__, NULL)
|
#define TEST_ASSERT_EQUAL_STRING(expected, actual) UNITY_TEST_ASSERT_EQUAL_STRING((expected), (actual), __LINE__, NULL)
|
||||||
@@ -466,7 +470,6 @@ void verifyTest(void);
|
|||||||
#define TEST_ASSERT_NOT_EQUAL_HEX64_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_NOT_EQUAL_HEX64((threshold), (actual), __LINE__, (message))
|
#define TEST_ASSERT_NOT_EQUAL_HEX64_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_NOT_EQUAL_HEX64((threshold), (actual), __LINE__, (message))
|
||||||
#define TEST_ASSERT_NOT_EQUAL_CHAR_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_NOT_EQUAL_CHAR((threshold), (actual), __LINE__, (message))
|
#define TEST_ASSERT_NOT_EQUAL_CHAR_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_NOT_EQUAL_CHAR((threshold), (actual), __LINE__, (message))
|
||||||
|
|
||||||
|
|
||||||
/* Integer Greater Than/ Less Than (of all sizes) */
|
/* Integer Greater Than/ Less Than (of all sizes) */
|
||||||
#define TEST_ASSERT_GREATER_THAN_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_INT((threshold), (actual), __LINE__, (message))
|
#define TEST_ASSERT_GREATER_THAN_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_INT((threshold), (actual), __LINE__, (message))
|
||||||
#define TEST_ASSERT_GREATER_THAN_INT_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_INT((threshold), (actual), __LINE__, (message))
|
#define TEST_ASSERT_GREATER_THAN_INT_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_INT((threshold), (actual), __LINE__, (message))
|
||||||
@@ -578,7 +581,6 @@ void verifyTest(void);
|
|||||||
#define TEST_ASSERT_HEX64_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_HEX64_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message))
|
#define TEST_ASSERT_HEX64_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_HEX64_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message))
|
||||||
#define TEST_ASSERT_CHAR_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_CHAR_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message))
|
#define TEST_ASSERT_CHAR_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_CHAR_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message))
|
||||||
|
|
||||||
|
|
||||||
/* Structs and Strings */
|
/* Structs and Strings */
|
||||||
#define TEST_ASSERT_EQUAL_PTR_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_PTR((expected), (actual), __LINE__, (message))
|
#define TEST_ASSERT_EQUAL_PTR_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_PTR((expected), (actual), __LINE__, (message))
|
||||||
#define TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_STRING((expected), (actual), __LINE__, (message))
|
#define TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_STRING((expected), (actual), __LINE__, (message))
|
||||||
|
|||||||
Binary file not shown.
Reference in new issue
Block a user