test_rotate.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 TestRotate
  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.hpp>
  15. #include <boost/compute/container/vector.hpp>
  16. #include "check_macros.hpp"
  17. #include "context_setup.hpp"
  18. BOOST_AUTO_TEST_CASE(rotate_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::copy_n(data, 10, vector.begin(), queue);
  23. boost::compute::rotate(vector.begin(), vector.begin(), vector.end(), queue);
  24. CHECK_RANGE_EQUAL(int, 10, vector, (1, 4, 2, 6, 3, 2, 5, 3, 4, 6));
  25. boost::compute::rotate(vector.begin(), vector.end(), vector.end(), queue);
  26. CHECK_RANGE_EQUAL(int, 10, vector, (1, 4, 2, 6, 3, 2, 5, 3, 4, 6));
  27. }
  28. BOOST_AUTO_TEST_CASE(rotate_1)
  29. {
  30. int data[] = {1, 4, 2, 6, 3, 2, 5, 3, 4, 6};
  31. boost::compute::vector<int> vector(10, context);
  32. boost::compute::copy_n(data, 10, vector.begin(), queue);
  33. boost::compute::rotate(vector.begin(), vector.begin()+1, vector.end(), queue);
  34. CHECK_RANGE_EQUAL(int, 10, vector, (4, 2, 6, 3, 2, 5, 3, 4, 6, 1));
  35. }
  36. BOOST_AUTO_TEST_CASE(rotate_4)
  37. {
  38. int data[] = {1, 4, 2, 6, 3, 2, 5, 3, 4, 6};
  39. boost::compute::vector<int> vector(10, context);
  40. boost::compute::copy_n(data, 10, vector.begin(), queue);
  41. boost::compute::rotate(vector.begin(), vector.begin()+4, vector.end(), queue);
  42. CHECK_RANGE_EQUAL(int, 10, vector, (3, 2, 5, 3, 4, 6, 1, 4, 2, 6));
  43. }
  44. BOOST_AUTO_TEST_CASE(rotate_9)
  45. {
  46. int data[] = {1, 4, 2, 6, 3, 2, 5, 3, 4, 6};
  47. boost::compute::vector<int> vector(10, context);
  48. boost::compute::copy_n(data, 10, vector.begin(), queue);
  49. boost::compute::rotate(vector.begin(), vector.begin()+9, vector.end(), queue);
  50. CHECK_RANGE_EQUAL(int, 10, vector, (6, 1, 4, 2, 6, 3, 2, 5, 3, 4));
  51. }
  52. BOOST_AUTO_TEST_SUITE_END()