wrote test_addToTreeExpandsTreeCorrectly()
This commit is contained in:
parent
e523b5462d
commit
1ead9595ce
@ -5,19 +5,72 @@
|
||||
#define MAX_TEST_NAME_LEN 10
|
||||
|
||||
|
||||
typedef struct
|
||||
static int compareIntEntries(const void *arg1, const void *arg2)
|
||||
{
|
||||
char name[MAX_TEST_NAME_LEN];
|
||||
int score;
|
||||
} HighscoreEntry;
|
||||
const int *entry1 = (const int *)arg1;
|
||||
const int *entry2 = (const int *)arg2;
|
||||
|
||||
int result = *entry2 - *entry1;
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// test if addToTree expands tree correctly
|
||||
// by going down the path where the given pice of data is expected
|
||||
// and checking if the pice of data is found there
|
||||
void test_addToTreeExpandsTreeCorrectlyNoDoubles(void)
|
||||
void test_addToTreeExpandsTreeCorrectly(void)
|
||||
{
|
||||
|
||||
TreeNode *testRoot = NULL;
|
||||
int *testIsDouble = 0;
|
||||
int score1 = 12;
|
||||
int score2 = 6;
|
||||
int score3 = 18;
|
||||
int score4 = 3;
|
||||
int score5 = 9;
|
||||
int score6 = 15;
|
||||
int score7 = 21;
|
||||
|
||||
|
||||
testRoot = addToTree(testRoot, &score1, sizeof(int), compareIntEntries, NULL);
|
||||
testRoot = addToTree(testRoot, &score2, sizeof(int), compareIntEntries, NULL);
|
||||
testRoot = addToTree(testRoot, &score3, sizeof(int), compareIntEntries, NULL);
|
||||
testRoot = addToTree(testRoot, &score4, sizeof(int), compareIntEntries, NULL);
|
||||
testRoot = addToTree(testRoot, &score5, sizeof(int), compareIntEntries, NULL);
|
||||
testRoot = addToTree(testRoot, &score6, sizeof(int), compareIntEntries, NULL);
|
||||
testRoot = addToTree(testRoot, &score7, sizeof(int), compareIntEntries, NULL);
|
||||
|
||||
// Checking the Tree without Doubles
|
||||
TEST_ASSERT_NOT_NULL(testRoot);
|
||||
TEST_ASSERT_EQUAL_UINT16(score1, testRoot);
|
||||
TEST_ASSERT_NOT_NULL(testRoot->left);
|
||||
TEST_ASSERT_EQUAL_UINT16(score2, testRoot->left);
|
||||
TEST_ASSERT_NOT_NULL(testRoot->right);
|
||||
TEST_ASSERT_EQUAL_UINT16(score3, testRoot->right);
|
||||
TEST_ASSERT_NOT_NULL(testRoot->left->left);
|
||||
TEST_ASSERT_EQUAL_UINT16(score4, testRoot->left->left);
|
||||
TEST_ASSERT_NOT_NULL(testRoot->left->right);
|
||||
TEST_ASSERT_EQUAL_UINT16(score5, testRoot->left->right);
|
||||
TEST_ASSERT_NOT_NULL(testRoot->right->left);
|
||||
TEST_ASSERT_EQUAL_UINT16(score6, testRoot->right->left);
|
||||
TEST_ASSERT_NOT_NULL(testRoot->right->right);
|
||||
TEST_ASSERT_EQUAL_UINT16(score7, testRoot->right->right);
|
||||
|
||||
// Adding Double
|
||||
testRoot = addToTree(testRoot, &score4, sizeof(int), compareIntEntries, NULL);
|
||||
|
||||
TEST_ASSERT_NOT_NULL(testRoot->left->left->left);
|
||||
TEST_ASSERT_EQUAL_UINT16(score4, testRoot->left->left->left);
|
||||
|
||||
// Trying to add Double while Doubles not Permitted
|
||||
testRoot = addToTree(testRoot, &score7, sizeof(int), compareIntEntries, testIsDouble);
|
||||
|
||||
TEST_ASSERT_NULL(testRoot->right->right->left);
|
||||
TEST_ASSERT_EQUAL_UINT16(1, testIsDouble);
|
||||
|
||||
|
||||
clearTree(testRoot);
|
||||
}
|
||||
|
||||
|
||||
@ -27,6 +80,10 @@ void test_addToTreeExpandsTreeCorrectlyNoDoubles(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)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
// tests if treeSize returns correct amount of nodes in Tree
|
||||
|
||||
BIN
bintreeTests.exe
BIN
bintreeTests.exe
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user