Skip to content

Commit

Permalink
Improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
alugowski committed Dec 14, 2023
1 parent 345429a commit cddf3a9
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 12 deletions.
5 changes: 3 additions & 2 deletions include/poolstl/execution
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <memory>
#include <mutex>
#include <stdexcept>
#include <type_traits>

#include "internal/task_thread_pool.hpp"
Expand Down Expand Up @@ -46,8 +47,8 @@ namespace poolstl {
*/
struct sequenced_policy : public poolstl_policy {
POOLSTL_NO_DISCARD ttp::task_thread_pool* pool() const {
// never called
return nullptr;
// never called, but must exist for C++11 support
throw std::runtime_error("poolSTL: requested thread pool for seq policy.");
}

POOLSTL_NO_DISCARD bool par_allowed() const {
Expand Down
9 changes: 9 additions & 0 deletions tests/cpp11_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,18 @@

int main() {
std::vector<int> v = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};

// sequential
std::for_each(poolstl::seq, v.cbegin(), v.cend(), [](int x) {
std::cout << x;
});
std::cout << std::endl;

// parallel
std::for_each(poolstl::par, v.cbegin(), v.cend(), [](int x) {
std::cout << x;
});
std::cout << std::endl;

return 0;
}
64 changes: 54 additions & 10 deletions tests/poolstl_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,13 +293,25 @@ TEST_CASE("sort", "[alg][algorithm]") {
case 1: scramble(source); break;
default: break;
}
std::vector<int> dest1(source);
std::vector<int> dest2(source);

std::sort(dest1.begin(), dest1.end());
std::sort(poolstl::par.on(pool), dest2.begin(), dest2.end());
for (auto which_impl : {0, 1}) {
std::vector<int> dest1(source);
std::vector<int> dest2(source);

std::sort(dest1.begin(), dest1.end());
switch (which_impl) {
case 0:
std::sort(poolstl::par_if(false), dest2.begin(), dest2.end());
break;
case 1:
std::sort(poolstl::par.on(pool), dest2.begin(), dest2.end());
break;
default:
break;
}

REQUIRE(dest1 == dest2);
REQUIRE(dest1 == dest2);
}
}
}
}
Expand All @@ -322,13 +334,25 @@ TEST_CASE("stable_sort", "[alg][algorithm]") {
case 1: scramble(source); break;
default: break;
}
std::vector<stable_sort_element> dest1(source);
std::vector<stable_sort_element> dest2(source);

std::stable_sort(dest1.begin(), dest1.end());
std::stable_sort(poolstl::par.on(pool), dest2.begin(), dest2.end());
for (auto which_impl : {0, 1}) {
std::vector<stable_sort_element> dest1(source);
std::vector<stable_sort_element> dest2(source);

std::sort(dest1.begin(), dest1.end());
switch (which_impl) {
case 0:
std::stable_sort(poolstl::par_if(false), dest2.begin(), dest2.end());
break;
case 1:
std::stable_sort(poolstl::par.on(pool), dest2.begin(), dest2.end());
break;
default:
break;
}

REQUIRE(dest1 == dest2);
REQUIRE(dest1 == dest2);
}
}
}
}
Expand Down Expand Up @@ -606,4 +630,24 @@ TEST_CASE("iota_iter(def)", "[iterator]") {
REQUIRE(*c == 0);
}

struct gettable {
explicit gettable(int v): value(v) {}
int value;
POOLSTL_NO_DISCARD int get() const { return value; }
};

TEST_CASE("getting_iter", "[coverage]") {
// Tests for required functionality not exercised in the proper tests.
std::vector<gettable> vec = {gettable(0), gettable(1), gettable(2), gettable(3)};
auto iter = poolstl::internal::getting_iter<std::vector<gettable>::iterator>(vec.begin());
REQUIRE(*iter == 0);
REQUIRE(iter[0] == 0);
REQUIRE(iter[2] == 2);
}

TEST_CASE("seq", "[coverage]") {
// Tests for required functionality not exercised in the proper tests.
REQUIRE_THROWS(poolstl::seq.pool());
}

std::mt19937 rng{1};

0 comments on commit cddf3a9

Please sign in to comment.