empty_search_test.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. Copyright (c) Marshall Clow 2010-2012.
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. For more information, see http://www.boost.org
  6. */
  7. #include <string>
  8. #include <boost/algorithm/searching/boyer_moore.hpp>
  9. #include <boost/algorithm/searching/boyer_moore_horspool.hpp>
  10. #include <boost/algorithm/searching/knuth_morris_pratt.hpp>
  11. #define BOOST_TEST_MAIN
  12. #include <boost/test/unit_test.hpp>
  13. BOOST_AUTO_TEST_CASE( test_main )
  14. {
  15. const std::string cs;
  16. std::string estr;
  17. std::string str ( "abc" );
  18. // empty corpus, empty pattern
  19. BOOST_CHECK (
  20. boost::algorithm::boyer_moore_search (
  21. cs.begin (), cs.end (), estr.begin (), estr.end ())
  22. == std::make_pair(cs.begin(), cs.begin())
  23. );
  24. BOOST_CHECK (
  25. boost::algorithm::boyer_moore_horspool_search (
  26. cs.begin (), cs.end (), estr.begin (), estr.end ())
  27. == std::make_pair(cs.begin(), cs.begin())
  28. );
  29. BOOST_CHECK (
  30. boost::algorithm::knuth_morris_pratt_search (
  31. cs.begin (), cs.end (), estr.begin (), estr.end ())
  32. == std::make_pair(cs.begin(), cs.begin())
  33. );
  34. // empty corpus, non-empty pattern
  35. BOOST_CHECK (
  36. boost::algorithm::boyer_moore_search (
  37. estr.begin (), estr.end (), str.begin (), str.end ())
  38. == std::make_pair(estr.end(), estr.end())
  39. );
  40. BOOST_CHECK (
  41. boost::algorithm::boyer_moore_horspool_search (
  42. estr.begin (), estr.end (), str.begin (), str.end ())
  43. == std::make_pair(estr.end(), estr.end())
  44. );
  45. BOOST_CHECK (
  46. boost::algorithm::knuth_morris_pratt_search (
  47. estr.begin (), estr.end (), str.begin (), str.end ())
  48. == std::make_pair(estr.end(), estr.end())
  49. );
  50. // non-empty corpus, empty pattern
  51. BOOST_CHECK (
  52. boost::algorithm::boyer_moore_search (
  53. str.begin (), str.end (), estr.begin (), estr.end ())
  54. == std::make_pair(str.begin(), str.begin())
  55. );
  56. BOOST_CHECK (
  57. boost::algorithm::boyer_moore_horspool_search (
  58. str.begin (), str.end (), estr.begin (), estr.end ())
  59. == std::make_pair(str.begin(), str.begin())
  60. );
  61. BOOST_CHECK (
  62. boost::algorithm::knuth_morris_pratt_search (
  63. str.begin (), str.end (), estr.begin (), estr.end ())
  64. == std::make_pair(str.begin(), str.begin())
  65. );
  66. }