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 TestTransformIf
12 #include <boost/test/unit_test.hpp>
13
14 #include <boost/compute/lambda.hpp>
15 #include <boost/compute/algorithm/transform_if.hpp>
16 #include <boost/compute/container/vector.hpp>
17
18 #include "check_macros.hpp"
19 #include "context_setup.hpp"
20
21 namespace compute = boost::compute;
22
BOOST_AUTO_TEST_CASE(transform_if_odd)23 BOOST_AUTO_TEST_CASE(transform_if_odd)
24 {
25 using boost::compute::abs;
26 using boost::compute::lambda::_1;
27
28 int data[] = { -2, -3, -4, -5, -6, -7, -8, -9 };
29 compute::vector<int> input(data, data + 8, queue);
30 compute::vector<int> output(input.size(), context);
31
32 compute::vector<int>::iterator end = compute::transform_if(
33 input.begin(), input.end(), output.begin(), abs<int>(), _1 % 2 != 0, queue
34 );
35 BOOST_CHECK_EQUAL(std::distance(output.begin(), end), 4);
36
37 CHECK_RANGE_EQUAL(int, 4, output, (+3, +5, +7, +9));
38 }
39
40 BOOST_AUTO_TEST_SUITE_END()
41