]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/compute/test/test_any_all_none_of.cpp
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
11 #define BOOST_TEST_MODULE TestAnyAllNoneOf
12 #include <boost/test/unit_test.hpp>
17 #include <boost/compute/lambda.hpp>
18 #include <boost/compute/algorithm/all_of.hpp>
19 #include <boost/compute/algorithm/any_of.hpp>
20 #include <boost/compute/algorithm/none_of.hpp>
21 #include <boost/compute/container/vector.hpp>
23 #include "context_setup.hpp"
25 namespace bc
= boost::compute
;
26 namespace compute
= boost::compute
;
28 BOOST_AUTO_TEST_CASE(any_all_none_of
)
30 int data
[] = { 1, 2, 3, 4, 5, 6 };
31 bc::vector
<int> v(data
, data
+ 6, queue
);
33 using ::boost::compute::_1
;
35 BOOST_CHECK(bc::any_of(v
.begin(), v
.end(), _1
== 6) == true);
36 BOOST_CHECK(bc::any_of(v
.begin(), v
.end(), _1
== 9) == false);
37 BOOST_CHECK(bc::none_of(v
.begin(), v
.end(), _1
== 6) == false);
38 BOOST_CHECK(bc::none_of(v
.begin(), v
.end(), _1
== 9) == true);
39 BOOST_CHECK(bc::all_of(v
.begin(), v
.end(), _1
== 6) == false);
40 BOOST_CHECK(bc::all_of(v
.begin(), v
.end(), _1
< 9) == true);
41 BOOST_CHECK(bc::all_of(v
.begin(), v
.end(), _1
< 6) == false);
42 BOOST_CHECK(bc::all_of(v
.begin(), v
.end(), _1
>= 1) == true);
45 BOOST_AUTO_TEST_CASE(any_nan_inf
)
47 using ::boost::compute::_1
;
48 using ::boost::compute::lambda::isinf
;
49 using ::boost::compute::lambda::isnan
;
50 using ::boost::compute::lambda::isfinite
;
52 float nan
= std::sqrt(-1.f
);
53 float inf
= std::numeric_limits
<float>::infinity();
55 float data
[] = { 1.2f
, 2.3f
, nan
, nan
, 3.4f
, inf
, 4.5f
, inf
};
56 compute::vector
<float> vector(data
, data
+ 8, queue
);
58 BOOST_CHECK(compute::any_of(vector
.begin(), vector
.end(),
59 isinf(_1
) || isnan(_1
), queue
) == true);
60 BOOST_CHECK(compute::any_of(vector
.begin(), vector
.end(),
61 isfinite(_1
), queue
) == true);
62 BOOST_CHECK(compute::all_of(vector
.begin(), vector
.end(),
63 isfinite(_1
), queue
) == false);
64 BOOST_CHECK(compute::all_of(vector
.begin(), vector
.begin() + 2,
65 isfinite(_1
), queue
) == true);
66 BOOST_CHECK(compute::all_of(vector
.begin() + 2, vector
.begin() + 4,
67 isnan(_1
), queue
) == true);
68 BOOST_CHECK(compute::none_of(vector
.begin(), vector
.end(),
69 isinf(_1
), queue
) == false);
70 BOOST_CHECK(compute::none_of(vector
.begin(), vector
.begin() + 4,
71 isinf(_1
), queue
) == true);
74 BOOST_AUTO_TEST_CASE(any_of_doctest
)
76 using boost::compute::lambda::_1
;
78 int data
[] = { 1, 2, 3, 4 };
79 boost::compute::vector
<int> v(data
, data
+ 4, queue
);
83 boost::compute::any_of(v
.begin(), v
.end(), _1
< 0, queue
);
86 BOOST_CHECK(result
== false);
89 BOOST_AUTO_TEST_SUITE_END()