reverse.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Copyright Neil Groves 2009. Use, modification and
  2. // distribution is subject to the Boost Software License, Version
  3. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. //
  6. //
  7. // For more information, see http://www.boost.org/libs/range/
  8. //
  9. #include <boost/range/algorithm/reverse.hpp>
  10. #include <boost/test/test_tools.hpp>
  11. #include <boost/test/unit_test.hpp>
  12. #include <boost/assign.hpp>
  13. #include <boost/bind.hpp>
  14. #include <algorithm>
  15. #include <functional>
  16. #include <list>
  17. #include <numeric>
  18. #include <deque>
  19. #include <vector>
  20. namespace boost
  21. {
  22. namespace
  23. {
  24. template<class Container>
  25. void test_reverse_impl(Container& cont)
  26. {
  27. Container reference(cont);
  28. Container test(cont);
  29. Container test2(cont);
  30. boost::reverse(test);
  31. std::reverse(reference.begin(), reference.end());
  32. BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
  33. test.begin(), test.end() );
  34. boost::reverse(boost::make_iterator_range(test2));
  35. BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
  36. test2.begin(), test2.end() );
  37. }
  38. template<class Container>
  39. void test_reverse_impl()
  40. {
  41. using namespace boost::assign;
  42. Container cont;
  43. test_reverse_impl(cont);
  44. cont.clear();
  45. cont += 1;
  46. test_reverse_impl(cont);
  47. cont.clear();
  48. cont += 1,2,3,4,5,6,7,8,9;
  49. test_reverse_impl(cont);
  50. }
  51. void test_reverse()
  52. {
  53. test_reverse_impl< std::vector<int> >();
  54. test_reverse_impl< std::list<int> >();
  55. test_reverse_impl< std::deque<int> >();
  56. }
  57. }
  58. }
  59. boost::unit_test::test_suite*
  60. init_unit_test_suite(int argc, char* argv[])
  61. {
  62. boost::unit_test::test_suite* test
  63. = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.reverse" );
  64. test->add( BOOST_TEST_CASE( &boost::test_reverse ) );
  65. return test;
  66. }