1// Boost.Range library
2//
3// Copyright Neil Groves 2014
4//
5// Copyright Thorsten Ottosen 2006. Use, modification and
6// distribution is subject to the Boost Software License, Version
7// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8// http://www.boost.org/LICENSE_1_0.txt)
9//
10// For more information, see http://www.boost.org/libs/range/
11//
12#include <boost/range/combine.hpp>
13
14#include <boost/range/algorithm_ext/push_back.hpp>
15
16#include <boost/test/test_tools.hpp>
17#include <boost/test/unit_test.hpp>
18#include <boost/foreach.hpp>
19#include <vector>
20
21namespace boost_range_test
22{
23 namespace
24 {
25
26template<typename ContRef1, typename ContRef2>
27void test_combine2()
28{
29 std::vector<int> v;
30 std::list<int> l;
31
32 for (int i = 0; i < 10; ++i)
33 {
34 v.push_back(i);
35 l.push_back(i * 2);
36 }
37
38 ContRef1& in1 = v;
39 ContRef2& in2 = l;
40
41 std::vector<boost::tuple<int,int> > output;
42 boost::push_back(output, boost::combine(in1, in2));
43
44 int index = 0;
45 int i1, i2;
46 BOOST_FOREACH(boost::tie(i1,i2), output)
47 {
48 BOOST_CHECK_EQUAL(i1, index);
49 BOOST_CHECK_EQUAL(i2, index * 2);
50 ++index;
51 }
52}
53
54template<typename ContRef1, typename ContRef2, typename ContRef3>
55void test_combine3()
56{
57 std::vector<int> v1;
58 std::vector<int> v2;
59 std::vector<int> v3;
60
61 for (int i = 0; i < 10; ++i)
62 {
63 v1.push_back(i);
64 v2.push_back(i * 2);
65 v3.push_back(i * 3);
66 }
67
68 ContRef1& in1 = v1;
69 ContRef2& in2 = v2;
70 ContRef3& in3 = v3;
71
72 std::vector<boost::tuple<int,int,int> > output;
73 boost::push_back(output, boost::combine(in1, in2, in3));
74
75 int index = 0;
76 int i1, i2, i3;
77
78 BOOST_FOREACH(boost::tie(i1,i2,i3), output)
79 {
80 BOOST_CHECK_EQUAL(i1, index);
81 BOOST_CHECK_EQUAL(i2, index * 2);
82 BOOST_CHECK_EQUAL(i3, index * 3);
83 ++index;
84 }
85}
86
87 } // anonymous namespace
88} // namespace boost_range_test
89
90boost::unit_test::test_suite* init_unit_test_suite(int, char*[] )
91{
92 boost::unit_test::test_suite* test =
93 BOOST_TEST_SUITE( "Boost.Range combine() test suite" );
94
95 test->add(BOOST_TEST_CASE((
96 &boost_range_test::test_combine2<
97 const std::vector<int>, const std::list<int> >)));
98
99 test->add(BOOST_TEST_CASE((
100 &boost_range_test::test_combine2<
101 const std::vector<int>, std::list<int> >)));
102
103 test->add(BOOST_TEST_CASE((
104 &boost_range_test::test_combine2<
105 std::vector<int>, const std::list<int> >)));
106
107 test->add(BOOST_TEST_CASE((
108 &boost_range_test::test_combine2<
109 std::vector<int>, std::list<int> >)));
110
111 test->add(BOOST_TEST_CASE((
112 &boost_range_test::test_combine3<
113 std::vector<int>,
114 std::vector<int>,
115 std::vector<int> >)));
116
117 test->add(BOOST_TEST_CASE((
118 &boost_range_test::test_combine3<
119 std::vector<int>,
120 std::vector<int>,
121 const std::vector<int> >)));
122
123 test->add(BOOST_TEST_CASE((
124 &boost_range_test::test_combine3<
125 std::vector<int>,
126 const std::vector<int>,
127 std::vector<int> >)));
128
129 test->add(BOOST_TEST_CASE((
130 &boost_range_test::test_combine3<
131 std::vector<int>,
132 const std::vector<int>,
133 const std::vector<int> >)));
134
135 test->add(BOOST_TEST_CASE((
136 &boost_range_test::test_combine3<
137 const std::vector<int>,
138 std::vector<int>,
139 std::vector<int> >)));
140
141 test->add(BOOST_TEST_CASE((
142 &boost_range_test::test_combine3<
143 const std::vector<int>,
144 std::vector<int>,
145 const std::vector<int> >)));
146
147 test->add(BOOST_TEST_CASE((
148 &boost_range_test::test_combine3<
149 const std::vector<int>,
150 const std::vector<int>,
151 std::vector<int> >)));
152
153 test->add(BOOST_TEST_CASE((
154 &boost_range_test::test_combine3<
155 const std::vector<int>,
156 const std::vector<int>,
157 const std::vector<int> >)));
158
159 return test;
160}
161