-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_chsort.cpp
More file actions
76 lines (56 loc) · 1.71 KB
/
test_chsort.cpp
File metadata and controls
76 lines (56 loc) · 1.71 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
// ------------------------------------------------
// You should not need to edit any files below here
// ------------------------------------------------
#include "catch.hpp"
#include <string>
#include <sstream>
#include "chsort.hpp"
template <typename T>
bool is_sorted(const T &vec) {
for (auto i = 1; i < vec.size(); ++i) {
if (vec[i-1] > vec[i]) {
return false;
}
}
return true;
}
TEST_CASE("Sequential sort of a vector of integers", "[chsort]") {
// Test vector
std::vector<int> v = {2, 4, 1, 3};
// CHSort for an int vector with zero additional threads (sequential)
CHSort<std::vector<int>> chsort(0);
// Sort
chsort(v);
// Test
REQUIRE(is_sorted(v) == true);
}
TEST_CASE("Sequential sort of a vector of strings", "[chsort]") {
// Test vector
std::vector<std::string> v = {"d", "a", "c", "b"};
// CHSort for a string vector with zero additional threads (sequential)
CHSort<std::vector<std::string>> chsort(0);
// Sort
chsort(v);
// Test
REQUIRE(is_sorted(v) == true);
}
TEST_CASE("Parallel sort of a vector of integers", "[chsort]") {
// Test vector
std::vector<int> v = {2, 4, 1, 3};
// CHSort for an int vector with two additional threads (parallel)
CHSort<std::vector<int>> chsort(2);
// Sort
chsort(v);
// Test
REQUIRE(is_sorted(v) == true);
}
TEST_CASE("Parallel sort of a vector of strings", "[chsort]") {
// Test vector
std::vector<std::string> v = {"d", "a", "c", "b"};
// CHSort for a string vector with two additional threads (parallel)
CHSort<std::vector<std::string>> chsort(2);
// Sort
chsort(v);
// Test
REQUIRE(is_sorted(v) == true);
}