• 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 TestConstantIterator
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/constant_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::constant_iterator<int>::value_type,
31             int
32         >::value
33     ));
34     BOOST_STATIC_ASSERT((
35         boost::is_same<
36             boost::compute::constant_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_constant_iterator(128, 0),
47             boost::compute::make_constant_iterator(128, 10)
48         ),
49         std::ptrdiff_t(10)
50     );
51     BOOST_CHECK_EQUAL(
52         std::distance(
53             boost::compute::make_constant_iterator(256, 5),
54             boost::compute::make_constant_iterator(256, 10)
55         ),
56         std::ptrdiff_t(5)
57     );
58 }
59 
BOOST_AUTO_TEST_CASE(copy)60 BOOST_AUTO_TEST_CASE(copy)
61 {
62     boost::compute::vector<int> vector(10, context);
63 
64     boost::compute::copy(
65         boost::compute::make_constant_iterator(42, 0),
66         boost::compute::make_constant_iterator(42, 10),
67         vector.begin(),
68         queue
69     );
70     CHECK_RANGE_EQUAL(
71         int, 10, vector,
72         (42, 42, 42, 42, 42, 42, 42, 42, 42, 42)
73     );
74 }
75 
BOOST_AUTO_TEST_CASE(fill_with_copy_doctest)76 BOOST_AUTO_TEST_CASE(fill_with_copy_doctest)
77 {
78 //! [fill_with_copy]
79 using boost::compute::make_constant_iterator;
80 
81 boost::compute::vector<int> result(5, context);
82 
83 boost::compute::copy(
84     make_constant_iterator(42, 0),
85     make_constant_iterator(42, result.size()),
86     result.begin(),
87     queue
88 );
89 
90 // result == { 42, 42, 42, 42, 42 }
91 //! [fill_with_copy]
92 
93     CHECK_RANGE_EQUAL(int, 5, result, (42, 42, 42, 42, 42));
94 }
95 
96 BOOST_AUTO_TEST_SUITE_END()
97