-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunittest_unsignedint.cpp
More file actions
121 lines (108 loc) · 2.81 KB
/
unittest_unsignedint.cpp
File metadata and controls
121 lines (108 loc) · 2.81 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
/*
* Playing around with parallelizing std::partial_sum
* by Paul Dreik https://www.pauldreik.se/
* LICENSE: http://www.boost.org/LICENSE_1_0.txt
*/
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include "include/parpartial.h"
#include <type_traits>
#include <vector>
// the truth (from std)
template <class T> auto theTruth(T input) {
std::partial_sum(std::cbegin(input), std::cend(input), std::begin(input));
return input;
}
// my variants
template <class T> auto myImplementation(T input, int implementation) {
switch (implementation) {
case 1:
whatever::par_partial_sum(std::cbegin(input), std::cend(input),
std::begin(input));
break;
case 2:
whatever::par_partial_sum_v2(std::cbegin(input), std::cend(input),
std::begin(input));
break;
case 3:
whatever::par_partial_sum_async(std::cbegin(input), std::cend(input),
std::begin(input));
break;
default:
throw "oops";
}
return input;
}
namespace {
void testEmpty(int implementation) {
const std::vector<unsigned> Z;
auto expected = Z;
auto truth = theTruth(Z);
BOOST_REQUIRE(1);
auto mine = myImplementation(Z, implementation);
BOOST_REQUIRE(expected == truth);
BOOST_REQUIRE(expected == mine);
BOOST_REQUIRE(truth.size() == 0);
}
}
BOOST_AUTO_TEST_CASE(test_empty) {
testEmpty(1);
testEmpty(2);
testEmpty(3);
}
namespace {
void testZeros(int implementation) {
const std::vector<unsigned> Z(5);
auto expected = Z;
auto truth = theTruth(Z);
BOOST_REQUIRE(1);
auto mine = myImplementation(Z, implementation);
BOOST_REQUIRE(expected == truth);
BOOST_REQUIRE(expected == mine);
BOOST_REQUIRE(truth.size() == 5);
}
}
BOOST_AUTO_TEST_CASE(test_with_zeros) {
testZeros(1);
testZeros(2);
testZeros(3);
}
namespace {
void testOnes(int implementation) {
const std::vector<unsigned> Z(5, 1);
const std::vector<unsigned> expected{1, 2, 3, 4, 5};
BOOST_REQUIRE(1);
auto truth = theTruth(Z);
BOOST_REQUIRE(1);
auto mine = myImplementation(Z, implementation);
BOOST_REQUIRE(expected == truth);
BOOST_REQUIRE(expected == mine);
BOOST_REQUIRE(truth.size() == 5);
}
}
BOOST_AUTO_TEST_CASE(test_with_ones) {
testOnes(1);
testOnes(2);
testOnes(3);
}
namespace {
void testLargeOnes(int implementation) {
const std::vector<unsigned> Z(500, 1);
std::vector<unsigned> expected(500);
for (std::size_t i = 0; i < Z.size(); ++i) {
expected.at(i) = 1 + i;
}
BOOST_REQUIRE(1);
auto truth = theTruth(Z);
BOOST_REQUIRE(1);
auto mine = myImplementation(Z, implementation);
BOOST_REQUIRE(expected == truth);
BOOST_REQUIRE(expected == mine);
BOOST_REQUIRE(truth.size() == 500);
}
}
BOOST_AUTO_TEST_CASE(test_with_large_ones) {
testLargeOnes(1);
testLargeOnes(2);
testLargeOnes(3);
}