reversed.cpp 2.1 KB

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