-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cpp
82 lines (70 loc) · 2.3 KB
/
test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "generalTree.h"
#include <iostream>
using namespace std;
/*Test Data Class*/
struct testData {
int card;
int suit;
};
/*Print Tree Function*/
void printTree(linkedList<treeNode<testData>> * loopList, int tabs) {
if (loopList == nullptr) {
return;
}
for (uint8_t i = 0; i < loopList->size(); i++) {
treeNode<testData> * test = loopList->get(i)->dataPtr;
for (uint8_t j = 0; j < tabs; j++) {
cout << "\t";
}
cout << "Card: " << ((testData*)test->dataPtr)->card << " Suit: " << ((testData*)test->dataPtr)->suit << "\n";
printTree(test->nodes, tabs + 1);
}
}
/*Main Test Code*/
int main() {
generalTree<testData> * testTree = new generalTree<testData>();
int cardData[10] = {1, 5, 8, 7, 1, 10, 13, 2, 9, 4};
int suitData[10] = {3, 1, 3, 2, 0, 0, 1, 2, 0, 3};
for (uint8_t i = 0; i < 10; i++) {
testData * testAdd = new testData();
testAdd->card = cardData[i];
testAdd->suit = suitData[i];
if (i < 5) {
int dir[] = {};
testTree->add(dir, sizeof(dir)/sizeof(dir[0]), testAdd);
} else {
int dir[1] = {1};
testTree->add(dir, sizeof(dir)/sizeof(dir[0]), testAdd);
}
}
cout << "Inital data added:\n";
printTree(testTree->root, 1);
testData * testSet = new testData();
testSet->card = 56;
testSet->suit = 5;
int dirSet[2] = {1,1};
testTree->set(dirSet, sizeof(dirSet)/sizeof(dirSet[0]), testSet);
cout << "After set [1,1]:\n";
printTree(testTree->root, 1);
testData * testInsert = new testData();
testInsert->card = 100;
testInsert->suit = 6;
int dirInsert[1] = {3};
testTree->insert(dirInsert, sizeof(dirInsert)/sizeof(dirInsert[0]), testInsert);
cout << "After insert [3]:\n";
printTree(testTree->root, 1);
int dirRemove[1] = {4};
testTree->remove(dirRemove, sizeof(dirRemove)/sizeof(dirRemove[0]));
cout << "After remove [4]:\n";
printTree(testTree->root, 1);
int dirSwap1[2] = {1, 1};
int dirSwap2[1] = {3};
testTree->swap(dirSwap1, sizeof(dirSwap1)/sizeof(dirSwap1[0]), dirSwap2, sizeof(dirSwap2)/sizeof(dirSwap2[0]));
cout << "After swap [1,1] and [3]:\n";
printTree(testTree->root, 1);
cout << "Before clear:\n";
cout << "isEmpty: " << testTree->isEmpty() << "\n";
testTree->clear(&testTree->root);
cout << "After clear:\n";
cout << "isEmpty: " << testTree->isEmpty() << "\n";
}