fill.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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/algorithm/fill.hpp>
  12. #include <boost/test/test_tools.hpp>
  13. #include <boost/test/unit_test.hpp>
  14. #include <boost/assign.hpp>
  15. #include <algorithm>
  16. #include <functional>
  17. #include <list>
  18. #include <numeric>
  19. #include <deque>
  20. #include <vector>
  21. namespace boost
  22. {
  23. namespace
  24. {
  25. template< class Container >
  26. void test_fill_impl(Container& cont)
  27. {
  28. Container reference(cont);
  29. std::fill(reference.begin(), reference.end(), 1);
  30. Container target(cont);
  31. boost::fill(target, 1);
  32. BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
  33. target.begin(), target.end() );
  34. Container target2(cont);
  35. boost::fill(boost::make_iterator_range(target2), 1);
  36. BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
  37. target2.begin(), target2.end() );
  38. }
  39. template< class Container >
  40. void test_fill_impl()
  41. {
  42. using namespace boost::assign;
  43. Container cont;
  44. test_fill_impl(cont);
  45. cont.clear();
  46. cont += 2;
  47. test_fill_impl(cont);
  48. cont.clear();
  49. cont += 1,2;
  50. test_fill_impl(cont);
  51. cont.clear();
  52. cont += 1,2,3,4,5,6,7,8,9;
  53. test_fill_impl(cont);
  54. }
  55. void test_fill()
  56. {
  57. test_fill_impl< std::vector<int> >();
  58. test_fill_impl< std::list<int> >();
  59. test_fill_impl< std::deque<int> >();
  60. }
  61. }
  62. }
  63. boost::unit_test::test_suite*
  64. init_unit_test_suite(int argc, char* argv[])
  65. {
  66. boost::unit_test::test_suite* test
  67. = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.fill" );
  68. test->add( BOOST_TEST_CASE( &boost::test_fill ) );
  69. return test;
  70. }