]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/compute/test/test_find.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 TestFind
12 #include <boost/test/unit_test.hpp>
14 #include <boost/compute/command_queue.hpp>
15 #include <boost/compute/lambda.hpp>
16 #include <boost/compute/algorithm/copy.hpp>
17 #include <boost/compute/algorithm/find.hpp>
18 #include <boost/compute/algorithm/find_if.hpp>
19 #include <boost/compute/algorithm/find_if_not.hpp>
20 #include <boost/compute/container/vector.hpp>
21 #include <boost/compute/iterator/constant_buffer_iterator.hpp>
23 #include "check_macros.hpp"
24 #include "context_setup.hpp"
26 namespace bc
= boost::compute
;
27 namespace compute
= boost::compute
;
29 BOOST_AUTO_TEST_CASE(find_int
)
31 int data
[] = { 9, 15, 1, 4, 9, 9, 4, 15, 12, 1 };
32 bc::vector
<int> vector(data
, data
+ 10, queue
);
34 bc::vector
<int>::iterator iter
=
35 bc::find(vector
.begin(), vector
.end(), 4, queue
);
36 BOOST_CHECK(iter
== vector
.begin() + 3);
37 BOOST_CHECK_EQUAL(*iter
, 4);
39 iter
= bc::find(vector
.begin(), vector
.end(), 12, queue
);
40 BOOST_CHECK(iter
== vector
.begin() + 8);
41 BOOST_CHECK_EQUAL(*iter
, 12);
43 iter
= bc::find(vector
.begin(), vector
.end(), 1, queue
);
44 BOOST_CHECK(iter
== vector
.begin() + 2);
45 BOOST_CHECK_EQUAL(*iter
, 1);
47 iter
= bc::find(vector
.begin(), vector
.end(), 9, queue
);
48 BOOST_CHECK(iter
== vector
.begin());
49 BOOST_CHECK_EQUAL(*iter
, 9);
51 iter
= bc::find(vector
.begin(), vector
.end(), 100, queue
);
52 BOOST_CHECK(iter
== vector
.end());
55 BOOST_AUTO_TEST_CASE(find_int2
)
59 int data
[] = { 1, 2, 4, 5, 7, 8 };
60 bc::vector
<int2_
> vector(
61 reinterpret_cast<int2_
*>(data
),
62 reinterpret_cast<int2_
*>(data
) + 3,
65 CHECK_RANGE_EQUAL(int2_
, 3, vector
, (int2_(1, 2), int2_(4, 5), int2_(7, 8)));
67 bc::vector
<int2_
>::iterator iter
=
68 bc::find(vector
.begin(), vector
.end(), int2_(4, 5), queue
);
69 BOOST_CHECK(iter
== vector
.begin() + 1);
70 BOOST_CHECK_EQUAL(*iter
, int2_(4, 5));
72 iter
= bc::find(vector
.begin(), vector
.end(), int2_(10, 11), queue
);
73 BOOST_CHECK(iter
== vector
.end());
76 BOOST_AUTO_TEST_CASE(find_if_not_int
)
78 int data
[] = { 2, 4, 6, 8, 1, 3, 5, 7, 9 };
79 bc::vector
<int> vector(data
, data
+ 9, queue
);
81 bc::vector
<int>::iterator iter
=
82 bc::find_if_not(vector
.begin(), vector
.end(), bc::_1
== 2, queue
);
83 BOOST_CHECK(iter
== vector
.begin() + 1);
84 BOOST_CHECK_EQUAL(*iter
, 4);
87 BOOST_AUTO_TEST_CASE(find_point_by_distance
)
89 using boost::compute::float2_
;
90 using boost::compute::lambda::_1
;
91 using boost::compute::lambda::distance
;
94 float2_(0, 0), float2_(2, 2), float2_(4, 4), float2_(8, 8)
96 compute::vector
<float2_
> vec(points
, points
+ 4, queue
);
98 compute::vector
<float2_
>::iterator iter
=
99 compute::find_if(vec
.begin(), vec
.end(), distance(_1
, float2_(5, 5)) < 1.5f
, queue
);
100 BOOST_CHECK(iter
== vec
.begin() + 2);
103 compute::copy_n(iter
, 1, &value
, queue
);
104 BOOST_CHECK_EQUAL(value
, float2_(4, 4));
107 BOOST_AUTO_TEST_SUITE_END()