test_replace.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 TestReplace
  11. #include <boost/test/unit_test.hpp>
  12. #include <boost/compute/system.hpp>
  13. #include <boost/compute/command_queue.hpp>
  14. #include <boost/compute/algorithm/copy.hpp>
  15. #include <boost/compute/algorithm/iota.hpp>
  16. #include <boost/compute/algorithm/replace.hpp>
  17. #include <boost/compute/algorithm/replace_copy.hpp>
  18. #include <boost/compute/container/vector.hpp>
  19. #include "check_macros.hpp"
  20. #include "context_setup.hpp"
  21. namespace bc = boost::compute;
  22. BOOST_AUTO_TEST_CASE(replace_int)
  23. {
  24. bc::vector<int> vector(5, context);
  25. bc::iota(vector.begin(), vector.end(), 0, queue);
  26. CHECK_RANGE_EQUAL(int, 5, vector, (0, 1, 2, 3, 4));
  27. bc::replace(vector.begin(), vector.end(), 2, 6, queue);
  28. CHECK_RANGE_EQUAL(int, 5, vector, (0, 1, 6, 3, 4));
  29. }
  30. BOOST_AUTO_TEST_CASE(replace_copy_int)
  31. {
  32. bc::vector<int> a(5, context);
  33. bc::iota(a.begin(), a.end(), 0, queue);
  34. CHECK_RANGE_EQUAL(int, 5, a, (0, 1, 2, 3, 4));
  35. bc::vector<int> b(5, context);
  36. bc::vector<int>::iterator iter =
  37. bc::replace_copy(a.begin(), a.end(), b.begin(), 3, 9, queue);
  38. BOOST_CHECK(iter == b.end());
  39. CHECK_RANGE_EQUAL(int, 5, b, (0, 1, 2, 9, 4));
  40. // ensure 'a' was not modified
  41. CHECK_RANGE_EQUAL(int, 5, a, (0, 1, 2, 3, 4));
  42. }
  43. BOOST_AUTO_TEST_SUITE_END()