test_find_end.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 TestFindEnd
  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/find_end.hpp>
  15. #include <boost/compute/container/vector.hpp>
  16. #include <boost/compute/types/fundamental.hpp>
  17. #include "check_macros.hpp"
  18. #include "context_setup.hpp"
  19. namespace bc = boost::compute;
  20. BOOST_AUTO_TEST_CASE(find_end_int)
  21. {
  22. bc::int_ data[] = {1, 4, 2, 6, 3, 2, 6, 3, 4, 6};
  23. bc::vector<bc::int_> vectort(data, data + 10, queue);
  24. bc::int_ datap[] = {2, 6};
  25. bc::vector<bc::int_> vectorp(datap, datap + 2, queue);
  26. bc::vector<bc::int_>::iterator iter =
  27. bc::find_end(vectort.begin(), vectort.end(),
  28. vectorp.begin(), vectorp.end(), queue);
  29. BOOST_CHECK(iter == vectort.begin() + 5);
  30. vectorp.insert(vectorp.begin() + 1, bc::int_(9), queue);
  31. iter =
  32. bc::find_end(vectort.begin(), vectort.end(),
  33. vectorp.begin(), vectorp.end(), queue);
  34. BOOST_CHECK(iter == vectort.end());
  35. }
  36. BOOST_AUTO_TEST_CASE(find_end_string)
  37. {
  38. bc::char_ text[] = "sdabababacabskjabacab";
  39. bc::vector<bc::char_> vectort(text, text + 21, queue);
  40. bc::char_ pattern[] = "aba";
  41. bc::vector<bc::char_> vectorp(pattern, pattern + 3, queue);
  42. bc::vector<bc::char_>::iterator iter =
  43. bc::find_end(vectort.begin(), vectort.end(),
  44. vectorp.begin(), vectorp.end(), queue);
  45. BOOST_CHECK(iter == (vectort.begin() + 15));
  46. }
  47. BOOST_AUTO_TEST_SUITE_END()