]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/range/test/counting_range.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / range / test / counting_range.cpp
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 // Disable a warning from <xutility> since this noise might
12 // stop us detecting a problem in our code.
13 #include <boost/range/counting_range.hpp>
14 #include <boost/range/adaptor/indirected.hpp>
15
16 #include <boost/test/test_tools.hpp>
17 #include <boost/test/unit_test.hpp>
18
19 #include <boost/assign.hpp>
20
21 #include <algorithm>
22 #include <deque>
23 #include <string>
24 #include <vector>
25 #include <boost/range/algorithm_ext.hpp>
26 namespace boost
27 {
28 namespace
29 {
30 template<class Container>
31 void counting_range_test_impl(int first, int last)
32 {
33 Container reference;
34 for (int i = first; i < last; ++i)
35 reference.push_back(i);
36
37 Container test;
38 push_back( test, counting_range(first, last) );
39
40 BOOST_CHECK_EQUAL_COLLECTIONS(
41 reference.begin(), reference.end(),
42 test.begin(), test.end());
43 }
44
45 template<class Container>
46 void counting_range_test_impl()
47 {
48 counting_range_test_impl<Container>(0, 0);
49 counting_range_test_impl<Container>(-1, -1);
50 counting_range_test_impl<Container>(-1, 0);
51 counting_range_test_impl<Container>(0, 1);
52 counting_range_test_impl<Container>(-100, 100);
53 counting_range_test_impl<Container>(50, 55);
54 }
55
56 void counting_range_test_range()
57 {
58 std::vector<int> v;
59 for (int i = 0; i < 10; ++i)
60 v.push_back(i);
61
62 std::vector<std::vector<int>::iterator> x;
63 push_back(x, counting_range(v));
64
65 std::vector<int> t;
66 push_back(t, x | boost::adaptors::indirected);
67
68 BOOST_CHECK_EQUAL_COLLECTIONS(t.begin(), t.end(),
69 v.begin(), v.end());
70 }
71 }
72
73 void counting_range_test()
74 {
75 counting_range_test_impl<std::vector<int> >();
76 counting_range_test_impl<std::list<int> >();
77 counting_range_test_impl<std::deque<int> >();
78 }
79 }
80
81 boost::unit_test::test_suite*
82 init_unit_test_suite(int argc, char* argv[])
83 {
84 boost::unit_test::test_suite* test
85 = BOOST_TEST_SUITE( "RangeTestSuite.adaptor.counting_range" );
86
87 test->add( BOOST_TEST_CASE( &boost::counting_range_test ) );
88
89 return test;
90 }