Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
804294b96e |
3
.gitignore
vendored
3
.gitignore
vendored
@ -6,6 +6,3 @@ runNumbersTest.exe
|
|||||||
numbers.o
|
numbers.o
|
||||||
.vscode/launch.json
|
.vscode/launch.json
|
||||||
.vscode/settings.json
|
.vscode/settings.json
|
||||||
*.o
|
|
||||||
*.exe
|
|
||||||
runBintreeTest
|
|
||||||
|
|||||||
18
bintree.c
18
bintree.c
@ -12,26 +12,8 @@
|
|||||||
// if isDuplicate is NULL, otherwise ignores duplicates and sets isDuplicate to 1 (or to 0 if a new entry is added).
|
// if isDuplicate is NULL, otherwise ignores duplicates and sets isDuplicate to 1 (or to 0 if a new entry is added).
|
||||||
TreeNode *addToTree(TreeNode *root, const void *data, size_t dataSize, CompareFctType compareFct, int *isDuplicate)
|
TreeNode *addToTree(TreeNode *root, const void *data, size_t dataSize, CompareFctType compareFct, int *isDuplicate)
|
||||||
{
|
{
|
||||||
TreeNode newNode = {data, NULL, NULL};
|
|
||||||
|
|
||||||
|
|
||||||
if(root == NULL)
|
|
||||||
{
|
|
||||||
return &newNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data < root->data)
|
|
||||||
{
|
|
||||||
root->left = addToTree(root->left, data, dataSize,compareFct, isDuplicate);
|
|
||||||
}
|
|
||||||
else if(data > root->data)
|
|
||||||
{
|
|
||||||
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, the next entry of the last tree given is returned in ordering direction.
|
// Iterates over the tree given by root. Follows the usage of strtok. If tree is NULL, the next entry of the last tree given is returned in ordering direction.
|
||||||
|
|||||||
6
makefile
6
makefile
@ -44,12 +44,6 @@ unitTests: stack.o test_stack.c $(unityfolder)/unity.c
|
|||||||
numbersTests: numbers.o test_numbers.c $(unityfolder)/unity.c
|
numbersTests: numbers.o test_numbers.c $(unityfolder)/unity.c
|
||||||
$(CC) $(FLAGS) -I$(unityfolder) -o runNumbersTest test_numbers.c numbers.o $(unityfolder)/unity.c
|
$(CC) $(FLAGS) -I$(unityfolder) -o runNumbersTest test_numbers.c numbers.o $(unityfolder)/unity.c
|
||||||
|
|
||||||
# --------------------------
|
|
||||||
# bintree.c Tests
|
|
||||||
# --------------------------
|
|
||||||
bintreeTests: bintree.o test_bintree.c $(unityfolder)/unity.c
|
|
||||||
$(CC) $(FLAGS) -I$(unityfolder) -o runBintreeTest test_bintree.c bintree.o $(unityfolder)/unity.c
|
|
||||||
|
|
||||||
# --------------------------
|
# --------------------------
|
||||||
# Clean
|
# Clean
|
||||||
# --------------------------
|
# --------------------------
|
||||||
|
|||||||
BIN
runNumbersTest.exe
Normal file
BIN
runNumbersTest.exe
Normal file
Binary file not shown.
@ -1,60 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include "bintree.h"
|
|
||||||
#include "unity.h"
|
|
||||||
|
|
||||||
|
|
||||||
void treeTest()
|
|
||||||
{
|
|
||||||
TreeNode root;
|
|
||||||
TreeNode node1;
|
|
||||||
TreeNode node2;
|
|
||||||
|
|
||||||
int dataRoot = 2;
|
|
||||||
int dataNode1 = 1;
|
|
||||||
int dataNode2 = 3;
|
|
||||||
|
|
||||||
|
|
||||||
root.data = &dataRoot;
|
|
||||||
root.left = &node1;
|
|
||||||
root.right = &node2;
|
|
||||||
|
|
||||||
node1.data = &dataNode1;
|
|
||||||
node1.left = NULL;
|
|
||||||
node1.right = NULL;
|
|
||||||
|
|
||||||
node2.data = &dataNode2;
|
|
||||||
node2.left = NULL;
|
|
||||||
node2.right = NULL;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_INT(3,treeSize(&root));
|
|
||||||
|
|
||||||
|
|
||||||
clearTree(&root);
|
|
||||||
TEST_ASSERT_EQUAL_INT(0,treeSize(&root));
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
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(treeTest);
|
|
||||||
|
|
||||||
return UNITY_END();
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user