-
Notifications
You must be signed in to change notification settings - Fork 0
/
SortingTests.cpp
101 lines (83 loc) · 2.3 KB
/
SortingTests.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
92
93
94
95
96
97
98
99
100
101
#include <iostream>
#include <gtest/gtest.h>
#include <vector>
#include <iostream>
#include "Sorting.cpp"
using namespace std;
class SortingTest : public ::testing::Test {
protected:
vector<int> ascAges;
vector<int> randAges;
vector<int> desAges;
vector<int> lrgAges;
vector<int> sortedLrgAges;
virtual void SetUp() {
ascAges.push_back(10);
ascAges.push_back(20);
ascAges.push_back(30);
randAges.push_back(20);
randAges.push_back(30);
randAges.push_back(10);
desAges.push_back(30);
desAges.push_back(20);
desAges.push_back(10);
lrgAges.push_back(50);
lrgAges.push_back(5);
lrgAges.push_back(60);
lrgAges.push_back(60);
lrgAges.push_back(-10);
lrgAges.push_back(45);
lrgAges.push_back(99);
lrgAges.push_back(0);
lrgAges.push_back(31);
lrgAges.push_back(200);
sortedLrgAges.push_back(-10);
sortedLrgAges.push_back(0);
sortedLrgAges.push_back(5);
sortedLrgAges.push_back(31);
sortedLrgAges.push_back(45);
sortedLrgAges.push_back(50);
sortedLrgAges.push_back(60);
sortedLrgAges.push_back(60);
sortedLrgAges.push_back(99);
sortedLrgAges.push_back(200);
}
};
TEST_F(SortingTest, ShouldReturnTheSameOrderIfAlreadySorted) {
Sorting sorting;
vector<int> sorted = sorting.selectionSort(ascAges);
ASSERT_EQ(sorted.front(), ascAges.front());
ASSERT_EQ(sorted.back(), ascAges.back());
}
TEST_F(SortingTest, ShouldReturnSortedIfNotSorted) {
Sorting sorting;
vector<int> sorted = sorting.selectionSort(randAges);
ASSERT_EQ(10, sorted.front());
ASSERT_EQ(30, sorted.back());
}
TEST_F(SortingTest, ShouldReturnAscendingSortedIfAlreadyDescending) {
Sorting sorting;
vector<int> sorted = sorting.selectionSort(desAges);
ASSERT_EQ(10, sorted.front());
ASSERT_EQ(30, sorted.back());
}
TEST_F(SortingTest, ShouldReturnSortedForLargeGroupOfNumber) {
Sorting sorting;
vector<int> actual = sorting.selectionSort(lrgAges);
for (int idx = 0; idx < lrgAges.size(); idx++) {
ASSERT_EQ(sortedLrgAges.at(idx), actual.at(idx));
}
}
TEST_F(SortingTest, ShouldSwapVariableContents) {
Sorting sorting;
int a = 10, b = 20;
sorting.swap(a, b);
ASSERT_EQ(10, b);
ASSERT_EQ(20, a);
}
// Use the Google Test main that is linked into the framework. It does something
// like this:
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}