2 // { dg-options "-std=gnu++17 -ltbb" }
3 // { dg-do run { target c++17 } }
4 // { dg-require-effective-target tbb-backend }
6 //===-- all_of.pass.cpp ---------------------------------------------------===//
8 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
9 // See https://llvm.org/LICENSE.txt for license information.
10 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
12 //===----------------------------------------------------------------------===//
14 #include "pstl/pstl_test_config.h"
16 #ifdef PSTL_STANDALONE_TESTS
17 #include "pstl/execution"
18 #include "pstl/algorithm"
22 #endif // PSTL_STANDALONE_TESTS
24 #include "pstl/test_utils.h"
27 TODO: consider implementing the following tests for a better code coverage
29 - bad input argument (if applicable)
30 - data corruption around/of input and output
31 - correctly work with nested parallelism
32 - check that algorithm does not require anything more than is described in its requirements section
35 using namespace TestUtils
;
39 template <typename ExecutionPolicy
, typename Iterator
, typename Predicate
>
41 operator()(ExecutionPolicy
&& exec
, Iterator begin
, Iterator end
, Predicate pred
, bool expected
)
44 auto actualr
= std::all_of(exec
, begin
, end
, pred
);
45 EXPECT_EQ(expected
, actualr
, "result for all_of");
55 Parity(bool parity_
) : parity(parity_
) {}
57 operator()(T value
) const
59 return (size_t(value
) ^ parity
) % 2 == 0;
67 for (size_t n
= 0; n
<= 100000; n
= n
<= 16 ? n
+ 1 : size_t(3.1415 * n
))
70 // Sequence of odd values
71 Sequence
<T
> in(n
, [n
, bits
](size_t k
) { return T(2 * HashBits(n
, bits
- 1) ^ 1); });
73 // Even value, or false when T is bool.
74 T
spike(2 * HashBits(n
, bits
- 1));
75 Sequence
<T
> inCopy(in
);
77 invoke_on_all_policies(test_all_of(), in
.begin(), in
.end(), Parity
<T
>(1), true);
78 invoke_on_all_policies(test_all_of(), in
.cbegin(), in
.cend(), Parity
<T
>(1), true);
79 EXPECT_EQ(in
, inCopy
, "all_of modified input sequence");
83 in
[2 * n
/ 3] = spike
;
84 invoke_on_all_policies(test_all_of(), in
.begin(), in
.end(), Parity
<T
>(1), false);
85 invoke_on_all_policies(test_all_of(), in
.cbegin(), in
.cend(), Parity
<T
>(1), false);
87 // Sprinkle in a few more misses
90 invoke_on_all_policies(test_all_of(), in
.begin(), in
.end(), Parity
<T
>(1), false);
91 invoke_on_all_policies(test_all_of(), in
.cbegin(), in
.cend(), Parity
<T
>(1), false);
98 template <typename Policy
, typename Iterator
>
100 operator()(Policy
&& exec
, Iterator iter
)
102 auto is_even
= [&](float64_t v
) {
103 uint32_t i
= (uint32_t)v
;
106 all_of(exec
, iter
, iter
, non_const(is_even
));
113 test
<int32_t>(8 * sizeof(int32_t));
114 test
<uint16_t>(8 * sizeof(uint16_t));
116 #if !_PSTL_ICC_16_17_TEST_REDUCTION_BOOL_TYPE_RELEASE_64_BROKEN
120 test_algo_basic_single
<int32_t>(run_for_rnd_fw
<test_non_const
>());
122 std::cout
<< done() << std::endl
;