test_functional_convert.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 TestFunctionalConvert
  11. #include <boost/test/unit_test.hpp>
  12. #include <boost/compute/system.hpp>
  13. #include <boost/compute/algorithm/copy_n.hpp>
  14. #include <boost/compute/algorithm/transform.hpp>
  15. #include <boost/compute/container/vector.hpp>
  16. #include <boost/compute/functional/convert.hpp>
  17. #include "check_macros.hpp"
  18. #include "context_setup.hpp"
  19. namespace compute = boost::compute;
  20. BOOST_AUTO_TEST_CASE(convert_int_float)
  21. {
  22. int data[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
  23. compute::vector<int> input(8, context);
  24. compute::copy_n(data, 8, input.begin(), queue);
  25. compute::vector<float> output(8, context);
  26. compute::transform(
  27. input.begin(),
  28. input.end(),
  29. output.begin(),
  30. compute::convert<float>(),
  31. queue
  32. );
  33. CHECK_RANGE_EQUAL(
  34. float, 8, output, (1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f)
  35. );
  36. }
  37. BOOST_AUTO_TEST_SUITE_END()