Compare commits
25
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
45b6fab21a | ||
|
|
d1320cf6b7 | ||
|
|
369c019c30 | ||
|
|
cccc013b99 | ||
|
|
9a79ff0ad4 | ||
|
|
284cdbdcfb | ||
|
|
e3501e8550 | ||
|
|
6a9461bf5b | ||
|
|
ef3e0b7891 | ||
|
|
82b2fb283f | ||
|
|
602220ba21 | ||
|
|
2368c9f3b9 | ||
|
|
e4a8afabdd | ||
|
|
9d08970513 | ||
|
|
9ee0f9e281 | ||
|
|
21aa67b165 | ||
|
|
2d6f8689f2 | ||
|
|
8754182f79 | ||
|
|
144648886f | ||
|
|
72f1d080a0 | ||
|
|
01bc613189 | ||
|
|
79a6eb7267 | ||
|
|
53c12ce0ed | ||
|
|
8deeb6417e | ||
|
|
02e008c03a |
@@ -9,10 +9,10 @@
|
||||
/* * `addToTree`: fügt ein neues Element in den Baum ein (rekursiv), Done
|
||||
* `clearTree`: gibt den gesamten Baum frei (rekursiv), Done
|
||||
* `treeSize`: zählt die Knoten im Baum (rekursiv), Done
|
||||
* `nextTreeData`: Traversierung mit Hilfe des zuvor implementierten Stacks. */
|
||||
* `nextTreeData`: Traversierung mit Hilfe des zuvor implementierten Stacks. Done */
|
||||
|
||||
|
||||
static TreeNode *root = NULL;
|
||||
static StackNode *stackRoot = NULL;
|
||||
|
||||
|
||||
TreeNode *addToTree (TreeNode *root, const void *data, size_t dataSize, CompareFctType compareFct, int *isDuplicate);
|
||||
@@ -21,10 +21,11 @@
|
||||
unsigned int treeSize (const TreeNode *root);
|
||||
|
||||
// self declared functions
|
||||
TreeNode *addToTreeRec (TreeNode *currentNode, TreeNode *newNode, CompareFctType compareFct, int *isDuplicate);
|
||||
TreeNode *addToTreeRec (TreeNode *currentNode, TreeNode *newNode, CompareFctType compareFct, int *isDuplicate, const int root);
|
||||
void clearTreeRec (TreeNode *currentNode);
|
||||
void clearNode (TreeNode *node);
|
||||
void treeSizeRec (const TreeNode *currentNode, unsigned int *nodeCount);
|
||||
int treeSizeRec (const TreeNode *currentNode);
|
||||
void *nextTreeDataRec (TreeNode *node, StackNode *stack);
|
||||
|
||||
|
||||
// Adds a copy of data's pointer destination to the tree using compareFct for ordering. Accepts duplicates
|
||||
@@ -41,39 +42,45 @@ TreeNode *addToTree(TreeNode *root, const void *data, size_t dataSize, CompareFc
|
||||
newNode->data = calloc(1, dataSize);
|
||||
newNode->left = NULL;
|
||||
newNode->right = NULL;
|
||||
memcpy(&newNode->data, data, dataSize);
|
||||
memcpy(newNode->data, data, dataSize);
|
||||
|
||||
|
||||
return addToTreeRec(root, newNode, compareFct, isDuplicate);
|
||||
return addToTreeRec(root, newNode, compareFct, isDuplicate, 1);
|
||||
}
|
||||
|
||||
|
||||
TreeNode *addToTreeRec(TreeNode *currentNode, TreeNode *newNode, CompareFctType compareFct, int *isDuplicate)
|
||||
TreeNode *addToTreeRec(TreeNode *currentNode, TreeNode *newNode, CompareFctType compareFct, int *isDuplicate, const int root)
|
||||
{
|
||||
if ((currentNode == NULL))
|
||||
{
|
||||
if (isDuplicate == NULL)
|
||||
if ((isDuplicate == NULL) || root)
|
||||
{
|
||||
if (isDuplicate != NULL)
|
||||
{
|
||||
*isDuplicate = 0;
|
||||
}
|
||||
|
||||
return newNode;
|
||||
}
|
||||
else
|
||||
{
|
||||
*isDuplicate = 0;
|
||||
return currentNode;
|
||||
}
|
||||
}
|
||||
else if ((compareFct(¤tNode->data, &newNode->data) < 0))
|
||||
else if ((compareFct(currentNode->data, newNode->data) < 0))
|
||||
{
|
||||
currentNode->left = addToTreeRec(currentNode->left, newNode, compareFct, isDuplicate);
|
||||
currentNode->left = addToTreeRec(currentNode->left, newNode, compareFct, isDuplicate, 0);
|
||||
}
|
||||
else if ((compareFct(¤tNode->data, &newNode->data) > 0))
|
||||
else if ((compareFct(currentNode->data, newNode->data) > 0))
|
||||
{
|
||||
currentNode->right = addToTreeRec(currentNode->right, newNode, compareFct, isDuplicate);
|
||||
currentNode->right = addToTreeRec(currentNode->right, newNode, compareFct, isDuplicate, 0);
|
||||
}
|
||||
else if ((compareFct(¤tNode->data, &newNode->data) == 0))
|
||||
else if ((compareFct(currentNode->data, newNode->data) == 0))
|
||||
{
|
||||
if (isDuplicate == NULL)
|
||||
{
|
||||
currentNode->left = addToTreeRec(currentNode->left, newNode, compareFct, isDuplicate);
|
||||
currentNode->left = addToTreeRec(currentNode->left, newNode, compareFct, isDuplicate, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -81,7 +88,10 @@ TreeNode *addToTreeRec(TreeNode *currentNode, TreeNode *newNode, CompareFctType
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (isDuplicate != NULL)
|
||||
{
|
||||
*isDuplicate = 0;
|
||||
}
|
||||
return currentNode;
|
||||
}
|
||||
|
||||
@@ -91,9 +101,40 @@ TreeNode *addToTreeRec(TreeNode *currentNode, TreeNode *newNode, CompareFctType
|
||||
// push the top node and push all its left nodes.
|
||||
|
||||
// Needs stack!!
|
||||
// Stack functions: push(), pop(), top(), clearStack()
|
||||
void *nextTreeData(TreeNode *root)
|
||||
{
|
||||
void *pointerToReturn = NULL;
|
||||
|
||||
if (root != NULL)
|
||||
{
|
||||
// Add tree to stack so that bigest entry is ontop
|
||||
stackRoot = nextTreeDataRec(root, stackRoot);
|
||||
pointerToReturn = stackRoot;
|
||||
}
|
||||
else
|
||||
{
|
||||
// return current top entry and then pop that top entry
|
||||
pointerToReturn = top(stackRoot);
|
||||
stackRoot = pop(stackRoot);
|
||||
}
|
||||
|
||||
|
||||
return pointerToReturn;
|
||||
}
|
||||
|
||||
|
||||
void *nextTreeDataRec(TreeNode *tree, StackNode *stack)
|
||||
{
|
||||
if (tree != NULL)
|
||||
{
|
||||
stack = nextTreeDataRec (tree->left, stack);
|
||||
stack = push (stack, tree->data);
|
||||
stack = nextTreeDataRec (tree->right, stack);
|
||||
}
|
||||
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
|
||||
@@ -109,42 +150,22 @@ void clearTreeRec(TreeNode *currentNode)
|
||||
if (currentNode != NULL)
|
||||
{
|
||||
clearTree(currentNode->left);
|
||||
|
||||
clearTree(currentNode->right);
|
||||
|
||||
clearNode(currentNode);
|
||||
/*
|
||||
printf("1\n");
|
||||
free(¤tNode->data);
|
||||
currentNode->data = NULL;
|
||||
printf("2\n");
|
||||
// free(currentNode);
|
||||
// currentNode = NULL;
|
||||
printf("3\n");
|
||||
// */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void clearNode(TreeNode *node)
|
||||
{
|
||||
// printf("in clearNode\n");
|
||||
// printf("node-> data = %u\n", node->data);
|
||||
// printf("node-> data = %u\n", _ADDRESSOF(node->data));
|
||||
free(&node->data);
|
||||
free(node->data);
|
||||
node->data = NULL;
|
||||
// printf("node-> data = %u\n", &node->data);
|
||||
// printf("data freed \n");
|
||||
|
||||
node->left = NULL;
|
||||
node->right = NULL;
|
||||
// printf("left & right = Null\n");
|
||||
printf("node = %u\n", &node);
|
||||
// printf("node = %u\n", _ADDRESSOF(node));
|
||||
// free(node);
|
||||
// printf("node = %d\n", node);
|
||||
|
||||
free(node);
|
||||
node = NULL;
|
||||
printf("node = %u\n", &node);
|
||||
printf("freed node\n");
|
||||
}
|
||||
|
||||
|
||||
@@ -154,19 +175,25 @@ unsigned int treeSize(const TreeNode *root)
|
||||
unsigned int amountOfNodes = 0;
|
||||
|
||||
|
||||
treeSizeRec(root, &amountOfNodes);
|
||||
amountOfNodes = treeSizeRec(root);
|
||||
|
||||
|
||||
return amountOfNodes;
|
||||
}
|
||||
|
||||
void treeSizeRec(const TreeNode *currentNode, unsigned int *nodeCount)
|
||||
|
||||
int treeSizeRec(const TreeNode *currentNode)
|
||||
{
|
||||
int nodeCount = 0;
|
||||
|
||||
|
||||
if (currentNode != NULL)
|
||||
{
|
||||
treeSizeRec(currentNode->left, nodeCount);
|
||||
*nodeCount++;
|
||||
treeSizeRec(currentNode->right, nodeCount);
|
||||
nodeCount += treeSizeRec(currentNode->left);
|
||||
nodeCount += treeSizeRec(currentNode->right);
|
||||
return nodeCount + 1;
|
||||
}
|
||||
|
||||
return nodeCount;
|
||||
}
|
||||
|
||||
|
||||
+57
-42
@@ -3,6 +3,7 @@
|
||||
#include <stdlib.h>
|
||||
#include "unity.h"
|
||||
#include "bintree.h"
|
||||
#include "stack.h"
|
||||
|
||||
#define MAX_TEST_NAME_LEN 10
|
||||
|
||||
@@ -11,6 +12,7 @@ void setUp(void) {
|
||||
// Falls notwendig, kann hier Vorbereitungsarbeit gemacht werden
|
||||
}
|
||||
|
||||
|
||||
void tearDown(void) {
|
||||
// Hier kann Bereinigungsarbeit nach jedem Test durchgeführt werden
|
||||
}
|
||||
@@ -54,24 +56,25 @@ void test_addToTreeExpandsTreeCorrectly(void)
|
||||
|
||||
// Checking the Tree without Doubles
|
||||
TEST_ASSERT_NOT_NULL(testRoot);
|
||||
TEST_ASSERT_EQUAL_UINT16(score1, testRoot->data);
|
||||
TEST_ASSERT_EQUAL(score1, *(int *)testRoot->data);
|
||||
|
||||
TEST_ASSERT_NOT_NULL(testRoot->left);
|
||||
TEST_ASSERT_EQUAL_UINT16(score2, testRoot->left->data);
|
||||
TEST_ASSERT_EQUAL(score2, *(int *)testRoot->left->data);
|
||||
TEST_ASSERT_NOT_NULL(testRoot->right);
|
||||
TEST_ASSERT_EQUAL_UINT16(score3, testRoot->right->data);
|
||||
TEST_ASSERT_EQUAL(score3, *(int *)testRoot->right->data);
|
||||
TEST_ASSERT_NOT_NULL(testRoot->left->left);
|
||||
TEST_ASSERT_EQUAL_UINT16(score4, testRoot->left->left->data);
|
||||
TEST_ASSERT_EQUAL(score4, *(int *)testRoot->left->left->data);
|
||||
TEST_ASSERT_NOT_NULL(testRoot->left->right);
|
||||
TEST_ASSERT_EQUAL_UINT16(score5, testRoot->left->right->data);
|
||||
TEST_ASSERT_EQUAL(score5, *(int *)testRoot->left->right->data);
|
||||
TEST_ASSERT_NOT_NULL(testRoot->right->left);
|
||||
TEST_ASSERT_EQUAL_UINT16(score6, testRoot->right->left->data);
|
||||
TEST_ASSERT_EQUAL(score6, *(int *)testRoot->right->left->data);
|
||||
TEST_ASSERT_NOT_NULL(testRoot->right->right);
|
||||
TEST_ASSERT_EQUAL_UINT16(score7, testRoot->right->right->data);
|
||||
TEST_ASSERT_EQUAL(score7, *(int *)testRoot->right->right->data);
|
||||
|
||||
// Adding Double
|
||||
testRoot = addToTree(testRoot, &score4, sizeof(int), compareIntEntries, NULL);
|
||||
TEST_ASSERT_NOT_NULL(testRoot->left->left->left);
|
||||
TEST_ASSERT_EQUAL_UINT16(score4, testRoot->left->left->left->data);
|
||||
TEST_ASSERT_EQUAL_UINT16(score4, *(int *)testRoot->left->left->left->data);
|
||||
|
||||
// Trying to add Double while Doubles not Permitted
|
||||
testRoot = addToTree(testRoot, &score7, sizeof(int), compareIntEntries, &testIsDouble);
|
||||
@@ -79,7 +82,7 @@ void test_addToTreeExpandsTreeCorrectly(void)
|
||||
TEST_ASSERT_EQUAL_UINT16(1, testIsDouble);
|
||||
|
||||
|
||||
// clearTree(testRoot);
|
||||
clearTree(testRoot);
|
||||
}
|
||||
|
||||
|
||||
@@ -87,7 +90,41 @@ void test_addToTreeExpandsTreeCorrectly(void)
|
||||
// needs Stack!!!
|
||||
void test_nextTreeDataReturnsNextDataCorrectly(void)
|
||||
{
|
||||
TreeNode *testRoot = NULL;
|
||||
int score1 = 12;
|
||||
int score2 = 6;
|
||||
int score3 = 18;
|
||||
int score4 = 3;
|
||||
int score5 = 9;
|
||||
int score6 = 15;
|
||||
int score7 = 21;
|
||||
|
||||
|
||||
// Prepare a Tree
|
||||
testRoot = addToTree(testRoot, &score1, sizeof(int), compareIntEntries, NULL);
|
||||
testRoot = addToTree(testRoot, &score2, sizeof(int), compareIntEntries, NULL);
|
||||
testRoot = addToTree(testRoot, &score3, sizeof(int), compareIntEntries, NULL);
|
||||
testRoot = addToTree(testRoot, &score4, sizeof(int), compareIntEntries, NULL);
|
||||
testRoot = addToTree(testRoot, &score5, sizeof(int), compareIntEntries, NULL);
|
||||
testRoot = addToTree(testRoot, &score6, sizeof(int), compareIntEntries, NULL);
|
||||
testRoot = addToTree(testRoot, &score7, sizeof(int), compareIntEntries, NULL);
|
||||
|
||||
// Create Stack
|
||||
StackNode *entry = nextTreeData(testRoot);
|
||||
|
||||
// check if nextTreeData returns Data correctly
|
||||
TEST_ASSERT_NOT_NULL(entry);
|
||||
|
||||
TEST_ASSERT_EQUAL(score7, *(int *)nextTreeData(NULL));
|
||||
TEST_ASSERT_EQUAL(score3, *(int *)nextTreeData(NULL));
|
||||
TEST_ASSERT_EQUAL(score6, *(int *)nextTreeData(NULL));
|
||||
TEST_ASSERT_EQUAL(score1, *(int *)nextTreeData(NULL));
|
||||
TEST_ASSERT_EQUAL(score5, *(int *)nextTreeData(NULL));
|
||||
TEST_ASSERT_EQUAL(score2, *(int *)nextTreeData(NULL));
|
||||
TEST_ASSERT_EQUAL(score4, *(int *)nextTreeData(NULL));
|
||||
|
||||
|
||||
clearTree(testRoot);
|
||||
}
|
||||
|
||||
|
||||
@@ -105,7 +142,6 @@ void test_clearTreeworksLikeExpected(void)
|
||||
int score7 = 21;
|
||||
|
||||
|
||||
// Fill Tree
|
||||
testRoot = addToTree(testRoot, &score1, sizeof(int), compareIntEntries, NULL);
|
||||
testRoot = addToTree(testRoot, &score2, sizeof(int), compareIntEntries, NULL);
|
||||
testRoot = addToTree(testRoot, &score3, sizeof(int), compareIntEntries, NULL);
|
||||
@@ -113,47 +149,27 @@ void test_clearTreeworksLikeExpected(void)
|
||||
testRoot = addToTree(testRoot, &score5, sizeof(int), compareIntEntries, NULL);
|
||||
testRoot = addToTree(testRoot, &score6, sizeof(int), compareIntEntries, NULL);
|
||||
testRoot = addToTree(testRoot, &score7, sizeof(int), compareIntEntries, NULL);
|
||||
testRoot = addToTree(testRoot, &score4, sizeof(int), compareIntEntries, NULL);
|
||||
printf("Tree Filled\n");
|
||||
|
||||
// Save all Adresses
|
||||
TreeNode *node1 = testRoot->left;
|
||||
TreeNode *node2 = testRoot->left->left;
|
||||
TreeNode *node3 = testRoot->left->right;
|
||||
TreeNode *node4 = testRoot->right;
|
||||
TreeNode *node5 = testRoot->right->left;
|
||||
TreeNode *node6 = testRoot->right->right;
|
||||
TreeNode *node7 = testRoot->left->left->left;
|
||||
printf("Adresses Saved\n");
|
||||
TreeNode *node1 = testRoot;
|
||||
TreeNode *node2 = testRoot->left;
|
||||
TreeNode *node3 = testRoot->left->left;
|
||||
TreeNode *node4 = testRoot->left->right;
|
||||
TreeNode *node5 = testRoot->right;
|
||||
TreeNode *node6 = testRoot->right->left;
|
||||
TreeNode *node7 = testRoot->right->right;
|
||||
|
||||
clearTree(testRoot);
|
||||
printf("Tree Cleared\n");
|
||||
|
||||
// Check if everything has been set to NULL
|
||||
TEST_ASSERT_NULL(testRoot->data);
|
||||
TEST_ASSERT_NULL(testRoot);
|
||||
|
||||
TEST_ASSERT_NULL(node1->data);
|
||||
// TEST_ASSERT_NULL(node1);
|
||||
|
||||
TEST_ASSERT_NULL(node1->data);
|
||||
TEST_ASSERT_NULL(node2->data);
|
||||
// TEST_ASSERT_NULL(node2);
|
||||
|
||||
TEST_ASSERT_NULL(node3->data);
|
||||
// TEST_ASSERT_NULL(node3);
|
||||
|
||||
TEST_ASSERT_NULL(node4->data);
|
||||
// TEST_ASSERT_NULL(node4);
|
||||
|
||||
TEST_ASSERT_NULL(node5->data);
|
||||
// TEST_ASSERT_NULL(node5);
|
||||
|
||||
TEST_ASSERT_NULL(node6->data);
|
||||
// TEST_ASSERT_NULL(node6);
|
||||
|
||||
TEST_ASSERT_NULL(node7->data);
|
||||
// TEST_ASSERT_NULL(node7);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -182,7 +198,6 @@ void test_treeSizeWorkingLikeExpected(void)
|
||||
testRoot = addToTree(testRoot, &score5, sizeof(int), compareIntEntries, NULL);
|
||||
testRoot = addToTree(testRoot, &score6, sizeof(int), compareIntEntries, NULL);
|
||||
testRoot = addToTree(testRoot, &score7, sizeof(int), compareIntEntries, NULL);
|
||||
testRoot = addToTree(testRoot, &score4, sizeof(int), compareIntEntries, NULL);
|
||||
|
||||
testTreeSize = treeSize(testRoot);
|
||||
|
||||
@@ -198,10 +213,10 @@ int main()
|
||||
UNITY_BEGIN();
|
||||
|
||||
printf("\n============================\nBinary Tree tests\n============================\n");
|
||||
// RUN_TEST(test_addToTreeExpandsTreeCorrectly);
|
||||
// RUN_TEST(test_nextTreeDataReturnsNextDataCorrectly);
|
||||
RUN_TEST(test_addToTreeExpandsTreeCorrectly);
|
||||
RUN_TEST(test_nextTreeDataReturnsNextDataCorrectly);
|
||||
RUN_TEST(test_clearTreeworksLikeExpected);
|
||||
// RUN_TEST(test_treeSizeWorkingLikeExpected);
|
||||
RUN_TEST(test_treeSizeWorkingLikeExpected);
|
||||
|
||||
return UNITY_END();
|
||||
}
|
||||
|
||||
@@ -41,9 +41,14 @@ $(program_obj_filesobj_files): %.o: %.c
|
||||
bintree: bintree.c
|
||||
$(CC) $(FLAGS) -c bintree bintree.c
|
||||
|
||||
bintreeTests: bintree.o bintreeTests.c $(unityfolder)/unity.c
|
||||
$(CC) $(FLAGS) -o runbintreeTests bintreeTests.c bintree.o $(unityfolder)/unity.c
|
||||
bintreeTests: stack.o bintree.o bintreeTests.c $(unityfolder)/unity.c
|
||||
$(CC) $(FLAGS) -o runbintreeTests bintreeTests.c bintree.o stack.o $(unityfolder)/unity.c
|
||||
|
||||
stack: stack.c
|
||||
$(CC) $(FLAGS) -c stack stack.c
|
||||
|
||||
test_stack: stack.o test_stack.c $(unityfolder)/unity.c
|
||||
$(CC) $(FLAGS) -o runstackTests test_stack.c stack.o $(unityfolder)/unity.c
|
||||
# --------------------------
|
||||
# Clean
|
||||
# --------------------------
|
||||
|
||||
Binary file not shown.
Binary file not shown.
+43
-44
@@ -1,24 +1,30 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "unity.h"
|
||||
#include "stack.h"
|
||||
|
||||
void setUp(void) {
|
||||
// Falls notwendig, kann hier Vorbereitungsarbeit gemacht werden
|
||||
}
|
||||
|
||||
void tearDown(void) {
|
||||
// Hier kann Bereinigungsarbeit nach jedem Test durchgeführt werden
|
||||
}
|
||||
|
||||
|
||||
|
||||
void testeStackBeschreiben()
|
||||
{
|
||||
printf("=== Test: push() ===\n");
|
||||
//printf("=== Test: push() ===\n");
|
||||
|
||||
StackNode *stack = NULL;
|
||||
int wert1 = 42;
|
||||
stack = push(stack, &wert1);
|
||||
|
||||
int *topValue = (int *)(stack->data);
|
||||
if(topValue != NULL && *topValue == 42)
|
||||
{
|
||||
printf("Test 1: Erstes Element erfolgreich gepusht!\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Test 1: FEHLGESCHLAGEN!\n");
|
||||
}
|
||||
|
||||
TEST_ASSERT_NOT_NULL(topValue);
|
||||
TEST_ASSERT_EQUAL_INT(42, *topValue);
|
||||
|
||||
|
||||
int wert2 = 12;
|
||||
@@ -27,23 +33,19 @@ void testeStackBeschreiben()
|
||||
topValue = (int *)(stack->data);
|
||||
int *secondValue = (int *)((stack->next)->data);
|
||||
|
||||
if(topValue != NULL && *topValue == 12.25 && secondValue != NULL && *secondValue == 42)
|
||||
{
|
||||
printf("Test 2: Zweites Element erfolgreich gepusht!\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Test 2: FEHLGESCHLAGEN!\n");
|
||||
}
|
||||
TEST_ASSERT_NOT_NULL(topValue);
|
||||
TEST_ASSERT_EQUAL_INT(12, *topValue);
|
||||
TEST_ASSERT_NOT_NULL(secondValue);
|
||||
TEST_ASSERT_EQUAL_INT(42, *secondValue);
|
||||
|
||||
|
||||
printf("=== Ende Test: push() ===\n\n");
|
||||
//printf("=== Ende Test: push() ===\n\n");
|
||||
return;
|
||||
}
|
||||
|
||||
void testepop()
|
||||
{
|
||||
printf("=== Test: pop() ===\n");
|
||||
//printf("=== Test: pop() ===\n");
|
||||
|
||||
StackNode *stack = NULL;
|
||||
int wert1 = 20;
|
||||
@@ -56,21 +58,15 @@ void testepop()
|
||||
|
||||
int *topValue = (int *)(stack->data);
|
||||
|
||||
if(topValue != NULL && *topValue == 20)
|
||||
{
|
||||
printf("Test: Erstes Element erfolgreich gelöscht!\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Test 1: FEHLGESCHLAGEN!\n");
|
||||
}
|
||||
TEST_ASSERT_NOT_NULL(topValue);
|
||||
TEST_ASSERT_EQUAL_INT(20, *topValue);
|
||||
|
||||
printf("=== Ende Test: pop() ===\n\n");
|
||||
//printf("=== Ende Test: pop() ===\n\n");
|
||||
}
|
||||
|
||||
void testetop()
|
||||
{
|
||||
printf("=== Test: top() ===\n");
|
||||
//printf("=== Test: top() ===\n");
|
||||
|
||||
StackNode *stack = NULL;
|
||||
int wert1 = 20;
|
||||
@@ -81,21 +77,15 @@ void testetop()
|
||||
|
||||
int *topValue = top(stack);
|
||||
|
||||
if(topValue != NULL && *topValue == 74)
|
||||
{
|
||||
printf("Test: top() gibt korrektes Element zurück!\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Test: FEHLGESCHLAGEN!\n");
|
||||
}
|
||||
TEST_ASSERT_NOT_NULL(topValue);
|
||||
TEST_ASSERT_EQUAL_INT(74, *topValue);
|
||||
|
||||
printf("=== Ende Test: top() ===\n\n");
|
||||
//printf("=== Ende Test: top() ===\n\n");
|
||||
}
|
||||
|
||||
void testeclearStack()
|
||||
{
|
||||
printf("=== Test: clearStack() ===\n");
|
||||
//printf("=== Test: clearStack() ===\n");
|
||||
|
||||
StackNode *stack = NULL;
|
||||
int wert1 = 20;
|
||||
@@ -106,16 +96,25 @@ void testeclearStack()
|
||||
|
||||
clearStack(stack);
|
||||
|
||||
printf("Test: clearStack() aufgerufen. Speicher freigegeben.\n");
|
||||
printf("=== Ende Test: clearStack() ===\n\n");
|
||||
//printf("Test: clearStack() aufgerufen. Speicher freigegeben.\n");
|
||||
//printf("=== Ende Test: clearStack() ===\n\n");
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
testeStackBeschreiben();
|
||||
UNITY_BEGIN();
|
||||
|
||||
//printf("...");
|
||||
|
||||
RUN_TEST(testeStackBeschreiben);
|
||||
RUN_TEST(testepop);
|
||||
RUN_TEST(testetop);
|
||||
RUN_TEST(testeclearStack);
|
||||
|
||||
/*testeStackBeschreiben();
|
||||
testepop();
|
||||
testetop();
|
||||
testeclearStack();
|
||||
testeclearStack();*/
|
||||
|
||||
return 0;
|
||||
return UNITY_END();
|
||||
}
|
||||
Reference in New Issue
Block a user