Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / math / test / test_heuman_lambda.hpp
1 // Copyright John Maddock 2015.
2 //  Use, modification and distribution are subject to the
3 //  Boost Software License, Version 1.0. (See accompanying file
4 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6 #ifdef _MSC_VER
7 #  pragma warning(disable : 4756) // overflow in constant arithmetic
8 // Constants are too big for float case, but this doesn't matter for test.
9 #endif
10
11 #include <boost/math/concepts/real_concept.hpp>
12 #define BOOST_TEST_MAIN
13 #include <boost/test/unit_test.hpp>
14 #include <boost/test/tools/floating_point_comparison.hpp>
15 #include <boost/math/special_functions/math_fwd.hpp>
16 #include <boost/math/constants/constants.hpp>
17 #include <boost/array.hpp>
18 #include "functor.hpp"
19
20 #include "handle_test_result.hpp"
21 #include "table_type.hpp"
22
23 #ifndef SC_
24 #define SC_(x) static_cast<typename table_type<T>::type>(BOOST_JOIN(x, L))
25 #endif
26
27 template <class Real, typename T>
28 void do_test_heuman_lambda(const T& data, const char* type_name, const char* test)
29 {
30 #if !(defined(ERROR_REPORTING_MODE) && !defined(HEUMAN_LAMBDA_FUNCTION_TO_TEST))
31    typedef Real                   value_type;
32
33    std::cout << "Testing: " << test << std::endl;
34
35 #ifdef HEUMAN_LAMBDA_FUNCTION_TO_TEST
36    value_type(*fp2)(value_type, value_type) = HEUMAN_LAMBDA_FUNCTION_TO_TEST;
37 #elif defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
38     value_type (*fp2)(value_type, value_type) = boost::math::ellint_d<value_type, value_type>;
39 #else
40    value_type(*fp2)(value_type, value_type) = boost::math::heuman_lambda;
41 #endif
42     boost::math::tools::test_result<value_type> result;
43
44     result = boost::math::tools::test_hetero<Real>(
45       data,
46       bind_func<Real>(fp2, 1, 0),
47       extract_result<Real>(2));
48    handle_test_result(result, data[result.worst()], result.worst(),
49       type_name, "heuman_lambda", test);
50
51    std::cout << std::endl;
52 #endif
53 }
54
55 template <typename T>
56 void test_spots(T, const char* type_name)
57 {
58     BOOST_MATH_STD_USING
59     // Function values calculated on http://functions.wolfram.com/
60     // Note that Mathematica's EllipticE accepts k^2 as the second parameter.
61     static const boost::array<boost::array<T, 3>, 5> data1 = {{
62        { { SC_(0.25), SC_(0.5), SC_(0.231195544262270355901990821099667428154924832224446817213200) } },
63        { { SC_(-0.25), SC_(0.5), SC_(-0.231195544262270355901990821099667428154924832224446817213200) } },
64         { { SC_(0), SC_(0.5), SC_(0) } },
65         { { SC_(1), T(0.5), SC_(0.792745183008071035953588061452801838417979005666066982987549) } },
66         { { SC_(1), T(0), SC_(0.841470984807896506652502321630298999622563060798371065672751) } },
67     }};
68
69     do_test_heuman_lambda<T>(data1, type_name, "Elliptic Integral Jacobi Zeta: Mathworld Data");
70
71 #include "heuman_lambda_data.ipp"
72
73     do_test_heuman_lambda<T>(heuman_lambda_data, type_name, "Elliptic Integral Heuman Lambda: Random Data");
74 }
75