Brian Silverman | 7c33ab2 | 2018-08-04 17:14:51 -0700 | [diff] [blame^] | 1 | /* |
| 2 | [auto_generated] |
| 3 | libs/numeric/odeint/test/n_step_time_iterator.cpp |
| 4 | |
| 5 | [begin_description] |
| 6 | This file tests the n-step time iterator. |
| 7 | [end_description] |
| 8 | |
| 9 | Copyright 2009-2013 Karsten Ahnert |
| 10 | Copyright 2009-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_n_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/n_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( n_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 n_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 , 0.1 , 10 ); |
| 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 n_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 , 0.1 , 10 ); |
| 71 | iterator_type iter2 = iterator_type( Stepper() , empty_system() , x2 , 0.0 , 0.2 , 10 ); |
| 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_n_step_time_iterator_begin( stepper , boost::ref( system ) , x , 0.0 , 0.1 , 10 ) , |
| 89 | make_n_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_n_step_time_range( stepper , boost::ref( system ) , x , 0.0 , 0.1 , 10 ) , |
| 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_n_step_time_iterator_begin( boost::ref( stepper ) , boost::ref( system ) , x , 0.0 , 0.1 , 10 ) , |
| 115 | make_n_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_n_step_time_range( boost::ref( stepper ) , boost::ref( system ) , x , 0.0 , 0.1 , 10 ) , |
| 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 n_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 , 0.0 , 0.1 , 0 ); |
| 141 | stepper_iterator last1( Stepper() , empty_system() , x ); |
| 142 | stepper_iterator last2( Stepper() , empty_system() , x ); |
| 143 | |
| 144 | BOOST_CHECK( last1 == last2 ); |
| 145 | BOOST_CHECK( first1 != last1 ); |
| 146 | BOOST_CHECK( ++first1 == last1 ); |
| 147 | } |
| 148 | |
| 149 | BOOST_AUTO_TEST_CASE_TEMPLATE( copy_algorithm , Stepper , dummy_steppers ) |
| 150 | { |
| 151 | typedef n_step_time_iterator< Stepper , empty_system , state_type > stepper_iterator; |
| 152 | state_type x = {{ 1.0 }}; |
| 153 | result_vector res; |
| 154 | stepper_iterator first( Stepper() , empty_system() , x , 0.0 , 0.1 , 3 ); |
| 155 | stepper_iterator last( Stepper() , empty_system() , x ); |
| 156 | |
| 157 | std::copy( first , last , std::back_insert_iterator< result_vector >( res ) ); |
| 158 | |
| 159 | BOOST_CHECK_EQUAL( res.size() , size_t( 4 ) ); |
| 160 | BOOST_CHECK_CLOSE( res[0].first[0] , 1.0 , 1.0e-13 ); |
| 161 | BOOST_CHECK_CLOSE( res[0].second , 0.0 , 1.0e-13 ); |
| 162 | BOOST_CHECK_CLOSE( res[1].first[0] , 1.25 , 1.0e-13 ); |
| 163 | BOOST_CHECK_CLOSE( res[1].second , 0.1 , 1.0e-13 ); |
| 164 | BOOST_CHECK_CLOSE( res[2].first[0] , 1.5 , 1.0e-13 ); |
| 165 | BOOST_CHECK_CLOSE( res[2].second , 0.2 , 1.0e-13 ); |
| 166 | BOOST_CHECK_CLOSE( res[3].first[0] , 1.75 , 1.0e-13 ); |
| 167 | BOOST_CHECK_CLOSE( res[3].second , 0.3 , 1.0e-13 ); |
| 168 | BOOST_CHECK_CLOSE( x[0] , 1.75 , 1.0e-13 ); |
| 169 | } |
| 170 | |
| 171 | BOOST_AUTO_TEST_CASE_TEMPLATE( copy_algorithm_with_factory , Stepper , dummy_steppers ) |
| 172 | { |
| 173 | state_type x = {{ 1.0 }}; |
| 174 | result_vector res; |
| 175 | std::copy( make_n_step_time_iterator_begin( Stepper() , empty_system() , x , 0.0 , 0.1 , 3 ) , |
| 176 | make_n_step_time_iterator_end( Stepper() , empty_system() , x ) , |
| 177 | std::back_insert_iterator< result_vector >( res ) ); |
| 178 | |
| 179 | BOOST_CHECK_EQUAL( res.size() , size_t( 4 ) ); |
| 180 | BOOST_CHECK_CLOSE( res[0].first[0] , 1.0 , 1.0e-13 ); |
| 181 | BOOST_CHECK_CLOSE( res[0].second , 0.0 , 1.0e-13 ); |
| 182 | BOOST_CHECK_CLOSE( res[1].first[0] , 1.25 , 1.0e-13 ); |
| 183 | BOOST_CHECK_CLOSE( res[1].second , 0.1 , 1.0e-13 ); |
| 184 | BOOST_CHECK_CLOSE( res[2].first[0] , 1.5 , 1.0e-13 ); |
| 185 | BOOST_CHECK_CLOSE( res[2].second , 0.2 , 1.0e-13 ); |
| 186 | BOOST_CHECK_CLOSE( res[3].first[0] , 1.75 , 1.0e-13 ); |
| 187 | BOOST_CHECK_CLOSE( res[3].second , 0.3 , 1.0e-13 ); |
| 188 | BOOST_CHECK_CLOSE( x[0] , 1.75 , 1.0e-13 ); |
| 189 | } |
| 190 | |
| 191 | BOOST_AUTO_TEST_CASE_TEMPLATE( copy_algorithm_with_range_factory , Stepper , dummy_steppers ) |
| 192 | { |
| 193 | state_type x = {{ 1.0 }}; |
| 194 | result_vector res; |
| 195 | boost::range::copy( make_n_step_time_range( Stepper() , empty_system() , x , 0.0 , 0.1 , 3 ) , |
| 196 | std::back_insert_iterator< result_vector >( res ) ); |
| 197 | |
| 198 | BOOST_CHECK_EQUAL( res.size() , size_t( 4 ) ); |
| 199 | BOOST_CHECK_CLOSE( res[0].first[0] , 1.0 , 1.0e-13 ); |
| 200 | BOOST_CHECK_CLOSE( res[0].second , 0.0 , 1.0e-13 ); |
| 201 | BOOST_CHECK_CLOSE( res[1].first[0] , 1.25 , 1.0e-13 ); |
| 202 | BOOST_CHECK_CLOSE( res[1].second , 0.1 , 1.0e-13 ); |
| 203 | BOOST_CHECK_CLOSE( res[2].first[0] , 1.5 , 1.0e-13 ); |
| 204 | BOOST_CHECK_CLOSE( res[2].second , 0.2 , 1.0e-13 ); |
| 205 | BOOST_CHECK_CLOSE( res[3].first[0] , 1.75 , 1.0e-13 ); |
| 206 | BOOST_CHECK_CLOSE( res[3].second , 0.3 , 1.0e-13 ); |
| 207 | BOOST_CHECK_CLOSE( x[0] , 1.75 , 1.0e-13 ); |
| 208 | } |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | BOOST_AUTO_TEST_SUITE_END() |