test_search.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 TestSearch
  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/search.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(search_int)
  21. {
  22. int data[] = {1, 4, 2, 6, 3, 2, 6, 3, 4, 6, 6};
  23. bc::vector<bc::int_> vectort(data, data + 11, queue);
  24. int datap[] = {2, 6};
  25. bc::vector<bc::int_> vectorp(datap, datap + 2, queue);
  26. bc::vector<bc::int_>::iterator iter =
  27. bc::search(vectort.begin(), vectort.end(),
  28. vectorp.begin(), vectorp.end(), queue);
  29. BOOST_CHECK(iter == vectort.begin() + 2);
  30. vectorp[1] = 9;
  31. iter =
  32. bc::search(vectort.begin(), vectort.end(),
  33. vectorp.begin(), vectorp.end(), queue);
  34. BOOST_CHECK(iter == vectort.begin() + 11);
  35. vectorp[0] = 6;
  36. vectorp[1] = 6;
  37. iter =
  38. bc::search(vectort.begin(), vectort.end(),
  39. vectorp.begin(), vectorp.end(), queue);
  40. BOOST_CHECK(iter == vectort.begin() + 9);
  41. }
  42. BOOST_AUTO_TEST_CASE(search_string)
  43. {
  44. char text[] = "sdabababacabskjabacab";
  45. bc::vector<bc::char_> vectort(text, text + 21, queue);
  46. char pattern[] = "aba";
  47. bc::vector<bc::char_> vectorp(pattern, pattern + 3, queue);
  48. bc::vector<bc::char_>::iterator iter =
  49. bc::search(vectort.begin(), vectort.end(),
  50. vectorp.begin(), vectorp.end(), queue);
  51. BOOST_CHECK(iter == vectort.begin() + 2);
  52. }
  53. BOOST_AUTO_TEST_SUITE_END()