test_inplace_merge.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 TestInplaceMerge
  11. #include <boost/test/unit_test.hpp>
  12. #include <boost/compute/system.hpp>
  13. #include <boost/compute/algorithm/inplace_merge.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(simple_merge_int)
  19. {
  20. int data[] = { 1, 3, 5, 7, 2, 4, 6, 8 };
  21. compute::vector<int> vector(data, data + 8, queue);
  22. // merge each half in-place
  23. compute::inplace_merge(
  24. vector.begin(),
  25. vector.begin() + 4,
  26. vector.end(),
  27. queue
  28. );
  29. CHECK_RANGE_EQUAL(int, 8, vector, (1, 2, 3, 4, 5, 6, 7, 8));
  30. // run again on already sorted list
  31. compute::inplace_merge(
  32. vector.begin(),
  33. vector.begin() + 4,
  34. vector.end(),
  35. queue
  36. );
  37. CHECK_RANGE_EQUAL(int, 8, vector, (1, 2, 3, 4, 5, 6, 7, 8));
  38. }
  39. BOOST_AUTO_TEST_SUITE_END()