-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cpp
47 lines (34 loc) · 1.15 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
#include <deepstate/DeepState.hpp>
#include "avl.h"
using namespace deepstate;
TEST(AVLTree, InsertionAndSearch) {
AVL tree;
int key = DeepState_IntInRange(0, 100);
tree.insert(key);
ASSERT_TRUE(tree.search(key)) << "Key " << key << " was not found after insertion";
}
TEST(AVLTree, Removal) {
AVL tree;
int key = DeepState_IntInRange(0, 100);
tree.insert(key);
tree.remove(key);
ASSERT_FALSE(tree.search(key)) << "Key " << key << " was found after removal";
}
TEST(AVLTree, HeightAndBalance) {
AVL tree;
int keys[] = {50, 25, 75, 10, 30, 60, 80};
for (int key : keys) {
tree.insert(key);
}
ASSERT_LE(tree.getHeight(), 4) << "Tree height exceeded expected value";
ASSERT_LE(abs(tree.getBalanceFactor()), 1) << "Tree balance factor exceeded expected value";
}
TEST(AVLTree, MinAndMaxValue) {
AVL tree;
int keys[] = {50, 25, 75, 10, 30, 60, 80};
for (int key : keys) {
tree.insert(key);
}
ASSERT_EQ(tree.getMinValue(), 10) << "Incorrect minimum value";
ASSERT_EQ(tree.getMaxValue(), 80) << "Incorrect maximum value";
}