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 TestCountingIterator
12 #include <boost/test/unit_test.hpp>
13
14 #include <iterator>
15
16 #include <boost/type_traits.hpp>
17 #include <boost/static_assert.hpp>
18
19 #include <boost/compute/algorithm/copy.hpp>
20 #include <boost/compute/container/vector.hpp>
21 #include <boost/compute/iterator/counting_iterator.hpp>
22
23 #include "check_macros.hpp"
24 #include "context_setup.hpp"
25
BOOST_AUTO_TEST_CASE(value_type)26 BOOST_AUTO_TEST_CASE(value_type)
27 {
28 BOOST_STATIC_ASSERT((
29 boost::is_same<
30 boost::compute::counting_iterator<int>::value_type,
31 int
32 >::value
33 ));
34 BOOST_STATIC_ASSERT((
35 boost::is_same<
36 boost::compute::counting_iterator<float>::value_type,
37 float
38 >::value
39 ));
40 }
41
BOOST_AUTO_TEST_CASE(distance)42 BOOST_AUTO_TEST_CASE(distance)
43 {
44 BOOST_CHECK_EQUAL(
45 std::distance(
46 boost::compute::make_counting_iterator(0),
47 boost::compute::make_counting_iterator(10)
48 ),
49 std::ptrdiff_t(10)
50 );
51 BOOST_CHECK_EQUAL(
52 std::distance(
53 boost::compute::make_counting_iterator(5),
54 boost::compute::make_counting_iterator(10)
55 ),
56 std::ptrdiff_t(5)
57 );
58 BOOST_CHECK_EQUAL(
59 std::distance(
60 boost::compute::make_counting_iterator(-5),
61 boost::compute::make_counting_iterator(5)
62 ),
63 std::ptrdiff_t(10)
64 );
65 }
66
BOOST_AUTO_TEST_CASE(copy)67 BOOST_AUTO_TEST_CASE(copy)
68 {
69 boost::compute::vector<int> vector(10, context);
70
71 boost::compute::copy(
72 boost::compute::make_counting_iterator(1),
73 boost::compute::make_counting_iterator(11),
74 vector.begin(),
75 queue
76 );
77 CHECK_RANGE_EQUAL(
78 int, 10, vector,
79 (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
80 );
81 }
82
BOOST_AUTO_TEST_CASE(iota_with_copy_doctest)83 BOOST_AUTO_TEST_CASE(iota_with_copy_doctest)
84 {
85 //! [iota_with_copy]
86 using boost::compute::make_counting_iterator;
87
88 boost::compute::vector<int> result(5, context);
89
90 boost::compute::copy(
91 make_counting_iterator(1), make_counting_iterator(6), result.begin(), queue
92 );
93
94 // result == { 1, 2, 3, 4, 5 }
95 //! [iota_with_copy]
96
97 CHECK_RANGE_EQUAL(int, 5, result, (1, 2, 3, 4, 5));
98 }
99
100 BOOST_AUTO_TEST_SUITE_END()
101