• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/copied.hpp>
12 
13 #include <boost/test/test_tools.hpp>
14 #include <boost/test/unit_test.hpp>
15 
16 #include <boost/assign.hpp>
17 
18 #include <algorithm>
19 #include <deque>
20 #include <string>
21 #include <vector>
22 #include <boost/range/algorithm_ext.hpp>
23 
24 namespace boost
25 {
26     namespace
27     {
28         template< class Container >
copied_test_impl(Container & c)29         void copied_test_impl( Container& c )
30         {
31             using namespace boost::adaptors;
32 
33             // This is my preferred syntax using the | operator.
34             std::vector< int > test_result1;
35             boost::push_back(test_result1, c | copied(0u, c.size()));
36 
37             // This is the alternative syntax preferred by some.
38             std::vector< int > test_result2;
39             boost::push_back(test_result2, adaptors::copy(c, 0u, c.size()));
40 
41             BOOST_CHECK_EQUAL_COLLECTIONS( test_result1.begin(), test_result1.end(),
42                                            c.begin(), c.end() );
43 
44             BOOST_CHECK_EQUAL_COLLECTIONS( test_result2.begin(), test_result2.end(),
45                                            c.begin(), c.end() );
46         }
47 
48         template< class Container >
copied_test_impl()49         void copied_test_impl()
50         {
51             using namespace boost::assign;
52 
53             Container c;
54 
55             // test empty collection
56             copied_test_impl(c);
57 
58             // test one element
59             c += 1;
60             copied_test_impl(c);
61 
62             // test many elements
63             c += 1,2,2,2,3,4,4,4,4,5,6,7,8,9,9;
64             copied_test_impl(c);
65         }
66 
copied_test()67         void copied_test()
68         {
69             copied_test_impl< std::vector< int > >();
70             copied_test_impl< std::deque< int > >();
71         }
72     }
73 }
74 
75 boost::unit_test::test_suite*
init_unit_test_suite(int argc,char * argv[])76 init_unit_test_suite(int argc, char* argv[])
77 {
78     boost::unit_test::test_suite* test
79         = BOOST_TEST_SUITE( "RangeTestSuite.adaptor.copied" );
80 
81     test->add( BOOST_TEST_CASE( &boost::copied_test ) );
82 
83     return test;
84 }
85