@@ -90,6 +90,28 @@ TEST_CASE("copy_n", "[alg][algorithm]") {
9090 }
9191}
9292
93+ TEST_CASE (" count" , " [alg][algorithm]" ) {
94+ for (auto num_threads : test_thread_counts) {
95+ ttp::task_thread_pool pool (num_threads);
96+
97+ for (auto vec_size : test_arr_sizes) {
98+ auto haystack = iota_vector (vec_size);
99+
100+ {
101+ int needle = 5 ;
102+ auto seq = std::count (poolstl::par_if<>(false ), haystack.cbegin (), haystack.cend (), needle);
103+ auto par = std::count (poolstl::par_pool (pool), haystack.cbegin (), haystack.cend (), needle);
104+ REQUIRE (seq == par);
105+ }
106+ {
107+ auto pred = [&](auto x) { return x % 2 == 0 ; };
108+ auto seq = std::count_if (poolstl::par_if<>(false ), haystack.cbegin (), haystack.cend (), pred);
109+ auto par = std::count_if (poolstl::par_pool (pool), haystack.cbegin (), haystack.cend (), pred);
110+ REQUIRE (seq == par);
111+ }
112+ }
113+ }
114+ }
93115
94116TEST_CASE (" fill" , " [alg][algorithm]" ) {
95117 for (auto num_threads : test_thread_counts) {
@@ -367,15 +389,13 @@ TEST_CASE("execution_policies", "[execution]") {
367389 ttp::task_thread_pool pool;
368390 std::vector<int > v = {0 , 1 , 2 , 3 , 4 , 5 };
369391
370- REQUIRE (15 == std::reduce (poolstl::par, v.cbegin (), v.cend ()));
371- REQUIRE (15 == std::reduce (poolstl::par_pool (pool), v.cbegin (), v.cend ()));
372- #if POOLSTL_HAVE_CXX17_LIB
373- REQUIRE (15 == std::reduce (poolstl::seq, v.cbegin (), v.cend ()));
374- REQUIRE (15 == std::reduce (poolstl::par_if<>(false ), v.cbegin (), v.cend ()));
375- REQUIRE (15 == std::reduce (poolstl::par_if<>(true ), v.cbegin (), v.cend ()));
376- REQUIRE (15 == std::reduce (poolstl::par_if_pool<>(false , pool), v.cbegin (), v.cend ()));
377- REQUIRE (15 == std::reduce (poolstl::par_if_pool<>(true , pool), v.cbegin (), v.cend ()));
378- #endif
392+ REQUIRE (1 == std::count (poolstl::par, v.cbegin (), v.cend (), 5 ));
393+ REQUIRE (1 == std::count (poolstl::par_pool (pool), v.cbegin (), v.cend (), 5 ));
394+ REQUIRE (1 == std::count (poolstl::seq, v.cbegin (), v.cend (), 5 ));
395+ REQUIRE (1 == std::count (poolstl::par_if<>(false ), v.cbegin (), v.cend (), 5 ));
396+ REQUIRE (1 == std::count (poolstl::par_if<>(true ), v.cbegin (), v.cend (), 5 ));
397+ REQUIRE (1 == std::count (poolstl::par_if_pool<>(false , pool), v.cbegin (), v.cend (), 5 ));
398+ REQUIRE (1 == std::count (poolstl::par_if_pool<>(true , pool), v.cbegin (), v.cend (), 5 ));
379399}
380400
381401std::mt19937 rng{1 };
0 commit comments