Repository navigation
Expand file tree
/
Copy pathTest.cpp
More file actions
187 lines (173 loc) · 6.12 KB
/
Copy pathTest.cpp
File metadata and controls
187 lines (173 loc) · 6.12 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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#include "SortTest.h"
#include "Sorts.h"
#include "Timer.h"
#include <string>
#include <list>
TEST(CorrectnessTest, InsertionSortForVector) {
std::vector<int> vec = {9, 8, 7, 6, 5, 4, 3, 2, 1};
InsertionSort(vec.begin(), vec.end());
ASSERT_EQ(vec, std::vector<int>({1, 2, 3, 4, 5, 6, 7, 8, 9}));
}
TEST(CorrectnessTest, InsertionSortForString) {
std::string IAmString = "abcdeABCDE";
InsertionSort(IAmString.begin(), IAmString.end());
ASSERT_EQ(IAmString, std::string("ABCDEabcde"));
}
TEST(CorrectnessTest, InsertionSortForList) {
std::list<int> my_list = {9, 8, 7, 6, 5, 4, 3, 2, 1};
InsertionSort(my_list.begin(), my_list.end());
ASSERT_EQ(my_list, std::list<int>({1, 2, 3, 4, 5, 6, 7, 8, 9}));
}
TEST(CorrectnessTest, BubbleSortForVector) {
std::vector<int> vec = {9, 8, 7, 6, 5, 4, 3, 2, 1};
BubbleSort(vec.begin(), vec.end());
ASSERT_EQ(vec, std::vector<int>({1, 2, 3, 4, 5, 6, 7, 8, 9}));
}
TEST(CorrectnessTest, BubbleSortForString) {
std::string IAmString = "abcdeABCDE";
BubbleSort(IAmString.begin(), IAmString.end());
ASSERT_EQ(IAmString, std::string("ABCDEabcde"));
}
TEST(CorrectnessTest, BubbleSortForList) {
std::list<int> my_list = {9, 8, 7, 6, 5, 4, 3, 2, 1};
BubbleSort(my_list.begin(), my_list.end());
ASSERT_EQ(my_list, std::list<int>({1, 2, 3, 4, 5, 6, 7, 8, 9}));
}
TEST(CorrectnessTest, MergeSortForVector) {
std::vector<int> vec = {9, 8, 7, 6, 5, 4, 3, 2, 1};
MergeSort(vec.begin(), vec.end());
ASSERT_EQ(vec, std::vector<int>({1, 2, 3, 4, 5, 6, 7, 8, 9}));
}
TEST(CorrectnessTest, MergeSortForString) {
std::string IAmString = "abcdeABCDE";
MergeSort(IAmString.begin(), IAmString.end());
ASSERT_EQ(IAmString, std::string("ABCDEabcde"));
}
TEST(CorrectnessTest, MergeSortForList) {
std::list<int> my_list = {9, 8, 7, 6, 5, 4, 3, 2, 1};
MergeSort(my_list.begin(), my_list.end());
ASSERT_EQ(my_list, std::list<int>({1, 2, 3, 4, 5, 6, 7, 8, 9}));
}
TEST(CorrectnessTest, QuickSortForVector) {
std::vector<int> vec = {9, 8, 7, 6, 5, 4, 3, 2, 1};
QuickSort(vec.begin(), vec.end());
ASSERT_EQ(vec, std::vector<int>({1, 2, 3, 4, 5, 6, 7, 8, 9}));
}
TEST(CorrectnessTest, QuickSortForString) {
std::string IAmString = "abcdeABCDE";
QuickSort(IAmString.begin(), IAmString.end());
ASSERT_EQ(IAmString, std::string("ABCDEabcde"));
}
TEST(CorrectnessTest, QuickSortForList) {
std::list<int> my_list = {9, 8, 7, 6, 5, 4, 3, 2, 1};
QuickSort(my_list.begin(), my_list.end());
ASSERT_EQ(my_list, std::list<int>({1, 2, 3, 4, 5, 6, 7, 8, 9}));
}
//TEST_F(SortTest, TimerOfInsertionSort) {
// Timer timer("InsertionSort");
// timer.start();
// InsertionSort(arr_10.begin(), arr_10.end());
// timer.stop("arr_10");
// timer.start();
// InsertionSort(arr_100.begin(), arr_100.end());
// timer.stop("arr_100");
// timer.start();
// InsertionSort(arr_1000.begin(), arr_1000.end());
// timer.stop("arr_1000");
// timer.start();
// InsertionSort(arr_10000.begin(), arr_10000.end());
// timer.stop("arr_10000");
// timer.start();
// InsertionSort(arr_100000.begin(), arr_100000.end());
// timer.stop("arr_100000");
// timer.start();
// InsertionSort(arr_250000.begin(), arr_250000.end());
// timer.stop("arr_250000");
//}
//
//TEST_F(SortTest, TimerOfBubbleSort) {
// Timer timer("BubbleSort");
// timer.start();
// BubbleSort(arr_10.begin(), arr_10.end());
// timer.stop("arr_10");
// timer.start();
// BubbleSort(arr_100.begin(), arr_100.end());
// timer.stop("arr_100");
// timer.start();
// BubbleSort(arr_1000.begin(), arr_1000.end());
// timer.stop("arr_1000");
// timer.start();
// BubbleSort(arr_10000.begin(), arr_10000.end());
// timer.stop("arr_10000");
// timer.start();
// BubbleSort(arr_100000.begin(), arr_100000.end());
// timer.stop("arr_100000");
// timer.start();
// BubbleSort(arr_250000.begin(), arr_250000.end());
// timer.stop("arr_250000");
//}
//
//TEST_F(SortTest, TimerOfMergeSort) {
// Timer timer("MergeSort");
// timer.start();
// MergeSort(arr_10.begin(), arr_10.end());
// timer.stop("arr_10");
// timer.start();
// MergeSort(arr_100.begin(), arr_100.end());
// timer.stop("arr_100");
// timer.start();
// MergeSort(arr_1000.begin(), arr_1000.end());
// timer.stop("arr_1000");
// timer.start();
// MergeSort(arr_10000.begin(), arr_10000.end());
// timer.stop("arr_10000");
// timer.start();
// MergeSort(arr_100000.begin(), arr_100000.end());
// timer.stop("arr_100000");
// timer.start();
// MergeSort(arr_250000.begin(), arr_250000.end());
// timer.stop("arr_250000");
//}
//
//TEST_F(SortTest, TimerOfQuickSort) {
// Timer timer("QuickSort");
// timer.start();
// QuickSort(arr_10.begin(), arr_10.end());
// timer.stop("arr_10");
// timer.start();
// QuickSort(arr_100.begin(), arr_100.end());
// timer.stop("arr_100");
// timer.start();
// QuickSort(arr_1000.begin(), arr_1000.end());
// timer.stop("arr_1000");
// timer.start();
// QuickSort(arr_10000.begin(), arr_10000.end());
// timer.stop("arr_10000");
// timer.start();
// QuickSort(arr_100000.begin(), arr_100000.end());
// timer.stop("arr_100000");
// timer.start();
// QuickSort(arr_250000.begin(), arr_250000.end());
// timer.stop("arr_250000");
//}
TEST_F(SortTest, TimerOfStdSort) {
Timer timer("STDSORT");
timer.start();
std::sort(arr_10.begin(), arr_10.end());
timer.stop("arr_10");
timer.start();
std::sort(arr_100.begin(), arr_100.end());
timer.stop("arr_100");
timer.start();
std::sort(arr_1000.begin(), arr_1000.end());
timer.stop("arr_1000");
timer.start();
std::sort(arr_10000.begin(), arr_10000.end());
timer.stop("arr_10000");
timer.start();
std::sort(arr_100000.begin(), arr_100000.end());
timer.stop("arr_100000");
timer.start();
std::sort(arr_250000.begin(), arr_250000.end());
timer.stop("arr_250000");
}