mirror of
https://github.com/boostorg/odeint.git
synced 2025-05-11 13:34:09 +00:00
unittests
This commit is contained in:
parent
6a00e946f7
commit
518f2186ca
@ -48,6 +48,10 @@ test-suite "odeint"
|
|||||||
[ run adams_bashforth.cpp ]
|
[ run adams_bashforth.cpp ]
|
||||||
[ run adams_moulton.cpp ]
|
[ run adams_moulton.cpp ]
|
||||||
[ run adams_bashforth_moulton.cpp ]
|
[ run adams_bashforth_moulton.cpp ]
|
||||||
|
[ run adaptive_adams_bashforth.cpp ]
|
||||||
|
[ run controlled_adams_bashforth_moulton.cpp ]
|
||||||
|
[ run adaptive_adams_coefficients.cpp ]
|
||||||
|
[ run polynomial.cpp ]
|
||||||
[ run generic_stepper.cpp ]
|
[ run generic_stepper.cpp ]
|
||||||
[ run generic_error_stepper.cpp ]
|
[ run generic_error_stepper.cpp ]
|
||||||
[ run bulirsch_stoer.cpp ]
|
[ run bulirsch_stoer.cpp ]
|
||||||
|
44
test/adaptive_adams_bashforth.cpp
Normal file
44
test/adaptive_adams_bashforth.cpp
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#include <boost/config.hpp>
|
||||||
|
#ifdef BOOST_MSVC
|
||||||
|
#pragma warning(disable:4996)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define BOOST_TEST_MODULE odeint_adaptive_adams_bashforth
|
||||||
|
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
|
#include <boost/numeric/odeint/stepper/adaptive_adams_bashforth.hpp>
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using namespace boost::unit_test;
|
||||||
|
using namespace boost::numeric::odeint;
|
||||||
|
|
||||||
|
struct const_sys
|
||||||
|
{
|
||||||
|
template< class State , class Deriv , class Value >
|
||||||
|
void operator()( const State &x , Deriv &dxdt , const Value &dt ) const
|
||||||
|
{
|
||||||
|
dxdt[0] = 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE( adaptive_adams_bashforth_test )
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE( test_const_int )
|
||||||
|
{
|
||||||
|
typedef double time_type;
|
||||||
|
typedef std::vector<double> state_type;
|
||||||
|
|
||||||
|
typedef adaptive_adams_bashforth<3, state_type, time_type> aab_type;
|
||||||
|
|
||||||
|
state_type x0;
|
||||||
|
x0.push_back(0);
|
||||||
|
time_type t0 = 0.0;
|
||||||
|
time_type dt = 0.1;
|
||||||
|
|
||||||
|
aab_type aab;
|
||||||
|
aab.do_step(const_sys(), x0, t0, dt);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE_END()
|
52
test/adaptive_adams_coefficients.cpp
Normal file
52
test/adaptive_adams_coefficients.cpp
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
#include <boost/config.hpp>
|
||||||
|
#ifdef BOOST_MSVC
|
||||||
|
#pragma warning(disable:4996)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define BOOST_TEST_MODULE odeint_adaptive_adams_coefficients
|
||||||
|
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
|
#include <boost/numeric/odeint/stepper/detail/adaptive_adams_coefficients.hpp>
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <boost/mpl/list.hpp>
|
||||||
|
#include <boost/mpl/size_t.hpp>
|
||||||
|
#include <boost/mpl/range_c.hpp>
|
||||||
|
|
||||||
|
using namespace boost::unit_test;
|
||||||
|
using namespace boost::numeric::odeint;
|
||||||
|
|
||||||
|
typedef double value_type;
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE( adaptive_adams_coefficients_test )
|
||||||
|
|
||||||
|
typedef boost::mpl::range_c< size_t , 2 , 10 > vector_of_steps;
|
||||||
|
BOOST_AUTO_TEST_CASE_TEMPLATE( test_step, step_type, vector_of_steps )
|
||||||
|
{
|
||||||
|
const static size_t steps = step_type::value;
|
||||||
|
|
||||||
|
typedef std::vector<double> deriv_type;
|
||||||
|
typedef double time_type;
|
||||||
|
|
||||||
|
typedef detail::adaptive_adams_coefficients<steps, deriv_type, time_type> aac;
|
||||||
|
|
||||||
|
std::vector<double> deriv;
|
||||||
|
deriv.push_back(-1);
|
||||||
|
|
||||||
|
aac coeff;
|
||||||
|
for(size_t i=0; i<steps; ++i)
|
||||||
|
{
|
||||||
|
coeff.step(deriv, i);
|
||||||
|
BOOST_CHECK_EQUAL(coeff.m_tts[0], i);
|
||||||
|
|
||||||
|
coeff.confirm();
|
||||||
|
BOOST_CHECK_EQUAL(coeff.m_ts[0], i);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_CHECK_EQUAL(coeff.m_ss[0][0].m_v[0], -1);
|
||||||
|
BOOST_CHECK_EQUAL(coeff.m_ss[1][0].m_v[0], 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE_END()
|
22
test/controlled_adams_bashforth_moulton.cpp
Normal file
22
test/controlled_adams_bashforth_moulton.cpp
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#include <boost/config.hpp>
|
||||||
|
#ifdef BOOST_MSVC
|
||||||
|
#pragma warning(disable:4996)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define BOOST_TEST_MODULE odeint_controlled_adams_bashforth_moulton
|
||||||
|
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
|
#include <boost/numeric/odeint/stepper/controlled_adams_bashforth_moulton.hpp>
|
||||||
|
|
||||||
|
using namespace boost::unit_test;
|
||||||
|
using namespace boost::numeric::odeint;
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE( controlled_adams_bashforth_moulton_test )
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE( test_init )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE_END()
|
@ -54,6 +54,8 @@
|
|||||||
#include <boost/numeric/odeint/stepper/dense_output_runge_kutta.hpp>
|
#include <boost/numeric/odeint/stepper/dense_output_runge_kutta.hpp>
|
||||||
#include <boost/numeric/odeint/stepper/bulirsch_stoer_dense_out.hpp>
|
#include <boost/numeric/odeint/stepper/bulirsch_stoer_dense_out.hpp>
|
||||||
|
|
||||||
|
#include <boost/numeric/odeint/stepper/controlled_adams_bashforth_moulton.hpp>
|
||||||
|
|
||||||
#include <boost/numeric/odeint/util/detail/less_with_sign.hpp>
|
#include <boost/numeric/odeint/util/detail/less_with_sign.hpp>
|
||||||
|
|
||||||
using namespace boost::unit_test;
|
using namespace boost::unit_test;
|
||||||
@ -237,7 +239,9 @@ class stepper_methods : public mpl::vector<
|
|||||||
controlled_runge_kutta< runge_kutta_dopri5< state_type > > ,
|
controlled_runge_kutta< runge_kutta_dopri5< state_type > > ,
|
||||||
controlled_runge_kutta< runge_kutta_fehlberg78< state_type > > ,
|
controlled_runge_kutta< runge_kutta_fehlberg78< state_type > > ,
|
||||||
bulirsch_stoer< state_type > ,
|
bulirsch_stoer< state_type > ,
|
||||||
dense_output_runge_kutta< controlled_runge_kutta< runge_kutta_dopri5< state_type > > >
|
dense_output_runge_kutta< controlled_runge_kutta< runge_kutta_dopri5< state_type > > >,
|
||||||
|
controlled_adams_bashforth_moulton<3, state_type, value_type>,
|
||||||
|
controlled_adams_bashforth_moulton<5, state_type, value_type>
|
||||||
//bulirsch_stoer_dense_out< state_type >
|
//bulirsch_stoer_dense_out< state_type >
|
||||||
> { };
|
> { };
|
||||||
|
|
||||||
|
60
test/polynomial.cpp
Normal file
60
test/polynomial.cpp
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
#include <boost/config.hpp>
|
||||||
|
#ifdef BOOST_MSVC
|
||||||
|
#pragma warning(disable:4996)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define BOOST_TEST_MODULE odeint_polynomial
|
||||||
|
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
|
#include <boost/numeric/odeint/stepper/detail/polynomial.hpp>
|
||||||
|
|
||||||
|
using namespace boost::unit_test;
|
||||||
|
using namespace boost::numeric::odeint::detail;
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE( polynomial_test )
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE( test_init )
|
||||||
|
{
|
||||||
|
Polynomial<3, double> p1;
|
||||||
|
|
||||||
|
boost::array<double, 3> coeff = {0, 1, 2};
|
||||||
|
Polynomial<3, double> p2(coeff);
|
||||||
|
}
|
||||||
|
BOOST_AUTO_TEST_CASE( test_add_roots )
|
||||||
|
{
|
||||||
|
Polynomial<3, double> poly;
|
||||||
|
poly.add_root(1);
|
||||||
|
|
||||||
|
poly.add_root(0);
|
||||||
|
}
|
||||||
|
BOOST_AUTO_TEST_CASE( test_copy )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
BOOST_AUTO_TEST_CASE( test_remove )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
BOOST_AUTO_TEST_CASE( test_integrate )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
BOOST_AUTO_TEST_CASE( test_evaluate )
|
||||||
|
{
|
||||||
|
boost::array<double, 3> c1 = {2, 1, 0};
|
||||||
|
Polynomial<3, double> p1(c1);
|
||||||
|
|
||||||
|
BOOST_CHECK_EQUAL(p1.evaluate(0), 0);
|
||||||
|
BOOST_CHECK_EQUAL(p1.evaluate(1), 3);
|
||||||
|
BOOST_CHECK_EQUAL(p1.evaluate(2), 10);
|
||||||
|
|
||||||
|
boost::array<double, 5> c2 = {0.001, 10, 0, 3, 1};
|
||||||
|
Polynomial<5, double> p2(c2);
|
||||||
|
|
||||||
|
BOOST_CHECK_CLOSE(p2.evaluate(0), 1, 0.001);
|
||||||
|
BOOST_CHECK_CLOSE(p2.evaluate(0.001), 1.003, 0.001);
|
||||||
|
BOOST_CHECK_CLOSE(p2.evaluate(1.001), 14.034, 0.001);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE_END()
|
Loading…
x
Reference in New Issue
Block a user