• 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 TestEqualRange
12 #include <boost/test/unit_test.hpp>
13 
14 #include <utility>
15 #include <iterator>
16 
17 #include <boost/compute/command_queue.hpp>
18 #include <boost/compute/algorithm/equal_range.hpp>
19 #include <boost/compute/container/vector.hpp>
20 
21 #include "context_setup.hpp"
22 
BOOST_AUTO_TEST_CASE(equal_range_int)23 BOOST_AUTO_TEST_CASE(equal_range_int)
24 {
25     int data[] = { 1, 2, 2, 2, 3, 3, 4, 5 };
26     boost::compute::vector<int> vector(data, data + 8, queue);
27 
28     typedef boost::compute::vector<int>::iterator iterator;
29 
30     std::pair<iterator, iterator> range0 =
31         boost::compute::equal_range(vector.begin(), vector.end(), int(0), queue);
32     BOOST_CHECK(range0.first == vector.begin());
33     BOOST_CHECK(range0.second == vector.begin());
34     BOOST_CHECK_EQUAL(std::distance(range0.first, range0.second), ptrdiff_t(0));
35 
36     std::pair<iterator, iterator> range1 =
37         boost::compute::equal_range(vector.begin(), vector.end(), int(1), queue);
38     BOOST_CHECK(range1.first == vector.begin());
39     BOOST_CHECK(range1.second == vector.begin() + 1);
40     BOOST_CHECK_EQUAL(std::distance(range1.first, range1.second), ptrdiff_t(1));
41 
42     std::pair<iterator, iterator> range2 =
43         boost::compute::equal_range(vector.begin(), vector.end(), int(2), queue);
44     BOOST_CHECK(range2.first == vector.begin() + 1);
45     BOOST_CHECK(range2.second == vector.begin() + 4);
46     BOOST_CHECK_EQUAL(std::distance(range2.first, range2.second), ptrdiff_t(3));
47 
48     std::pair<iterator, iterator> range3 =
49         boost::compute::equal_range(vector.begin(), vector.end(), int(3), queue);
50     BOOST_CHECK(range3.first == vector.begin() + 4);
51     BOOST_CHECK(range3.second == vector.begin() + 6);
52     BOOST_CHECK_EQUAL(std::distance(range3.first, range3.second), ptrdiff_t(2));
53 
54     std::pair<iterator, iterator> range4 =
55         boost::compute::equal_range(vector.begin(), vector.end(), int(4), queue);
56     BOOST_CHECK(range4.first == vector.begin() + 6);
57     BOOST_CHECK(range4.second == vector.begin() + 7);
58     BOOST_CHECK_EQUAL(std::distance(range4.first, range4.second), ptrdiff_t(1));
59 
60     std::pair<iterator, iterator> range5 =
61         boost::compute::equal_range(vector.begin(), vector.end(), int(5), queue);
62     BOOST_CHECK(range5.first == vector.begin() + 7);
63     BOOST_CHECK(range5.second == vector.end());
64     BOOST_CHECK_EQUAL(std::distance(range5.first, range5.second), ptrdiff_t(1));
65 
66     std::pair<iterator, iterator> range6 =
67         boost::compute::equal_range(vector.begin(), vector.end(), int(6), queue);
68     BOOST_CHECK(range6.first == vector.end());
69     BOOST_CHECK(range6.second == vector.end());
70     BOOST_CHECK_EQUAL(std::distance(range6.first, range6.second), ptrdiff_t(0));
71 }
72 
73 BOOST_AUTO_TEST_SUITE_END()
74