]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/compute/test/test_any_all_none_of.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / compute / test / test_any_all_none_of.cpp
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
3 //
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
7 //
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
10
11 #define BOOST_TEST_MODULE TestAnyAllNoneOf
12 #include <boost/test/unit_test.hpp>
13
14 #include <limits>
15 #include <cmath>
16
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>
22
23 #include "context_setup.hpp"
24
25 namespace bc = boost::compute;
26 namespace compute = boost::compute;
27
28 BOOST_AUTO_TEST_CASE(any_all_none_of)
29 {
30 int data[] = { 1, 2, 3, 4, 5, 6 };
31 bc::vector<int> v(data, data + 6, queue);
32
33 using ::boost::compute::_1;
34
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);
43 }
44
45 BOOST_AUTO_TEST_CASE(any_nan_inf)
46 {
47 using ::boost::compute::_1;
48 using ::boost::compute::lambda::isinf;
49 using ::boost::compute::lambda::isnan;
50 using ::boost::compute::lambda::isfinite;
51
52 float nan = std::sqrt(-1.f);
53 float inf = std::numeric_limits<float>::infinity();
54
55 float data[] = { 1.2f, 2.3f, nan, nan, 3.4f, inf, 4.5f, inf };
56 compute::vector<float> vector(data, data + 8, queue);
57
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);
72 }
73
74 BOOST_AUTO_TEST_CASE(any_of_doctest)
75 {
76 using boost::compute::lambda::_1;
77
78 int data[] = { 1, 2, 3, 4 };
79 boost::compute::vector<int> v(data, data + 4, queue);
80
81 bool result =
82 //! [any_of]
83 boost::compute::any_of(v.begin(), v.end(), _1 < 0, queue);
84 //! [any_of]
85
86 BOOST_CHECK(result == false);
87 }
88
89 BOOST_AUTO_TEST_SUITE_END()