-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestBST.cpp
More file actions
90 lines (72 loc) · 2.13 KB
/
Copy pathtestBST.cpp
File metadata and controls
90 lines (72 loc) · 2.13 KB
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
#include <bits/stdc++.h>
#include <iostream>
#include <iterator>
#include <utility>
#include <cassert>
#include "bst.h"
typedef std::function<bool()> testType;
bool testSimple1() {
BST tree;
tree.insert(tree.root, 1);
tree.insert(tree.root, 1);
tree.insert(tree.root, 1);
tree.insert(tree.root, 1);
tree.insert(tree.root, 6);
if (tree.get_max_score(tree.root) != 7) return false;
tree.erase(6);
if (tree.get_max_score(tree.root) != 5) return false;
return true;
}
bool testSimple2() {
BST tree;
tree.insert(tree.root, 2);
tree.insert(tree.root, 2);
tree.insert(tree.root, 2);
tree.insert(tree.root, 2);
tree.insert(tree.root, 2);
if (tree.get_max_score(tree.root) != 7) return false;
tree.insert(tree.root, 2);
if (tree.get_max_score(tree.root) != 8) return false;
tree.erase(2);
if (tree.get_max_score(tree.root) != 7) return false;
tree.erase(2);
tree.insert(tree.root, 2);
if (tree.get_max_score(tree.root) != 7) return false;
return true;
}
bool testLargeConsecutive1() {
BST tree;
for (int i = 1; i < 1000; ++i) {
tree.insert(tree.root, i);
if (tree.get_max_score(tree.root) != i+1) return false;
}
return true;
}
bool testLargeConsecutive2() {
BST tree;
for (int i = 1000; i > 0; -- i) {
tree.insert(tree.root, i);
if (tree.get_max_score(tree.root) != i+1) return false;
tree.erase(i);
if (tree.get_max_score(tree.root) != 1) return false;
}
return true;
}
int main()
{
std::initializer_list<testType> testArray {testSimple1,
testSimple2,
testLargeConsecutive1,
testLargeConsecutive2};
size_t index = 0;
size_t failedTests = 0;
for (auto test : testArray) {
if (!test()) {
std::cout << "Test #" << index << " was wrong.\n";
failedTests += 1;
}
index += 1;
}
std::cout << failedTests << "/" << index << " tests failed.\n";
return 0;
}