Compare commits

..

No commits in common. "7c3df62d86c9075251ad1e42ccc6f72afc5fcd75" and "14fa122f20b2d34f7884e73f08c1053ea8f5cf8c" have entirely different histories.

4 changed files with 14 additions and 55 deletions

View File

@ -1,6 +1,5 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h>
#include "stack.h" #include "stack.h"
#include "bintree.h" #include "bintree.h"
@ -109,42 +108,22 @@ void clearTreeRec(TreeNode *currentNode)
if (currentNode != NULL) if (currentNode != NULL)
{ {
clearTree(currentNode->left); clearTree(currentNode->left);
clearTree(currentNode->right);
clearNode(currentNode); clearNode(currentNode);
/* clearTree(currentNode->right);
printf("1\n");
free(&currentNode->data);
currentNode->data = NULL;
printf("2\n");
// free(currentNode);
// currentNode = NULL;
printf("3\n");
// */
} }
} }
void clearNode(TreeNode *node) void clearNode(TreeNode *node)
{ {
// printf("in clearNode\n"); free(node->data);
// printf("node-> data = %u\n", node->data);
// printf("node-> data = %u\n", _ADDRESSOF(node->data));
free(&node->data);
node->data = NULL; node->data = NULL;
// printf("node-> data = %u\n", &node->data);
// printf("data freed \n");
node->left = NULL; node->left = NULL;
node->right = NULL; node->right = NULL;
// printf("left & right = Null\n");
printf("node = %u\n", &node); free(node);
// printf("node = %u\n", _ADDRESSOF(node));
// free(node);
// printf("node = %d\n", node);
node = NULL; node = NULL;
printf("node = %u\n", &node);
printf("freed node\n");
} }

BIN
bintree.o

Binary file not shown.

View File

@ -1,6 +1,5 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h>
#include "unity.h" #include "unity.h"
#include "bintree.h" #include "bintree.h"
@ -114,7 +113,6 @@ void test_clearTreeworksLikeExpected(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);
testRoot = addToTree(testRoot, &score4, sizeof(int), compareIntEntries, NULL); testRoot = addToTree(testRoot, &score4, sizeof(int), compareIntEntries, NULL);
printf("Tree Filled\n");
// Save all Adresses // Save all Adresses
TreeNode *node1 = testRoot->left; TreeNode *node1 = testRoot->left;
@ -124,36 +122,18 @@ void test_clearTreeworksLikeExpected(void)
TreeNode *node5 = testRoot->right->left; TreeNode *node5 = testRoot->right->left;
TreeNode *node6 = testRoot->right->right; TreeNode *node6 = testRoot->right->right;
TreeNode *node7 = testRoot->left->left->left; TreeNode *node7 = testRoot->left->left->left;
printf("Adresses Saved\n");
clearTree(testRoot); clearTree(testRoot);
printf("Tree Cleared\n");
// Check if everything has been set to NULL // 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);
TEST_ASSERT_NULL(node1->data); TEST_ASSERT_NULL(node2);
// TEST_ASSERT_NULL(node1); TEST_ASSERT_NULL(node3);
TEST_ASSERT_NULL(node4);
TEST_ASSERT_NULL(node2->data); TEST_ASSERT_NULL(node5);
// TEST_ASSERT_NULL(node2); TEST_ASSERT_NULL(node6);
TEST_ASSERT_NULL(node7);
TEST_ASSERT_NULL(node3->data);
// TEST_ASSERT_NULL(node3);
TEST_ASSERT_NULL(node4->data);
// TEST_ASSERT_NULL(node4);
TEST_ASSERT_NULL(node5->data);
// TEST_ASSERT_NULL(node5);
TEST_ASSERT_NULL(node6->data);
// TEST_ASSERT_NULL(node6);
TEST_ASSERT_NULL(node7->data);
// TEST_ASSERT_NULL(node7);
} }
@ -198,9 +178,9 @@ int main()
UNITY_BEGIN(); UNITY_BEGIN();
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);
return UNITY_END(); return UNITY_END();

Binary file not shown.