Imported Upstream version 1.57.0
[platform/upstream/boost.git] / libs / numeric / odeint / test_external / nt2 / algebra_dispatcher.cpp
1 //==============================================================================
2 //         Copyright 2014          LRI    UMR 8623 CNRS/Univ Paris Sud XI
3 //         Copyright 2014          NumScale SAS
4 //
5 //          Distributed under the Boost Software License, Version 1.0.
6 //                 See accompanying file LICENSE.txt or copy at
7 //                     http://www.boost.org/LICENSE_1_0.txt
8 //==============================================================================
9 #define BOOST_TEST_MODULE odeint_nt2_algebra_dispatcher
10
11 #include <boost/test/included/unit_test.hpp>
12 #include <boost/test/floating_point_comparison.hpp>
13 #include <boost/numeric/odeint/external/nt2/nt2_algebra_dispatcher.hpp>
14 #include <boost/numeric/odeint/algebra/default_operations.hpp>
15 #include <boost/mpl/list.hpp>
16
17 #include <boost/preprocessor/repetition.hpp>
18 #include <boost/preprocessor/arithmetic/mul.hpp>
19
20 #include <nt2/table.hpp>
21 #include <nt2/sdk/meta/as.hpp>
22 #include <nt2/include/functions/ones.hpp>
23
24 using namespace boost::unit_test;
25 using namespace boost::numeric::odeint;
26
27 typedef boost::mpl::list< float , double > fp_types;
28
29 #define TABLE(z,n,text) nt2::table<T> y ## n =                                   \
30                         nt2::ones(1,2,nt2::meta::as_<T>() )*T(BOOST_PP_ADD(n,1));
31
32 #define PARAMS(z,n,text) T(BOOST_PP_ADD(n,1)),
33
34 #define SUM(z,n,text) +BOOST_PP_MUL(BOOST_PP_ADD(n,3),BOOST_PP_ADD(n,2))
35
36 #define TEST(z,n,text) BOOST_CHECK_SMALL( y0(BOOST_PP_ADD(n,1))                  \
37                        -T( 2 BOOST_PP_REPEAT(text, SUM, text) ), T(1e-10) );
38
39 #define TEST_CASE(z,n,text) BOOST_AUTO_TEST_CASE_TEMPLATE (                      \
40                             BOOST_PP_CAT(odeint_foreach, n), T, fp_types )       \
41 {                                                                                \
42   vector_space_algebra algebra;                                                  \
43   BOOST_PP_REPEAT(BOOST_PP_ADD(n,2),TABLE,tt)                                    \
44   BOOST_PP_CAT(algebra.for_each,BOOST_PP_ADD(n,2))(                              \
45                BOOST_PP_ENUM_PARAMS(BOOST_PP_ADD(n,2),y), default_operations::   \
46   BOOST_PP_CAT(scale_sum,BOOST_PP_ADD(n,1)) <T>(                                 \
47                BOOST_PP_REPEAT(n, PARAMS, text ) T(BOOST_PP_ADD(n,1))));         \
48   BOOST_PP_REPEAT(2,TEST,n)                                                      \
49 }
50
51 BOOST_AUTO_TEST_SUITE( nt2_algebra )
52
53 BOOST_PP_REPEAT(7,TEST_CASE,dummy)
54
55 BOOST_AUTO_TEST_SUITE_END()