-
Notifications
You must be signed in to change notification settings - Fork 0
/
red_black_test.h
55 lines (55 loc) · 1.44 KB
/
red_black_test.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
#pragma once
#include <iostream>
#include <vector>
#include <gtest/gtest.h>
#include "red_black.h"
namespace red_black {
class red_black_test : public ::testing::Test {
protected:
red_black_tree<int, int> tree;
void SetUp() override {
}
};
TEST_F(red_black_test, calling_insert) {
EXPECT_TRUE(tree.empty());
tree.insert(1, 1);
EXPECT_FALSE(tree.empty());
EXPECT_EQ(tree.size(), 1);
tree.insert(2, 2);
EXPECT_EQ(tree.size(), 2);
tree.insert(3, 3);
EXPECT_EQ(tree.size(), 3);
}
TEST_F(red_black_test, calling_minimum) {
EXPECT_THROW(tree.minimum(), std::out_of_range);
tree.insert(1, 1);
EXPECT_EQ(tree.minimum().first, 1);
tree.insert(2, 2);
EXPECT_EQ(tree.minimum().first, 1);
tree.insert(3, 3);
EXPECT_EQ(tree.minimum().first, 1);
}
TEST_F(red_black_test, calling_maximum) {
EXPECT_THROW(tree.maximum(), std::out_of_range);
tree.insert(1, 1);
EXPECT_EQ(tree.maximum().first, 1);
tree.insert(2, 2);
EXPECT_EQ(tree.maximum().first, 2);
tree.insert(3, 3);
EXPECT_EQ(tree.maximum().first, 3);
}
TEST_F(red_black_test, calling_random_behavior){
std::set<int> temp;
for(auto i =0; i<20; ++i)
temp.insert(std::rand());
EXPECT_TRUE(tree.empty());
for(auto beg = temp.begin(); beg!= temp.end(); ++beg)
tree.insert(*beg, 0);
EXPECT_FALSE(tree.empty());
EXPECT_EQ(temp.size(), tree.size());
EXPECT_EQ(*temp.begin(), tree.minimum().first);
auto temp_max = temp.end();
--temp_max;
EXPECT_EQ(*temp_max, tree.maximum().first);
}
} // namespace red_black