-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
56 lines (47 loc) · 1.5 KB
/
test.cpp
File metadata and controls
56 lines (47 loc) · 1.5 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
#include <gtest/gtest.h>
#include <algorithm>
/// Only simple test cases are demonstrated,
/// because it is easier to use them for people,
/// who don't want to go deep in GTests
template <typename T>
class Less {
public:
bool operator()(const T& first, const T& second) { return first < second; }
};
template <typename T>
class Greater {
public:
bool operator()(const T& first, const T& second) { return second < first; }
};
/// Example with sort
// =============================================
TEST(Basic, Less) {
std::vector<int> test_vec{1, 10, 3, 5, 2, 19, 0};
std::vector<int> result{0, 1, 2, 3, 5, 10, 19};
std::sort(test_vec.begin(), test_vec.end(), Less<int>());
for (size_t i = 0; i < test_vec.size(); ++i) {
ASSERT_EQ(test_vec[i], result[i]);
}
}
TEST(Basic, Greater) {
std::vector<int> test_vec{1, 10, 3, 5, 2, 19, 0};
std::vector<int> result{19, 10, 5, 3, 2, 1, 0};
std::sort(test_vec.begin(), test_vec.end(), Greater<int>());
for (size_t i = 0; i < test_vec.size(); ++i) {
ASSERT_EQ(test_vec[i], result[i]);
}
}
// =============================================
TEST(Stress, Less) {
/// TODO: make a lot of tests with generating different data
/// more examples in other tasks
// std::random_device rand_dev;
// std::mt19937 gen;
// std::uniform_int_distribution<size_t> distrib;
// for (size_t iteration = 0; iteration < 10000000; ++iteration) {
// }
}
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}