-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.h
105 lines (90 loc) · 3.31 KB
/
tests.h
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#pragma once
#include "test_framework.h"
void TestKLP() {
binary_tree<int> bt({8, 3, 10, 1, 6, 14, 4, 7, 13});
vector<int> correct_result = {8, 3, 1, 6, 4, 7, 10, 14, 13};
AssertEqual(bt.klp_tree(), correct_result, "Error");
}
void TestKPL() {
binary_tree<int> bt({8, 3, 10, 1, 6, 14, 4, 7, 13});
vector<int> correct_result = {8, 10, 14, 13, 3, 6, 7, 4, 1};
AssertEqual(bt.kpl_tree(), correct_result, "Error");
}
void TestLPK() {
binary_tree<int> bt({8, 3, 10, 1, 6, 14, 4, 7, 13});
vector<int> correct_result = {1, 4, 7, 6, 3, 13, 14, 10, 8};
AssertEqual(bt.lpk_tree(), correct_result, "Error");
}
void TestLKP() {
binary_tree<int> bt({8, 3, 10, 1, 6, 14, 4, 7, 13});
vector<int> correct_result = {1, 3, 4, 6, 7, 8, 10, 13, 14};
AssertEqual(bt.lkp_tree(), correct_result, "Error");
}
void TestPLK() {
binary_tree<int> bt({8, 3, 10, 1, 6, 14, 4, 7, 13});
vector<int> correct_result = {13, 14, 10, 7, 4, 6, 1, 3, 8};
AssertEqual(bt.plk_tree(), correct_result, "Error");
}
void TestPKL() {
binary_tree<int> bt({8, 3, 10, 1, 6, 14, 4, 7, 13});
vector<int> correct_result = {14, 13, 10, 8, 7, 6, 4, 3, 1};
AssertEqual(bt.pkl_tree(), correct_result, "Error");
}
void TestAddElement() {
binary_tree<int> bt({8, 3, 10, 1, 6, 14, 4, 7, 13});
vector<int> correct_result = {8, 3, 1, 6, 4, 7, 10, 9, 14, 13};
bt.AddElement(9);
AssertEqual(bt.klp_tree(), correct_result, "Error");
}
void TestSearchElement() {
binary_tree<int> bt({8, 3, 10, 1, 6, 14, 4, 7, 13});
bool res1 = bt.SearchElement(7);
bool res2 = bt.SearchElement(15);
AssertEqual(res1, true, "Error");
AssertEqual(res2, false, "Error");
}
void TestDeleteElement() {
binary_tree<int> bt({8, 3, 10, 1, 6, 14, 4, 7, 13});
bt.DeleteElement(10);
vector<int> correct_result = {8, 3, 1, 6, 4, 7, 14, 13};
AssertEqual(bt.klp_tree(), correct_result, "Error");
}
void TestMap() {
binary_tree<int> bt({8, 3, 10, 1, 6, 14, 4, 7, 13});
bt.Map(decrement);
vector<int> correct_result = {7, 2, 0, 5, 3, 6, 9, 13, 12};
AssertEqual(bt.klp_tree(), correct_result, "Error");
}
void TestWhere() {
binary_tree<int> bt({8, 3, 10, 1, 6, 14, 4, 7, 13});
bt.Where(more_then_three);
vector<int> correct_result = {8, 6, 4, 7, 10, 14, 13};
AssertEqual(bt.klp_tree(), correct_result, "Error");
}
void TestReduce() {
binary_tree<int> bt({8, 3, 10, 1, 6, 14, 4, 7, 13});
int result = bt.Reduce(multiply_items, 2);
int correct_result = 14'676'480;
AssertEqual(result, correct_result, "Error");
}
void TestSubTree() {
binary_tree<int> bt({8, 3, 10, 1, 6, 14, 4, 7, 13});
vector<int> correct_result = {6, 4, 7};
AssertEqual((*bt.SubTree(6)).klp_tree(), correct_result, "Error");
}
void TestAll() {
TestRunner tr;
tr.RunTest(TestKLP, "Test KLP");
tr.RunTest(TestKPL, "Test KPL");
tr.RunTest(TestLPK, "Test LPK");
tr.RunTest(TestLKP, "Test LKP");
tr.RunTest(TestPLK, "Test PLK");
tr.RunTest(TestPKL, "Test PKL");
tr.RunTest(TestAddElement, "Test Add Element");
tr.RunTest(TestSearchElement, "Test Search Element");
tr.RunTest(TestDeleteElement, "Test Delete Element");
tr.RunTest(TestMap, "Test Map");
tr.RunTest(TestWhere, "Test Where");
tr.RunTest(TestReduce, "Test Reduce");
tr.RunTest(TestSubTree, "Test SubTree");
}