Compare commits
15
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
45b6fab21a | ||
|
|
d1320cf6b7 | ||
|
|
369c019c30 | ||
|
|
cccc013b99 | ||
|
|
9a79ff0ad4 | ||
|
|
284cdbdcfb | ||
|
|
e3501e8550 | ||
|
|
6a9461bf5b | ||
|
|
ef3e0b7891 | ||
|
|
82b2fb283f | ||
|
|
602220ba21 | ||
|
|
01bc613189 | ||
|
|
79a6eb7267 | ||
|
|
53c12ce0ed | ||
|
|
8deeb6417e |
@@ -9,10 +9,9 @@
|
|||||||
/* * `addToTree`: fügt ein neues Element in den Baum ein (rekursiv), Done
|
/* * `addToTree`: fügt ein neues Element in den Baum ein (rekursiv), Done
|
||||||
* `clearTree`: gibt den gesamten Baum frei (rekursiv), Done
|
* `clearTree`: gibt den gesamten Baum frei (rekursiv), Done
|
||||||
* `treeSize`: zählt die Knoten im Baum (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;
|
static StackNode *stackRoot = NULL;
|
||||||
|
|
||||||
|
|
||||||
@@ -56,10 +55,16 @@ TreeNode *addToTreeRec(TreeNode *currentNode, TreeNode *newNode, CompareFctType
|
|||||||
{
|
{
|
||||||
if ((isDuplicate == NULL) || root)
|
if ((isDuplicate == NULL) || root)
|
||||||
{
|
{
|
||||||
|
if (isDuplicate != NULL)
|
||||||
|
{
|
||||||
|
*isDuplicate = 0;
|
||||||
|
}
|
||||||
|
|
||||||
return newNode;
|
return newNode;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
*isDuplicate = 0;
|
||||||
return currentNode;
|
return currentNode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -83,7 +88,10 @@ TreeNode *addToTreeRec(TreeNode *currentNode, TreeNode *newNode, CompareFctType
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isDuplicate != NULL)
|
||||||
|
{
|
||||||
|
*isDuplicate = 0;
|
||||||
|
}
|
||||||
return currentNode;
|
return currentNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,5 +193,7 @@ int treeSizeRec(const TreeNode *currentNode)
|
|||||||
nodeCount += treeSizeRec(currentNode->right);
|
nodeCount += treeSizeRec(currentNode->right);
|
||||||
return nodeCount + 1;
|
return nodeCount + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nodeCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-3
@@ -109,7 +109,6 @@ void test_nextTreeDataReturnsNextDataCorrectly(void)
|
|||||||
testRoot = addToTree(testRoot, &score6, sizeof(int), compareIntEntries, NULL);
|
testRoot = addToTree(testRoot, &score6, sizeof(int), compareIntEntries, NULL);
|
||||||
testRoot = addToTree(testRoot, &score7, sizeof(int), compareIntEntries, NULL);
|
testRoot = addToTree(testRoot, &score7, sizeof(int), compareIntEntries, NULL);
|
||||||
|
|
||||||
|
|
||||||
// Create Stack
|
// Create Stack
|
||||||
StackNode *entry = nextTreeData(testRoot);
|
StackNode *entry = nextTreeData(testRoot);
|
||||||
|
|
||||||
@@ -124,7 +123,7 @@ void test_nextTreeDataReturnsNextDataCorrectly(void)
|
|||||||
TEST_ASSERT_EQUAL(score2, *(int *)nextTreeData(NULL));
|
TEST_ASSERT_EQUAL(score2, *(int *)nextTreeData(NULL));
|
||||||
TEST_ASSERT_EQUAL(score4, *(int *)nextTreeData(NULL));
|
TEST_ASSERT_EQUAL(score4, *(int *)nextTreeData(NULL));
|
||||||
|
|
||||||
clearStack(entry);
|
|
||||||
clearTree(testRoot);
|
clearTree(testRoot);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,7 +214,7 @@ int main()
|
|||||||
|
|
||||||
printf("\n============================\nBinary Tree tests\n============================\n");
|
printf("\n============================\nBinary Tree tests\n============================\n");
|
||||||
RUN_TEST(test_addToTreeExpandsTreeCorrectly);
|
RUN_TEST(test_addToTreeExpandsTreeCorrectly);
|
||||||
// RUN_TEST(test_nextTreeDataReturnsNextDataCorrectly);
|
RUN_TEST(test_nextTreeDataReturnsNextDataCorrectly);
|
||||||
RUN_TEST(test_clearTreeworksLikeExpected);
|
RUN_TEST(test_clearTreeworksLikeExpected);
|
||||||
RUN_TEST(test_treeSizeWorkingLikeExpected);
|
RUN_TEST(test_treeSizeWorkingLikeExpected);
|
||||||
|
|
||||||
|
|||||||
@@ -38,18 +38,17 @@ $(program_obj_filesobj_files): %.o: %.c
|
|||||||
# unitTests:
|
# unitTests:
|
||||||
# echo "needs to be implemented"
|
# echo "needs to be implemented"
|
||||||
|
|
||||||
|
bintree: bintree.c
|
||||||
|
$(CC) $(FLAGS) -c bintree bintree.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
|
stack: stack.c
|
||||||
$(CC) $(FLAGS) -c stack stack.c
|
$(CC) $(FLAGS) -c stack stack.c
|
||||||
|
|
||||||
test_stack: stack.o test_stack.c $(unityfolder)/unity.c
|
test_stack: stack.o test_stack.c $(unityfolder)/unity.c
|
||||||
$(CC) $(FLAGS) -o runstackTests test_stack.c stack.o $(unityfolder)/unity.c
|
$(CC) $(FLAGS) -o runstackTests test_stack.c stack.o $(unityfolder)/unity.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
|
|
||||||
|
|
||||||
# --------------------------
|
# --------------------------
|
||||||
# Clean
|
# Clean
|
||||||
# --------------------------
|
# --------------------------
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
+43
-44
@@ -1,24 +1,30 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include "unity.h"
|
||||||
#include "stack.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()
|
void testeStackBeschreiben()
|
||||||
{
|
{
|
||||||
printf("=== Test: push() ===\n");
|
//printf("=== Test: push() ===\n");
|
||||||
|
|
||||||
StackNode *stack = NULL;
|
StackNode *stack = NULL;
|
||||||
int wert1 = 42;
|
int wert1 = 42;
|
||||||
stack = push(stack, &wert1);
|
stack = push(stack, &wert1);
|
||||||
|
|
||||||
int *topValue = (int *)(stack->data);
|
int *topValue = (int *)(stack->data);
|
||||||
if(topValue != NULL && *topValue == 42)
|
|
||||||
{
|
TEST_ASSERT_NOT_NULL(topValue);
|
||||||
printf("Test 1: Erstes Element erfolgreich gepusht!\n");
|
TEST_ASSERT_EQUAL_INT(42, *topValue);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("Test 1: FEHLGESCHLAGEN!\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int wert2 = 12;
|
int wert2 = 12;
|
||||||
@@ -27,23 +33,19 @@ void testeStackBeschreiben()
|
|||||||
topValue = (int *)(stack->data);
|
topValue = (int *)(stack->data);
|
||||||
int *secondValue = (int *)((stack->next)->data);
|
int *secondValue = (int *)((stack->next)->data);
|
||||||
|
|
||||||
if(topValue != NULL && *topValue == 12.25 && secondValue != NULL && *secondValue == 42)
|
TEST_ASSERT_NOT_NULL(topValue);
|
||||||
{
|
TEST_ASSERT_EQUAL_INT(12, *topValue);
|
||||||
printf("Test 2: Zweites Element erfolgreich gepusht!\n");
|
TEST_ASSERT_NOT_NULL(secondValue);
|
||||||
}
|
TEST_ASSERT_EQUAL_INT(42, *secondValue);
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("Test 2: FEHLGESCHLAGEN!\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
printf("=== Ende Test: push() ===\n\n");
|
//printf("=== Ende Test: push() ===\n\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void testepop()
|
void testepop()
|
||||||
{
|
{
|
||||||
printf("=== Test: pop() ===\n");
|
//printf("=== Test: pop() ===\n");
|
||||||
|
|
||||||
StackNode *stack = NULL;
|
StackNode *stack = NULL;
|
||||||
int wert1 = 20;
|
int wert1 = 20;
|
||||||
@@ -56,21 +58,15 @@ void testepop()
|
|||||||
|
|
||||||
int *topValue = (int *)(stack->data);
|
int *topValue = (int *)(stack->data);
|
||||||
|
|
||||||
if(topValue != NULL && *topValue == 20)
|
TEST_ASSERT_NOT_NULL(topValue);
|
||||||
{
|
TEST_ASSERT_EQUAL_INT(20, *topValue);
|
||||||
printf("Test: Erstes Element erfolgreich gelöscht!\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("Test 1: FEHLGESCHLAGEN!\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("=== Ende Test: pop() ===\n\n");
|
//printf("=== Ende Test: pop() ===\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void testetop()
|
void testetop()
|
||||||
{
|
{
|
||||||
printf("=== Test: top() ===\n");
|
//printf("=== Test: top() ===\n");
|
||||||
|
|
||||||
StackNode *stack = NULL;
|
StackNode *stack = NULL;
|
||||||
int wert1 = 20;
|
int wert1 = 20;
|
||||||
@@ -81,21 +77,15 @@ void testetop()
|
|||||||
|
|
||||||
int *topValue = top(stack);
|
int *topValue = top(stack);
|
||||||
|
|
||||||
if(topValue != NULL && *topValue == 74)
|
TEST_ASSERT_NOT_NULL(topValue);
|
||||||
{
|
TEST_ASSERT_EQUAL_INT(74, *topValue);
|
||||||
printf("Test: top() gibt korrektes Element zurück!\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("Test: FEHLGESCHLAGEN!\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("=== Ende Test: top() ===\n\n");
|
//printf("=== Ende Test: top() ===\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void testeclearStack()
|
void testeclearStack()
|
||||||
{
|
{
|
||||||
printf("=== Test: clearStack() ===\n");
|
//printf("=== Test: clearStack() ===\n");
|
||||||
|
|
||||||
StackNode *stack = NULL;
|
StackNode *stack = NULL;
|
||||||
int wert1 = 20;
|
int wert1 = 20;
|
||||||
@@ -106,16 +96,25 @@ void testeclearStack()
|
|||||||
|
|
||||||
clearStack(stack);
|
clearStack(stack);
|
||||||
|
|
||||||
printf("Test: clearStack() aufgerufen. Speicher freigegeben.\n");
|
//printf("Test: clearStack() aufgerufen. Speicher freigegeben.\n");
|
||||||
printf("=== Ende Test: clearStack() ===\n\n");
|
//printf("=== Ende Test: clearStack() ===\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
testeStackBeschreiben();
|
UNITY_BEGIN();
|
||||||
|
|
||||||
|
//printf("...");
|
||||||
|
|
||||||
|
RUN_TEST(testeStackBeschreiben);
|
||||||
|
RUN_TEST(testepop);
|
||||||
|
RUN_TEST(testetop);
|
||||||
|
RUN_TEST(testeclearStack);
|
||||||
|
|
||||||
|
/*testeStackBeschreiben();
|
||||||
testepop();
|
testepop();
|
||||||
testetop();
|
testetop();
|
||||||
testeclearStack();
|
testeclearStack();*/
|
||||||
|
|
||||||
return 0;
|
return UNITY_END();
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user