test_rotate_copy.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //---------------------------------------------------------------------------//
  2. // Copyright (c) 2014 Roshan <thisisroshansmail@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 TestRotateCopy
  11. #include <boost/test/unit_test.hpp>
  12. #include <boost/compute/command_queue.hpp>
  13. #include <boost/compute/algorithm/copy_n.hpp>
  14. #include <boost/compute/algorithm/rotate_copy.hpp>
  15. #include <boost/compute/container/vector.hpp>
  16. #include "check_macros.hpp"
  17. #include "context_setup.hpp"
  18. BOOST_AUTO_TEST_CASE(rotate_copy_trivial)
  19. {
  20. int data[] = {1, 4, 2, 6, 3, 2, 5, 3, 4, 6};
  21. boost::compute::vector<int> vector(10, context);
  22. boost::compute::vector<int> result(10, context);
  23. boost::compute::copy_n(data, 10, vector.begin(), queue);
  24. boost::compute::rotate_copy(vector.begin(), vector.begin(), vector.end(), result.begin(), queue);
  25. CHECK_RANGE_EQUAL(int, 10, result, (1, 4, 2, 6, 3, 2, 5, 3, 4, 6));
  26. boost::compute::rotate_copy(vector.begin(), vector.end(), vector.end(), result.begin(), queue);
  27. CHECK_RANGE_EQUAL(int, 10, result, (1, 4, 2, 6, 3, 2, 5, 3, 4, 6));
  28. }
  29. BOOST_AUTO_TEST_CASE(rotate_copy_1)
  30. {
  31. int data[] = {1, 4, 2, 6, 3, 2, 5, 3, 4, 6};
  32. boost::compute::vector<int> vector(10, context);
  33. boost::compute::vector<int> result(10, context);
  34. boost::compute::copy_n(data, 10, vector.begin(), queue);
  35. boost::compute::rotate_copy(vector.begin(), vector.begin()+1, vector.end(), result.begin(), queue);
  36. CHECK_RANGE_EQUAL(int, 10, result, (4, 2, 6, 3, 2, 5, 3, 4, 6, 1));
  37. }
  38. BOOST_AUTO_TEST_CASE(rotate_copy_4)
  39. {
  40. int data[] = {1, 4, 2, 6, 3, 2, 5, 3, 4, 6};
  41. boost::compute::vector<int> vector(10, context);
  42. boost::compute::vector<int> result(10, context);
  43. boost::compute::copy_n(data, 10, vector.begin(), queue);
  44. boost::compute::rotate_copy(vector.begin(), vector.begin()+4, vector.end(), result.begin(), queue);
  45. CHECK_RANGE_EQUAL(int, 10, result, (3, 2, 5, 3, 4, 6, 1, 4, 2, 6));
  46. }
  47. BOOST_AUTO_TEST_CASE(rotate_copy_9)
  48. {
  49. int data[] = {1, 4, 2, 6, 3, 2, 5, 3, 4, 6};
  50. boost::compute::vector<int> vector(10, context);
  51. boost::compute::vector<int> result(10, context);
  52. boost::compute::copy_n(data, 10, vector.begin(), queue);
  53. boost::compute::rotate_copy(vector.begin(), vector.begin()+9, vector.end(), result.begin(), queue);
  54. CHECK_RANGE_EQUAL(int, 10, result, (6, 1, 4, 2, 6, 3, 2, 5, 3, 4));
  55. }
  56. BOOST_AUTO_TEST_SUITE_END()