insert.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Boost.Range library
  2. //
  3. // Copyright Neil Groves 2010. 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/algorithm_ext/insert.hpp>
  12. #include <boost/test/test_tools.hpp>
  13. #include <boost/test/unit_test.hpp>
  14. #include <boost/range/iterator.hpp>
  15. #include <boost/range/irange.hpp>
  16. #include <algorithm>
  17. #include <list>
  18. #include <vector>
  19. namespace
  20. {
  21. template< class Container >
  22. void test_insert_impl( int n )
  23. {
  24. Container test;
  25. boost::insert( test, test.end(), boost::irange(0, n) );
  26. Container reference;
  27. for (int i = 0; i < n; ++i)
  28. reference.push_back(i);
  29. BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
  30. test.begin(), test.end() );
  31. // Do it again so that we are inserting into a non-empty target
  32. boost::insert( test, test.end(), boost::irange(0, n) );
  33. for (int j = 0; j < n; ++j)
  34. reference.push_back(j);
  35. BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
  36. test.begin(), test.end() );
  37. }
  38. template< class Container >
  39. void test_insert_impl()
  40. {
  41. test_insert_impl< Container >(0);
  42. test_insert_impl< Container >(1);
  43. test_insert_impl< Container >(2);
  44. test_insert_impl< Container >(100);
  45. }
  46. void test_insert()
  47. {
  48. test_insert_impl< std::vector<std::size_t> >();
  49. test_insert_impl< std::list<std::size_t> >();
  50. }
  51. }
  52. boost::unit_test::test_suite*
  53. init_unit_test_suite(int argc, char* argv[])
  54. {
  55. boost::unit_test::test_suite* test
  56. = BOOST_TEST_SUITE( "RangeTestSuite.algorithm_ext.insert" );
  57. test->add( BOOST_TEST_CASE( &test_insert ) );
  58. return test;
  59. }