Compare commits

..

No commits in common. "5b576589e36867c54fd3990ad84ad37763d12fdc" and "39965a95c4c78c772748e14593e26182fae6ca68" have entirely different histories.

8 changed files with 4 additions and 124 deletions

4
.gitignore vendored
View File

@ -2,7 +2,3 @@ doble_initial.exe
highscores.txt
runStackTest.exe
stack.o
runNumbersTest.exe
numbers.o
.vscode/launch.json
.vscode/settings.json

View File

@ -12,26 +12,7 @@
// 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 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.
@ -51,12 +32,5 @@ void clearTree(TreeNode *root)
// Returns the number of entries in the tree given by root.
unsigned int treeSize(const TreeNode *root)
{
int counter = 0;
if(root != NULL)
{
treeSize(root->left);
counter++;
treeSize(root->right);
}
}

View File

@ -44,12 +44,6 @@ unitTests: stack.o test_stack.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
# --------------------------
# 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
# --------------------------

View File

@ -32,33 +32,19 @@ unsigned int checkArray(unsigned int *array, unsigned int len, unsigned int numb
unsigned int *createNumbers(unsigned int len)
{
srand(time(NULL));
unsigned int *array = (unsigned int*)malloc(len * sizeof(unsigned int));
int randomNr, counter;
if(array == NULL)
{
return NULL;
}
unsigned int array[len];
unsigned int randomNr;
for (int i = 0; i < len; i++)
{
counter = 0;
do
{
if (counter == 9)
{
return NULL;
}
randomNr = rand() % (2 * len + 1);
counter++;
randomNr = rand() % 2 * len + 1;
} while (!checkArray(array, i, randomNr));
array[i] = randomNr;
printf("%u ", array[i]);
}
printf("\n");
return array;
}

BIN
numbers.o Normal file

Binary file not shown.

BIN
runNumbersTest.exe Normal file

Binary file not shown.

View File

@ -1,56 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include "bintree.h"
#include "unity.h"
void sizeTest()
{
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));
}
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(sizeTest);
return UNITY_END();
}

View File

@ -3,20 +3,6 @@
#include "numbers.h"
#include "unity.h"
void createNumbersTest()
{
unsigned int *array;
unsigned int len = 6;
array = createNumbers(len);
for (int i = 0; i < len; i++)
{
printf("%u ", array[i]);
}
printf("\n");
TEST_ASSERT_NOT_NULL(array);
}
void duplicateTest()
{
unsigned int array[6] = {1, 4, 5, 2, 3, 1};
@ -40,7 +26,7 @@ int main()
UNITY_BEGIN();
printf("============================\nNumbers tests\n============================\n");
RUN_TEST(createNumbersTest);
RUN_TEST(duplicateTest);
return UNITY_END();