-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.cpp
91 lines (89 loc) · 2.87 KB
/
tests.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
83
84
85
86
87
88
89
90
91
#include "CppUnitTest.h"
#include "rb_tree.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace TepNik;
namespace tests
{
TEST_CLASS(tests){
public :
TEST_METHOD(insert_in_empty_container)
{
rb_tree<int, int> tree;
tree.insert(1, 2);
std::vector<int> keys{1}, values{2};
Assert::IsTrue(tree.get_keys() == keys && tree.get_values() == values);
}
TEST_METHOD(test_copy_constructor)
{
rb_tree<int, int> tree1;
tree1.insert(1, 2);
tree1.insert(2, 2);
tree1.insert(3, 2);
rb_tree<int, int> tree2 = tree1;
Assert::IsTrue(tree1.get_keys() == tree2.get_keys() && tree1.get_values() == tree2.get_values());
}
TEST_METHOD(erase_element)
{
rb_tree<int, int> tree;
tree.insert(1, 2);
tree.insert(2, 2);
tree.insert(3, 2);
tree.erase(2);
std::vector<int> keys{1, 3}, values{2, 2};
Assert::IsTrue(tree.get_keys() == keys && tree.get_values() == values);
}
TEST_METHOD(test_copy_operator)
{
rb_tree<int, int> tree1;
tree1.insert(1, 2);
tree1.insert(2, 2);
tree1.insert(3, 2);
rb_tree<int, int> tree2;
tree2 = tree1;
Assert::IsTrue(tree1.get_keys() == tree2.get_keys() && tree1.get_values() == tree2.get_values());
}
TEST_METHOD(test_equal_operator)
{
rb_tree<int, int> tree1, tree2;
tree1.insert(1, 2);
tree1.insert(2, 2);
tree1.insert(3, 2);
tree2.insert(1, 2);
tree2.insert(2, 2);
tree2.insert(3, 2);
Assert::IsTrue(tree1 == tree2);
}
TEST_METHOD(test_find_function)
{
rb_tree<int, int> tree1;
tree1.insert(1, 2);
tree1.insert(2, 2);
tree1.insert(3, 2);
int *temp = tree1.find(1);
Assert::IsTrue(temp && *temp == 2);
temp = tree1.find(5);
Assert::IsTrue(temp == nullptr);
}
TEST_METHOD(test_get_keys_values)
{
rb_tree<int, int> tree1;
tree1.insert(1, 2);
tree1.insert(2, 2);
tree1.insert(3, 2);
auto keys_t = tree1.get_keys();
auto values_t = tree1.get_values();
std::vector<int> keys{1, 2, 3}, values{2, 2, 2};
Assert::IsTrue(keys_t == keys && values_t == values);
}
TEST_METHOD(test_size_function)
{
rb_tree<int, int> tree1;
tree1.insert(1, 2);
tree1.insert(2, 2);
tree1.insert(3, 2);
tree1.erase(1);
tree1.erase(5);
Assert::IsTrue(tree1.size() == 2);
}
};
}