Skip to content

Commit 2309a8f

Browse files
committed
Implemented red black tree unit test.
1 parent c3da5e7 commit 2309a8f

File tree

4 files changed

+356
-40
lines changed

4 files changed

+356
-40
lines changed

DataStructure/Trees/Headers/RedBlackTree.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,23 @@ RBTree *redBlackTreeInitialization(void (*freeItem)(void *), int (*cmp)(const vo
6363

6464
void rBTreeInsert(RBTree *tree, void *item);
6565

66-
void rBInOrderTraversal(RBTree *tree, void (*printFun)(const void *, COLOR));
67-
6866
void rBTreeDelete(RBTree *tree, void *item);
6967

7068
void *rBTreeDeleteWtoFr(RBTree *tree, void *item);
7169

72-
void *rbTreeGet(RBTree *tree, char *item);
70+
void *rbTreeGet(RBTree *tree, void *item);
7371

7472
void **rBTreeToArray(RBTree *rbTree);
7573

7674
int rBTreeGetSize(RBTree *tree);
7775

7876
int rBTreeContains(RBTree *tree, void *item);
7977

78+
void rBTreePrint(RBTree *tree, void (*printFun)(const void *, COLOR));
79+
8080
void rBPreOrderTraversal(RBTree *tree, void (*printFun)(const void *, COLOR));
8181

82-
void rBTreePrint(RBTree *tree, void (*printFun)(const void *, COLOR));
82+
void rBInOrderTraversal(RBTree *tree, void (*printFun)(const void *, COLOR));
8383

8484
void rBPostOrderTraversal(RBTree *tree, void (*printFun)(const void *, COLOR));
8585

DataStructure/Trees/Sources/RedBlackTree.c

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void RBTreeToArrayRecurs(RBNode* node , void **arr, int *i);
5656

5757
void printRBTreeHelper(RBNode *root, int space, void (*printFun)(const void *item, COLOR color));
5858

59-
void *rbTreeGetR(RBTree *rbTree, RBNode *node, char *item);
59+
void *rbTreeGetR(RBTree *rbTree, RBNode *node, void *item);
6060

6161
int rBTreeContainsR(RBTree *tree, RBNode *root, void *item);
6262

@@ -1326,15 +1326,30 @@ void rBTreePrint(RBTree *tree, void (*printFun)(const void *, COLOR)) {
13261326
**/
13271327

13281328
void printRBTreeHelper(RBNode *root, int space, void (*printFun)(const void *, COLOR)){
1329-
if (root == NULL){
1329+
1330+
if (root == NULL)
13301331
return;
1331-
}
1332+
13321333
space += 10;
1334+
13331335
printRBTreeHelper(root->right, space, printFun);
1334-
printf("\n");
1335-
for (int i = 10; i < space; i++) printf(" ");
1336+
1337+
#ifdef CU_TEST_H
1338+
#else
1339+
printf("\n");
1340+
#endif
1341+
1342+
for (int i = 10; i < space; i++) {
1343+
#ifdef CU_TEST_H
1344+
#else
1345+
printf(" ");
1346+
#endif
1347+
}
1348+
13361349
(printFun)(root->key, root->color);
1350+
13371351
printRBTreeHelper(root->left, space, printFun);
1352+
13381353
}
13391354

13401355

@@ -1351,7 +1366,7 @@ void printRBTreeHelper(RBNode *root, int space, void (*printFun)(const void *, C
13511366
* @return the return will be the item address if it's existed other wise it will be NULL
13521367
*/
13531368

1354-
void *rbTreeGet(RBTree *tree, char *item) {
1369+
void *rbTreeGet(RBTree *tree, void *item) {
13551370

13561371
if (tree == NULL) {
13571372
#ifdef CU_TEST_H
@@ -1391,7 +1406,7 @@ void *rbTreeGet(RBTree *tree, char *item) {
13911406
* @return Returns the Found node.
13921407
**/
13931408

1394-
void *rbTreeGetR(RBTree *rbTree, RBNode *node, char *item) {
1409+
void *rbTreeGetR(RBTree *rbTree, RBNode *node, void *item) {
13951410
if(node == NULL)
13961411
return NULL;
13971412

Unit Test/Tests/Tests.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
int main(void) {
2424

25-
/*vectorUnitTest();
25+
vectorUnitTest();
2626
arrayListUnitTest();
2727
linkedListUnitTest();
2828
doublyLinkedListUnitTest();
@@ -41,8 +41,7 @@ int main(void) {
4141
hashSetUnitTest();
4242
directedGraphUnitTest();
4343
undirectedGraphUnitTest();
44-
trieUnitTest();*/
45-
44+
trieUnitTest();
4645
redBlackTreeUnitTest();
4746

4847

0 commit comments

Comments
 (0)