• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 TestAdjacentFind
12 #include <boost/test/unit_test.hpp>
13 
14 #include <boost/compute/command_queue.hpp>
15 #include <boost/compute/algorithm/adjacent_find.hpp>
16 #include <boost/compute/algorithm/fill.hpp>
17 #include <boost/compute/algorithm/iota.hpp>
18 #include <boost/compute/container/vector.hpp>
19 
20 #include "context_setup.hpp"
21 
22 namespace compute = boost::compute;
23 
BOOST_AUTO_TEST_CASE(adjacent_find_int)24 BOOST_AUTO_TEST_CASE(adjacent_find_int)
25 {
26     int data[] = { 1, 3, 5, 5, 6, 7, 7, 8 };
27     compute::vector<int> vec(data, data + 8, queue);
28 
29     compute::vector<int>::iterator iter =
30         compute::adjacent_find(vec.begin(), vec.end(), queue);
31     BOOST_CHECK(iter == vec.begin() + 2);
32 }
33 
BOOST_AUTO_TEST_CASE(adjacent_find_int2)34 BOOST_AUTO_TEST_CASE(adjacent_find_int2)
35 {
36     using compute::int2_;
37 
38     compute::vector<int2_> vec(context);
39     vec.push_back(int2_(1, 2), queue);
40     vec.push_back(int2_(3, 4), queue);
41     vec.push_back(int2_(5, 6), queue);
42     vec.push_back(int2_(7, 8), queue);
43     vec.push_back(int2_(7, 8), queue);
44 
45     compute::vector<int2_>::iterator iter =
46         compute::adjacent_find(vec.begin(), vec.end(), queue);
47     BOOST_CHECK(iter == vec.begin() + 3);
48 }
49 
BOOST_AUTO_TEST_CASE(adjacent_find_iota)50 BOOST_AUTO_TEST_CASE(adjacent_find_iota)
51 {
52     compute::vector<int> vec(2048, context);
53     compute::iota(vec.begin(), vec.end(), 1, queue);
54     BOOST_VERIFY(
55         compute::adjacent_find(vec.begin(), vec.end(), queue) == vec.end()
56     );
57 }
58 
BOOST_AUTO_TEST_CASE(adjacent_find_fill)59 BOOST_AUTO_TEST_CASE(adjacent_find_fill)
60 {
61     compute::vector<int> vec(2048, context);
62     compute::fill(vec.begin(), vec.end(), 7, queue);
63     BOOST_VERIFY(
64         compute::adjacent_find(vec.begin(), vec.end(), queue) == vec.begin()
65     );
66 }
67 
68 BOOST_AUTO_TEST_SUITE_END()
69