test_search_n.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 TestSearchN
  11. #include <boost/test/unit_test.hpp>
  12. #include <boost/compute/command_queue.hpp>
  13. #include <boost/compute/algorithm/search_n.hpp>
  14. #include <boost/compute/container/vector.hpp>
  15. #include <boost/compute/types/fundamental.hpp>
  16. #include "check_macros.hpp"
  17. #include "context_setup.hpp"
  18. namespace bc = boost::compute;
  19. BOOST_AUTO_TEST_CASE(search_int)
  20. {
  21. int data[] = {1, 2, 2, 2, 3, 2, 2, 2, 4, 6, 6};
  22. bc::vector<bc::int_> vectort(data, data + 11, queue);
  23. bc::vector<bc::int_>::iterator iter =
  24. bc::search_n(vectort.begin(), vectort.end(), 3, 2, queue);
  25. BOOST_CHECK(iter == vectort.begin() + 1);
  26. iter =
  27. bc::search_n(vectort.begin(), vectort.end(), 5, 2, queue);
  28. BOOST_CHECK(iter == vectort.begin() + 11);
  29. iter =
  30. bc::search_n(vectort.begin(), vectort.end(), 2, 6, queue);
  31. BOOST_CHECK(iter == vectort.begin() + 9);
  32. }
  33. BOOST_AUTO_TEST_CASE(search_string)
  34. {
  35. char text[] = "asaaababaaca";
  36. bc::vector<bc::char_> vectort(text, text + 12, queue);
  37. bc::vector<bc::char_>::iterator iter =
  38. bc::search_n(vectort.begin(), vectort.end(), 2, 'a', queue);
  39. BOOST_CHECK(iter == vectort.begin() + 2);
  40. }
  41. BOOST_AUTO_TEST_SUITE_END()