test_transform_if.cpp 1.3 KB

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