generated from freudenreichan/info2Praktikum-DobleSpiel
clearTree + Test
This commit is contained in:
parent
f4cf06ff53
commit
11b25b75d2
@ -96,7 +96,19 @@ void *nextTreeData(TreeNode *root)
|
|||||||
// Releases all memory resources (including data copies).
|
// Releases all memory resources (including data copies).
|
||||||
void clearTree(TreeNode *root)
|
void clearTree(TreeNode *root)
|
||||||
{
|
{
|
||||||
|
if (root == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
clearTree(root->left);
|
||||||
|
clearTree(root->right);
|
||||||
|
|
||||||
|
if (root->data != NULL) {
|
||||||
|
free(root->data);
|
||||||
|
root->data = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the number of entries in the tree given by root.
|
// Returns the number of entries in the tree given by root.
|
||||||
|
|||||||
Binary file not shown.
@ -73,6 +73,23 @@ static void testNextTreeDataInorderTraversal(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void testClearTree() {
|
||||||
|
TreeNode *root = NULL;
|
||||||
|
int values[] = {10, 5, 15};
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for(i = 0; i < 3; i++) {
|
||||||
|
root = addToTree(root, &values[i], sizeof(int), compareInt, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_ASSERT_NOT_NULL(root);
|
||||||
|
|
||||||
|
clearTree(root);
|
||||||
|
root = NULL;
|
||||||
|
|
||||||
|
TEST_ASSERT_NULL(root);
|
||||||
|
}
|
||||||
|
|
||||||
void setUp(void){
|
void setUp(void){
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -89,6 +106,8 @@ int main(){
|
|||||||
RUN_TEST(testAddToTreeNewRoot);
|
RUN_TEST(testAddToTreeNewRoot);
|
||||||
RUN_TEST(testAddToTreeToExistingRoot);
|
RUN_TEST(testAddToTreeToExistingRoot);
|
||||||
RUN_TEST(testAddToTreeNoData);
|
RUN_TEST(testAddToTreeNoData);
|
||||||
|
RUN_TEST(testNextTreeDataInorderTraversal);
|
||||||
|
RUN_TEST(testClearTree);
|
||||||
|
|
||||||
return UNITY_END();
|
return UNITY_END();
|
||||||
}
|
}
|
||||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user