| 1 | //---------------------------------------------------------------------------// |
| 2 | // Copyright (c) 2013-2014 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 TestDiscardIterator |
| 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/algorithm/copy_if.hpp> |
| 21 | #include <boost/compute/algorithm/fill.hpp> |
| 22 | #include <boost/compute/lambda.hpp> |
| 23 | #include <boost/compute/container/vector.hpp> |
| 24 | #include <boost/compute/iterator/discard_iterator.hpp> |
| 25 | |
| 26 | #include "check_macros.hpp" |
| 27 | #include "context_setup.hpp" |
| 28 | |
| 29 | BOOST_AUTO_TEST_CASE(value_type) |
| 30 | { |
| 31 | BOOST_STATIC_ASSERT(( |
| 32 | boost::is_same< |
| 33 | boost::compute::discard_iterator::value_type, void |
| 34 | >::value |
| 35 | )); |
| 36 | } |
| 37 | |
| 38 | BOOST_AUTO_TEST_CASE(distance) |
| 39 | { |
| 40 | BOOST_CHECK_EQUAL( |
| 41 | std::distance( |
| 42 | boost::compute::make_discard_iterator(0), |
| 43 | boost::compute::make_discard_iterator(10) |
| 44 | ), |
| 45 | std::ptrdiff_t(10) |
| 46 | ); |
| 47 | BOOST_CHECK_EQUAL( |
| 48 | std::distance( |
| 49 | boost::compute::make_discard_iterator(5), |
| 50 | boost::compute::make_discard_iterator(10) |
| 51 | ), |
| 52 | std::ptrdiff_t(5) |
| 53 | ); |
| 54 | } |
| 55 | |
| 56 | BOOST_AUTO_TEST_CASE(discard_copy) |
| 57 | { |
| 58 | boost::compute::vector<int> vector(10, context); |
| 59 | boost::compute::fill(vector.begin(), vector.end(), 42, queue); |
| 60 | |
| 61 | boost::compute::copy( |
| 62 | vector.begin(), vector.end(), |
| 63 | boost::compute::make_discard_iterator(), |
| 64 | queue |
| 65 | ); |
| 66 | } |
| 67 | |
| 68 | BOOST_AUTO_TEST_CASE(discard_copy_if) |
| 69 | { |
| 70 | int data[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; |
| 71 | boost::compute::vector<int> vector(data, data + 8, queue); |
| 72 | |
| 73 | using boost::compute::lambda::_1; |
| 74 | |
| 75 | boost::compute::discard_iterator end = boost::compute::copy_if( |
| 76 | first: vector.begin(), last: vector.end(), |
| 77 | result: boost::compute::make_discard_iterator(), |
| 78 | predicate: _1 > 4, |
| 79 | queue |
| 80 | ); |
| 81 | BOOST_CHECK(std::distance(boost::compute::discard_iterator(), end) == 4); |
| 82 | } |
| 83 | |
| 84 | BOOST_AUTO_TEST_CASE(discard_fill) |
| 85 | { |
| 86 | boost::compute::fill( |
| 87 | first: boost::compute::make_discard_iterator(index: 0), |
| 88 | last: boost::compute::make_discard_iterator(index: 100), |
| 89 | value: 42, |
| 90 | queue |
| 91 | ); |
| 92 | } |
| 93 | |
| 94 | BOOST_AUTO_TEST_SUITE_END() |
| 95 | |