is_partitioned_until_test.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. Copyright (c) Marshall Clow 2011-2012, Alexander Zaitsev <zamazan4ik@gmail.com>, 2017.
  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 <iostream>
  8. #include <boost/config.hpp>
  9. #include <boost/algorithm/is_partitioned_until.hpp>
  10. #define BOOST_TEST_MAIN
  11. #include <boost/test/unit_test.hpp>
  12. #include <string>
  13. #include <vector>
  14. #include <list>
  15. namespace ba = boost::algorithm;
  16. // namespace ba = boost;
  17. template <typename T>
  18. struct less_than {
  19. public:
  20. less_than ( T foo ) : val ( foo ) {}
  21. less_than ( const less_than &rhs ) : val ( rhs.val ) {}
  22. bool operator () ( const T &v ) const { return v < val; }
  23. private:
  24. less_than ();
  25. less_than operator = ( const less_than &rhs );
  26. T val;
  27. };
  28. void test_sequence1 () {
  29. std::vector<int> v;
  30. v.clear ();
  31. for ( int i = 5; i < 15; ++i )
  32. v.push_back ( i );
  33. BOOST_CHECK ( ba::is_partitioned_until ( v, less_than<int>(3)) == v.end()); // no elements
  34. BOOST_CHECK ( ba::is_partitioned_until ( v, less_than<int>(6)) == v.end()); // only the first element
  35. BOOST_CHECK ( ba::is_partitioned_until ( v, less_than<int>(10)) == v.end()); // in the middle somewhere
  36. BOOST_CHECK ( ba::is_partitioned_until ( v, less_than<int>(99)) == v.end()); // all elements satisfy
  37. // With bidirectional iterators.
  38. std::list<int> l;
  39. for ( int i = 5; i < 15; ++i )
  40. l.push_back ( i );
  41. BOOST_CHECK ( ba::is_partitioned_until ( l.begin (), l.end (), less_than<int>(3)) == l.end()); // no elements
  42. BOOST_CHECK ( ba::is_partitioned_until ( l.begin (), l.end (), less_than<int>(6)) == l.end()); // only the first element
  43. BOOST_CHECK ( ba::is_partitioned_until ( l.begin (), l.end (), less_than<int>(10)) == l.end()); // in the middle somewhere
  44. BOOST_CHECK ( ba::is_partitioned_until ( l.begin (), l.end (), less_than<int>(99)) == l.end()); // all elements satisfy
  45. }
  46. BOOST_AUTO_TEST_CASE( test_main )
  47. {
  48. test_sequence1 ();
  49. }