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/iota.hpp>
12
13 #include <boost/test/test_tools.hpp>
14 #include <boost/test/unit_test.hpp>
15
16 #include <boost/range/iterator.hpp>
17 #include <algorithm>
18 #include <list>
19 #include <vector>
20
21 namespace
22 {
23 template< class Container >
test_iota_impl(std::size_t n)24 void test_iota_impl(std::size_t n)
25 {
26 Container test;
27 test.resize( n );
28 boost::iota( test, n );
29
30 Container reference;
31 reference.resize( n );
32 std::size_t i = n;
33 typedef BOOST_DEDUCED_TYPENAME Container::iterator iterator_t;
34 iterator_t last = reference.end();
35 for (iterator_t it = reference.begin(); it != last; ++it, ++i)
36 {
37 *it = i;
38 }
39
40 BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
41 test.begin(), test.end() );
42
43 }
44
45 template< class Container >
test_iota_impl()46 void test_iota_impl()
47 {
48 test_iota_impl< Container >(0);
49 test_iota_impl< Container >(1);
50 test_iota_impl< Container >(2);
51 test_iota_impl< Container >(100);
52 }
53
test_iota()54 void test_iota()
55 {
56 test_iota_impl< std::vector<std::size_t> >();
57 test_iota_impl< std::list<std::size_t> >();
58 }
59 }
60
61 boost::unit_test::test_suite*
init_unit_test_suite(int argc,char * argv[])62 init_unit_test_suite(int argc, char* argv[])
63 {
64 boost::unit_test::test_suite* test
65 = BOOST_TEST_SUITE( "RangeTestSuite.algorithm_ext.iota" );
66
67 test->add( BOOST_TEST_CASE( &test_iota ) );
68
69 return test;
70 }
71