normal Nodes working in addToTree()
This commit is contained in:
parent
517d363f3e
commit
36ac0d6d9d
10
bintree.c
10
bintree.c
@ -50,9 +50,7 @@ TreeNode *addToTree(TreeNode *root, const void *data, size_t dataSize, CompareFc
|
||||
|
||||
TreeNode *addToTreeRec(TreeNode *currentNode, TreeNode *newNode, CompareFctType compareFct, int *isDuplicate)
|
||||
{
|
||||
// printf("entered addRec\n");
|
||||
//printf("curdat = %d\n", currentNode->data);
|
||||
//printf("newdat = %d\n", newNode->data);
|
||||
printf("entered addRec\n");
|
||||
if (currentNode == NULL)
|
||||
{
|
||||
printf("currentNode == NULL\n");
|
||||
@ -63,17 +61,17 @@ TreeNode *addToTreeRec(TreeNode *currentNode, TreeNode *newNode, CompareFctType
|
||||
|
||||
return newNode;
|
||||
}
|
||||
else if (compareFct(currentNode->data, newNode->data) < 0)
|
||||
else if (compareFct(¤tNode->data, &newNode->data) < 0)
|
||||
{
|
||||
printf("compareFct(currentNode->data, newNode->data) < 0\n");
|
||||
currentNode->left = addToTreeRec(currentNode->left, newNode, compareFct, isDuplicate);
|
||||
}
|
||||
else if (compareFct(currentNode->data, newNode->data) > 0)
|
||||
else if (compareFct(¤tNode->data, &newNode->data) > 0)
|
||||
{
|
||||
printf("compareFct(currentNode->data, newNode->data) > 0\n");
|
||||
currentNode->right = addToTreeRec(currentNode->right, newNode, compareFct, isDuplicate);
|
||||
}
|
||||
else if (compareFct(currentNode->data, newNode->data) == 0)
|
||||
else if (compareFct(¤tNode->data, &newNode->data) == 0)
|
||||
{
|
||||
//duplicate
|
||||
printf("duplicate\n");
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "unity.h"
|
||||
#include "bintree.h"
|
||||
|
||||
@ -17,10 +18,13 @@ void tearDown(void) {
|
||||
static int compareIntEntries(const void *arg1, const void *arg2)
|
||||
{
|
||||
// printf("in comp\n");
|
||||
const int *entry1 = (const int *)arg1;
|
||||
const int *entry2 = (const int *)arg2;
|
||||
const int *entry1 = (const void *)arg1;
|
||||
const int *entry2 = (const void *)arg2;
|
||||
|
||||
// printf("const set\n");
|
||||
int result = entry2 - entry1;
|
||||
int result = *entry2 - *entry1;
|
||||
|
||||
// int result = entry2 - entry1;
|
||||
|
||||
// printf("exit comp\n");
|
||||
return result;
|
||||
@ -45,18 +49,25 @@ void test_addToTreeExpandsTreeCorrectly(void)
|
||||
|
||||
testRoot = addToTree(testRoot, &score1, sizeof(int), compareIntEntries, NULL);
|
||||
printf("add1passed\n");
|
||||
|
||||
testRoot = addToTree(testRoot, &score2, sizeof(int), compareIntEntries, NULL);
|
||||
printf("add2passed\n");
|
||||
|
||||
testRoot = addToTree(testRoot, &score3, sizeof(int), compareIntEntries, NULL);
|
||||
printf("add3passed\n");
|
||||
|
||||
testRoot = addToTree(testRoot, &score4, sizeof(int), compareIntEntries, NULL);
|
||||
printf("add4passed\n");
|
||||
|
||||
testRoot = addToTree(testRoot, &score5, sizeof(int), compareIntEntries, NULL);
|
||||
printf("add5passed\n");
|
||||
|
||||
testRoot = addToTree(testRoot, &score6, sizeof(int), compareIntEntries, NULL);
|
||||
printf("add6passed\n");
|
||||
/*
|
||||
testRoot = addToTree(testRoot, &score7, sizeof(int), compareIntEntries, NULL);
|
||||
printf("add7passed\n");
|
||||
*/
|
||||
|
||||
// Checking the Tree without Doubles
|
||||
TEST_ASSERT_NOT_NULL(testRoot);
|
||||
@ -70,7 +81,7 @@ void test_addToTreeExpandsTreeCorrectly(void)
|
||||
TEST_ASSERT_NOT_NULL(testRoot->right);
|
||||
TEST_ASSERT_EQUAL_UINT16(score3, testRoot->right->data);
|
||||
printf("node3passed\n");
|
||||
|
||||
|
||||
TEST_ASSERT_NOT_NULL(testRoot->left->left);
|
||||
TEST_ASSERT_EQUAL_UINT16(score4, testRoot->left->left->data);
|
||||
printf("node4passed\n");
|
||||
@ -78,7 +89,7 @@ void test_addToTreeExpandsTreeCorrectly(void)
|
||||
TEST_ASSERT_NOT_NULL(testRoot->left->right);
|
||||
TEST_ASSERT_EQUAL_UINT16(score5, testRoot->left->right->data);
|
||||
printf("node5passed\n");
|
||||
/*
|
||||
|
||||
TEST_ASSERT_NOT_NULL(testRoot->right->left);
|
||||
TEST_ASSERT_EQUAL_UINT16(score6, testRoot->right->left->data);
|
||||
printf("node6passed\n");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user