test_adjacent_find.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 TestAdjacentFind
  11. #include <boost/test/unit_test.hpp>
  12. #include <boost/compute/command_queue.hpp>
  13. #include <boost/compute/algorithm/adjacent_find.hpp>
  14. #include <boost/compute/algorithm/fill.hpp>
  15. #include <boost/compute/algorithm/iota.hpp>
  16. #include <boost/compute/container/vector.hpp>
  17. #include "context_setup.hpp"
  18. namespace compute = boost::compute;
  19. BOOST_AUTO_TEST_CASE(adjacent_find_int)
  20. {
  21. int data[] = { 1, 3, 5, 5, 6, 7, 7, 8 };
  22. compute::vector<int> vec(data, data + 8, queue);
  23. compute::vector<int>::iterator iter =
  24. compute::adjacent_find(vec.begin(), vec.end(), queue);
  25. BOOST_CHECK(iter == vec.begin() + 2);
  26. }
  27. BOOST_AUTO_TEST_CASE(adjacent_find_int2)
  28. {
  29. using compute::int2_;
  30. compute::vector<int2_> vec(context);
  31. vec.push_back(int2_(1, 2), queue);
  32. vec.push_back(int2_(3, 4), queue);
  33. vec.push_back(int2_(5, 6), queue);
  34. vec.push_back(int2_(7, 8), queue);
  35. vec.push_back(int2_(7, 8), queue);
  36. compute::vector<int2_>::iterator iter =
  37. compute::adjacent_find(vec.begin(), vec.end(), queue);
  38. BOOST_CHECK(iter == vec.begin() + 3);
  39. }
  40. BOOST_AUTO_TEST_CASE(adjacent_find_iota)
  41. {
  42. compute::vector<int> vec(2048, context);
  43. compute::iota(vec.begin(), vec.end(), 1, queue);
  44. BOOST_VERIFY(
  45. compute::adjacent_find(vec.begin(), vec.end(), queue) == vec.end()
  46. );
  47. }
  48. BOOST_AUTO_TEST_CASE(adjacent_find_fill)
  49. {
  50. compute::vector<int> vec(2048, context);
  51. compute::fill(vec.begin(), vec.end(), 7, queue);
  52. BOOST_VERIFY(
  53. compute::adjacent_find(vec.begin(), vec.end(), queue) == vec.begin()
  54. );
  55. }
  56. BOOST_AUTO_TEST_SUITE_END()