clear Tree and test now working corectly
This commit is contained in:
parent
144648886f
commit
8754182f79
@ -135,18 +135,21 @@ void clearNode(TreeNode *node)
|
||||
// printf("in clearNode\n");
|
||||
// printf("node-> data = %u\n", node->data);
|
||||
// printf("node-> data = %u\n", _ADDRESSOF(node->data));
|
||||
// printf("data = %p\n", node->data);
|
||||
free(node->data);
|
||||
node->data = NULL;
|
||||
// printf("data = %p\n", node->data);
|
||||
// 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 = %p\n", node);
|
||||
// printf("node = %u\n", _ADDRESSOF(node));
|
||||
free(node);
|
||||
// printf("node = %d\n", node);
|
||||
node = NULL;
|
||||
// printf("node = %p\n", node);
|
||||
// printf("node = %u\n", &node);
|
||||
// printf("freed node\n");
|
||||
}
|
||||
|
||||
@ -80,7 +80,7 @@ void test_addToTreeExpandsTreeCorrectly(void)
|
||||
TEST_ASSERT_EQUAL_UINT16(1, testIsDouble);
|
||||
|
||||
|
||||
// clearTree(testRoot);
|
||||
clearTree(testRoot);
|
||||
}
|
||||
|
||||
|
||||
@ -92,6 +92,7 @@ void test_nextTreeDataReturnsNextDataCorrectly(void)
|
||||
}
|
||||
|
||||
|
||||
|
||||
// test if clear Tree frees all node.name and node memory AND sets them to zero
|
||||
// aditionally tests if the memoryspaces have been cleared
|
||||
void test_clearTreeworksLikeExpected(void)
|
||||
@ -113,30 +114,28 @@ 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);
|
||||
printf("Tree Filled\n");
|
||||
// printf("Tree Filled\n");
|
||||
|
||||
// Save all Adresses
|
||||
TreeNode *node1 = testRoot->left;
|
||||
// Save all Adresses
|
||||
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;
|
||||
|
||||
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");
|
||||
|
||||
clearTree(testRoot);
|
||||
printf("Tree Cleared\n");
|
||||
// printf("Adresses Saved\n");
|
||||
|
||||
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(testRoot);
|
||||
|
||||
//TEST_ASSERT_NULL(node1->data);
|
||||
// TEST_ASSERT_NULL(node1);
|
||||
/*
|
||||
|
||||
TEST_ASSERT_NULL(node2->data);
|
||||
// TEST_ASSERT_NULL(node2);
|
||||
|
||||
@ -199,7 +198,7 @@ int main()
|
||||
UNITY_BEGIN();
|
||||
|
||||
printf("\n============================\nBinary Tree tests\n============================\n");
|
||||
// RUN_TEST(test_addToTreeExpandsTreeCorrectly);
|
||||
RUN_TEST(test_addToTreeExpandsTreeCorrectly);
|
||||
// RUN_TEST(test_nextTreeDataReturnsNextDataCorrectly);
|
||||
RUN_TEST(test_clearTreeworksLikeExpected);
|
||||
// RUN_TEST(test_treeSizeWorkingLikeExpected);
|
||||
|
||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user