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
12 // This test was added due to a report that the Range Adaptors:
13 // 1. Caused havoc when using namespace boost::adaptors was used
14 // 2. Did not work with non-member functions
15 // 3. The strided adaptor could not be composed with sliced
16 //
17 // None of these issues could be reproduced on GCC 4.4, but this
18 // work makes for useful additional test coverage since this
19 // uses chaining of adaptors and non-member functions whereas
20 // most of the tests avoid this use case.
21
22 #include <boost/range/adaptor/strided.hpp>
23 #include <boost/range/adaptor/sliced.hpp>
24 #include <boost/range/adaptor/transformed.hpp>
25 #include <boost/range/irange.hpp>
26
27 #include <boost/test/test_tools.hpp>
28 #include <boost/test/unit_test.hpp>
29
30 #include <boost/assign.hpp>
31 #include <boost/range/algorithm_ext.hpp>
32
33 #include <algorithm>
34 #include <vector>
35
36 namespace boost
37 {
38 namespace
39 {
times_two(int x)40 int times_two(int x) { return x * 2; }
41
strided_test2()42 void strided_test2()
43 {
44 using namespace boost::adaptors;
45 using namespace boost::assign;
46 std::vector<int> v;
47 boost::push_back(v, boost::irange(0,10));
48 std::vector<int> z;
49 boost::push_back(z, v | sliced(2,6) | strided(2) | transformed(×_two));
50 std::vector<int> reference;
51 reference += 4,8;
52 BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
53 z.begin(), z.end() );
54 }
55 }
56 }
57
58 boost::unit_test::test_suite*
init_unit_test_suite(int argc,char * argv[])59 init_unit_test_suite(int argc, char* argv[])
60 {
61 boost::unit_test::test_suite* test
62 = BOOST_TEST_SUITE( "RangeTestSuite.adaptor.strided2" );
63
64 test->add( BOOST_TEST_CASE( &boost::strided_test2 ) );
65
66 return test;
67 }
68