]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/numeric/odeint/test/const_step_time_iterator.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / numeric / odeint / test / const_step_time_iterator.cpp
1 /*
2 [auto_generated]
3 libs/numeric/odeint/test/const_step_time_iterator.cpp
4
5 [begin_description]
6 This file tests the const step time iterator.
7 [end_description]
8
9 Copyright 2012-2013 Karsten Ahnert
10 Copyright 2012-2013 Mario Mulansky
11
12 Distributed under the Boost Software License, Version 1.0.
13 (See accompanying file LICENSE_1_0.txt or
14 copy at http://www.boost.org/LICENSE_1_0.txt)
15 */
16
17
18 #define BOOST_TEST_MODULE odeint_const_step_time_iterator
19
20 #include <iterator>
21 #include <algorithm>
22 #include <vector>
23
24 #include <boost/numeric/odeint/config.hpp>
25 #include <boost/array.hpp>
26 #include <boost/range/algorithm/copy.hpp>
27 #include <boost/range/algorithm/for_each.hpp>
28 #include <boost/mpl/vector.hpp>
29
30 #include <boost/test/unit_test.hpp>
31 #include <boost/test/floating_point_comparison.hpp>
32
33 #include <boost/numeric/odeint/iterator/const_step_time_iterator.hpp>
34 #include "dummy_steppers.hpp"
35 #include "dummy_odes.hpp"
36 #include "dummy_observers.hpp"
37
38 namespace mpl = boost::mpl;
39 using namespace boost::numeric::odeint;
40
41 typedef dummy_stepper::state_type state_type;
42 typedef dummy_stepper::value_type value_type;
43 typedef dummy_stepper::time_type time_type;
44 typedef std::vector< std::pair< state_type , time_type > > result_vector;
45
46 BOOST_AUTO_TEST_SUITE( const_step_time_iterator_test )
47
48 typedef mpl::vector<
49 dummy_stepper
50 , dummy_dense_output_stepper
51 > dummy_steppers;
52
53
54
55 BOOST_AUTO_TEST_CASE_TEMPLATE( copy_stepper_iterator , Stepper , dummy_steppers )
56 {
57 typedef const_step_time_iterator< Stepper , empty_system , state_type > iterator_type;
58 state_type x = {{ 1.0 }};
59 iterator_type iter1 = iterator_type( Stepper() , empty_system() , x , 0.0 , 1.0 , 0.1 );
60 iterator_type iter2 = iter1;
61 BOOST_CHECK_EQUAL( &( iter1->first ) , &( iter2->first ) );
62 BOOST_CHECK_EQUAL( &( iter1->first ) , &x );
63 BOOST_CHECK( iter1.same( iter2 ) );
64 }
65
66 BOOST_AUTO_TEST_CASE_TEMPLATE( assignment_stepper_iterator , Stepper , dummy_steppers )
67 {
68 typedef const_step_time_iterator< Stepper , empty_system , state_type > iterator_type;
69 state_type x1 = {{ 1.0 }} , x2 = {{ 2.0 }};
70 iterator_type iter1 = iterator_type( Stepper() , empty_system() , x1 , 0.0 , 1.0 , 0.1 );
71 iterator_type iter2 = iterator_type( Stepper() , empty_system() , x2 , 0.0 , 1.0 , 0.2 );
72 BOOST_CHECK_EQUAL( &( iter1->first ) , &x1 );
73 BOOST_CHECK_EQUAL( &( iter2->first ) , &x2 );
74 BOOST_CHECK( !iter1.same( iter2 ) );
75 iter2 = iter1;
76 BOOST_CHECK_EQUAL( &( iter1->first ) , &x1 );
77 BOOST_CHECK_EQUAL( &( iter2->first ) , &x1 );
78 BOOST_CHECK( iter1.same( iter2 ) );
79 }
80
81 BOOST_AUTO_TEST_CASE_TEMPLATE( stepper_iterator_factory , Stepper , dummy_steppers )
82 {
83 Stepper stepper;
84 empty_system system;
85 state_type x = {{ 1.0 }};
86
87 std::for_each(
88 make_const_step_time_iterator_begin( stepper , boost::ref( system ) , x , 0.0 , 1.0 , 0.1 ) ,
89 make_const_step_time_iterator_end( stepper , boost::ref( system ) , x ) ,
90 dummy_observer() );
91
92 BOOST_CHECK_CLOSE( x[0] , 3.5 , 1.0e-13 );
93 }
94
95 BOOST_AUTO_TEST_CASE_TEMPLATE( stepper_range , Stepper , dummy_steppers )
96 {
97 Stepper stepper;
98 empty_system system;
99 state_type x = {{ 1.0 }};
100
101 boost::for_each( make_const_step_time_range( stepper , boost::ref( system ) , x , 0.0 , 1.0 , 0.1 ) ,
102 dummy_observer() );
103
104 BOOST_CHECK_CLOSE( x[0] , 3.5 , 1.0e-13 );
105 }
106
107 BOOST_AUTO_TEST_CASE_TEMPLATE( stepper_iterator_with_reference_wrapper_factory , Stepper , dummy_steppers )
108 {
109 Stepper stepper;
110 empty_system system;
111 state_type x = {{ 1.0 }};
112
113 std::for_each(
114 make_const_step_time_iterator_begin( boost::ref( stepper ) , boost::ref( system ) , x , 0.0 , 1.0 , 0.1 ) ,
115 make_const_step_time_iterator_end( boost::ref( stepper ) , boost::ref( system ) , x ) ,
116 dummy_observer() );
117
118 BOOST_CHECK_CLOSE( x[0] , 3.5 , 1.0e-13 );
119 }
120
121 BOOST_AUTO_TEST_CASE_TEMPLATE( stepper_range_with_reference_wrapper , Stepper , dummy_steppers )
122 {
123 Stepper stepper;
124 empty_system system;
125 state_type x = {{ 1.0 }};
126
127 boost::for_each( make_const_step_time_range( boost::ref( stepper ) , boost::ref( system ) , x , 0.0 , 1.0 , 0.1 ) ,
128 dummy_observer() );
129
130 BOOST_CHECK_CLOSE( x[0] , 3.5 , 1.0e-13 );
131 }
132
133
134
135 BOOST_AUTO_TEST_CASE_TEMPLATE( transitivity1 , Stepper , dummy_steppers )
136 {
137 typedef const_step_time_iterator< Stepper , empty_system , state_type > stepper_iterator;
138
139 state_type x = {{ 1.0 }};
140 stepper_iterator first1( Stepper() , empty_system() , x , 1.5 , 1.0 , 0.1 );
141 stepper_iterator last1( Stepper() , empty_system() , x );
142 stepper_iterator last2( Stepper() , empty_system() , x );
143
144 BOOST_CHECK( first1 == last1 );
145 BOOST_CHECK( first1 == last2 );
146 BOOST_CHECK( last1 == last2 );
147
148 first1 = stepper_iterator( Stepper() , empty_system() , x , 2.0 , 2.0 , 0.1 );
149 last1 = stepper_iterator( Stepper() , empty_system() , x );
150 BOOST_CHECK( first1 != last1 );
151 BOOST_CHECK( ++first1 == last1 );
152 }
153
154 BOOST_AUTO_TEST_CASE_TEMPLATE( copy_algorithm , Stepper , dummy_steppers )
155 {
156 typedef const_step_time_iterator< Stepper , empty_system , state_type > stepper_iterator;
157 state_type x = {{ 1.0 }};
158 result_vector res;
159 stepper_iterator first( Stepper() , empty_system() , x , 0.0 , 0.35 , 0.1 );
160 stepper_iterator last( Stepper() , empty_system() , x );
161
162 std::copy( first , last , std::back_insert_iterator< result_vector >( res ) );
163
164 BOOST_CHECK_EQUAL( res.size() , size_t( 4 ) );
165 BOOST_CHECK_CLOSE( res[0].first[0] , 1.0 , 1.0e-13 );
166 BOOST_CHECK_CLOSE( res[0].second , 0.0 , 1.0e-13 );
167 BOOST_CHECK_CLOSE( res[1].first[0] , 1.25 , 1.0e-13 );
168 BOOST_CHECK_CLOSE( res[1].second , 0.1 , 1.0e-13 );
169 BOOST_CHECK_CLOSE( res[2].first[0] , 1.5 , 1.0e-13 );
170 BOOST_CHECK_CLOSE( res[2].second , 0.2 , 1.0e-13 );
171 BOOST_CHECK_CLOSE( res[3].first[0] , 1.75 , 1.0e-13 );
172 BOOST_CHECK_CLOSE( res[3].second , 0.3 , 1.0e-13 );
173 BOOST_CHECK_CLOSE( x[0] , 1.75 , 1.0e-13 );
174 }
175
176 BOOST_AUTO_TEST_CASE_TEMPLATE( copy_algorithm_with_factory , Stepper , dummy_steppers )
177 {
178 state_type x = {{ 1.0 }};
179 result_vector res;
180 std::copy( make_const_step_time_iterator_begin( Stepper() , empty_system() , x , 0.0 , 0.35 , 0.1 ) ,
181 make_const_step_time_iterator_end( Stepper() , empty_system() , x ) ,
182 std::back_insert_iterator< result_vector >( res ) );
183
184 BOOST_CHECK_EQUAL( res.size() , size_t( 4 ) );
185 BOOST_CHECK_CLOSE( res[0].first[0] , 1.0 , 1.0e-13 );
186 BOOST_CHECK_CLOSE( res[0].second , 0.0 , 1.0e-13 );
187 BOOST_CHECK_CLOSE( res[1].first[0] , 1.25 , 1.0e-13 );
188 BOOST_CHECK_CLOSE( res[1].second , 0.1 , 1.0e-13 );
189 BOOST_CHECK_CLOSE( res[2].first[0] , 1.5 , 1.0e-13 );
190 BOOST_CHECK_CLOSE( res[2].second , 0.2 , 1.0e-13 );
191 BOOST_CHECK_CLOSE( res[3].first[0] , 1.75 , 1.0e-13 );
192 BOOST_CHECK_CLOSE( res[3].second , 0.3 , 1.0e-13 );
193 BOOST_CHECK_CLOSE( x[0] , 1.75 , 1.0e-13 );
194 }
195
196 BOOST_AUTO_TEST_CASE_TEMPLATE( copy_algorithm_with_range_factory , Stepper , dummy_steppers )
197 {
198 state_type x = {{ 1.0 }};
199 result_vector res;
200 boost::range::copy( make_const_step_time_range( Stepper() , empty_system() , x , 0.0 , 0.35 , 0.1 ) ,
201 std::back_insert_iterator< result_vector >( res ) );
202
203 BOOST_CHECK_EQUAL( res.size() , size_t( 4 ) );
204 BOOST_CHECK_CLOSE( res[0].first[0] , 1.0 , 1.0e-13 );
205 BOOST_CHECK_CLOSE( res[0].second , 0.0 , 1.0e-13 );
206 BOOST_CHECK_CLOSE( res[1].first[0] , 1.25 , 1.0e-13 );
207 BOOST_CHECK_CLOSE( res[1].second , 0.1 , 1.0e-13 );
208 BOOST_CHECK_CLOSE( res[2].first[0] , 1.5 , 1.0e-13 );
209 BOOST_CHECK_CLOSE( res[2].second , 0.2 , 1.0e-13 );
210 BOOST_CHECK_CLOSE( res[3].first[0] , 1.75 , 1.0e-13 );
211 BOOST_CHECK_CLOSE( res[3].second , 0.3 , 1.0e-13 );
212 BOOST_CHECK_CLOSE( x[0] , 1.75 , 1.0e-13 );
213 }
214
215
216
217
218 BOOST_AUTO_TEST_SUITE_END()