]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Copyright John Maddock 2006. |
2 | // Copyright Paul A. Bristow 2007, 2009 | |
3 | // Use, modification and distribution are subject to the | |
4 | // Boost Software License, Version 1.0. (See accompanying file | |
5 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
6 | ||
7 | #include <boost/math/concepts/real_concept.hpp> | |
8 | #define BOOST_TEST_MAIN | |
9 | #include <boost/test/unit_test.hpp> | |
92f5a8d4 | 10 | #include <boost/test/tools/floating_point_comparison.hpp> |
7c673cae FG |
11 | #include <boost/math/special_functions/math_fwd.hpp> |
12 | #include <boost/math/constants/constants.hpp> | |
13 | #include <boost/array.hpp> | |
14 | #include "functor.hpp" | |
15 | ||
16 | #include "handle_test_result.hpp" | |
17 | #include "table_type.hpp" | |
18 | ||
19 | #ifndef SC_ | |
20 | #define SC_(x) static_cast<typename table_type<T>::type>(BOOST_JOIN(x, L)) | |
21 | #endif | |
22 | ||
23 | template <class Real, class T> | |
24 | void do_test_laguerre2(const T& data, const char* type_name, const char* test_name) | |
25 | { | |
26 | #if !(defined(ERROR_REPORTING_MODE) && !defined(LAGUERRE_FUNCTION_TO_TEST)) | |
27 | typedef Real value_type; | |
28 | ||
29 | typedef value_type (*pg)(unsigned, value_type); | |
30 | #ifdef LAGUERRE_FUNCTION_TO_TEST | |
31 | pg funcp = LAGUERRE_FUNCTION_TO_TEST; | |
32 | #elif defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS) | |
33 | pg funcp = boost::math::laguerre<value_type>; | |
34 | #else | |
35 | pg funcp = boost::math::laguerre; | |
36 | #endif | |
37 | ||
38 | boost::math::tools::test_result<value_type> result; | |
39 | ||
40 | std::cout << "Testing " << test_name << " with type " << type_name | |
41 | << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"; | |
42 | ||
43 | // | |
44 | // test laguerre against data: | |
45 | // | |
46 | result = boost::math::tools::test_hetero<Real>( | |
47 | data, | |
48 | bind_func_int1<Real>(funcp, 0, 1), | |
49 | extract_result<Real>(2)); | |
50 | handle_test_result(result, data[result.worst()], result.worst(), type_name, "laguerre(n, x)", test_name); | |
51 | ||
52 | std::cout << std::endl; | |
53 | #endif | |
54 | } | |
55 | ||
56 | template <class Real, class T> | |
57 | void do_test_laguerre3(const T& data, const char* type_name, const char* test_name) | |
58 | { | |
59 | #if !(defined(ERROR_REPORTING_MODE) && !defined(ASSOC_LAGUERRE_FUNCTION_TO_TEST)) | |
60 | typedef Real value_type; | |
61 | ||
62 | typedef value_type (*pg)(unsigned, unsigned, value_type); | |
63 | #ifdef ASSOC_LAGUERRE_FUNCTION_TO_TEST | |
64 | pg funcp = ASSOC_LAGUERRE_FUNCTION_TO_TEST; | |
65 | #elif defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS) | |
66 | pg funcp = boost::math::laguerre<unsigned, value_type>; | |
67 | #else | |
68 | pg funcp = boost::math::laguerre; | |
69 | #endif | |
70 | ||
71 | boost::math::tools::test_result<value_type> result; | |
72 | ||
73 | std::cout << "Testing " << test_name << " with type " << type_name | |
74 | << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"; | |
75 | ||
76 | // | |
77 | // test laguerre against data: | |
78 | // | |
79 | result = boost::math::tools::test_hetero<Real>( | |
80 | data, | |
81 | bind_func_int2<Real>(funcp, 0, 1, 2), | |
82 | extract_result<Real>(3)); | |
83 | handle_test_result(result, data[result.worst()], result.worst(), type_name, "laguerre(n, m, x)", test_name); | |
84 | std::cout << std::endl; | |
85 | #endif | |
86 | } | |
87 | ||
88 | template <class T> | |
89 | void test_laguerre(T, const char* name) | |
90 | { | |
91 | // | |
92 | // The actual test data is rather verbose, so it's in a separate file | |
93 | // | |
94 | // The contents are as follows, each row of data contains | |
95 | // three items, input value a, input value b and erf(a, b): | |
96 | // | |
97 | # include "laguerre2.ipp" | |
98 | ||
99 | do_test_laguerre2<T>(laguerre2, name, "Laguerre Polynomials"); | |
100 | ||
101 | # include "laguerre3.ipp" | |
102 | ||
103 | do_test_laguerre3<T>(laguerre3, name, "Associated Laguerre Polynomials"); | |
104 | } | |
105 | ||
106 | template <class T> | |
107 | void test_spots(T, const char* t) | |
108 | { | |
109 | std::cout << "Testing basic sanity checks for type " << t << std::endl; | |
110 | // | |
111 | // basic sanity checks, tolerance is 100 epsilon: | |
112 | // | |
113 | T tolerance = boost::math::tools::epsilon<T>() * 100; | |
114 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(1, static_cast<T>(0.5L)), static_cast<T>(0.5L), tolerance); | |
115 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(4, static_cast<T>(0.5L)), static_cast<T>(-0.3307291666666666666666666666666666666667L), tolerance); | |
116 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(7, static_cast<T>(0.5L)), static_cast<T>(-0.5183392237103174603174603174603174603175L), tolerance); | |
117 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(20, static_cast<T>(0.5L)), static_cast<T>(0.3120174870800154148915399248893113634676L), tolerance); | |
118 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(50, static_cast<T>(0.5L)), static_cast<T>(-0.3181388060269979064951118308575628226834L), tolerance); | |
119 | ||
120 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(1, static_cast<T>(-0.5L)), static_cast<T>(1.5L), tolerance); | |
121 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(4, static_cast<T>(-0.5L)), static_cast<T>(3.835937500000000000000000000000000000000L), tolerance); | |
122 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(7, static_cast<T>(-0.5L)), static_cast<T>(7.950934709821428571428571428571428571429L), tolerance); | |
123 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(20, static_cast<T>(-0.5L)), static_cast<T>(76.12915699869631476833699787070874048223L), tolerance); | |
124 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(50, static_cast<T>(-0.5L)), static_cast<T>(2307.428631277506570629232863491518399720L), tolerance); | |
125 | ||
126 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(1, static_cast<T>(4.5L)), static_cast<T>(-3.500000000000000000000000000000000000000L), tolerance); | |
127 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(4, static_cast<T>(4.5L)), static_cast<T>(0.08593750000000000000000000000000000000000L), tolerance); | |
128 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(7, static_cast<T>(4.5L)), static_cast<T>(-1.036928013392857142857142857142857142857L), tolerance); | |
129 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(20, static_cast<T>(4.5L)), static_cast<T>(1.437239150257817378525582974722170737587L), tolerance); | |
130 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(50, static_cast<T>(4.5L)), static_cast<T>(-0.7795068145562651416494321484050019245248L), tolerance); | |
131 | ||
132 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(4, 5, static_cast<T>(0.5L)), static_cast<T>(88.31510416666666666666666666666666666667L), tolerance); | |
133 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(10, 0, static_cast<T>(2.5L)), static_cast<T>(-0.8802526766660982969576719576719576719577L), tolerance); | |
134 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(10, 1, static_cast<T>(4.5L)), static_cast<T>(1.564311458042689732142857142857142857143L), tolerance); | |
135 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(10, 6, static_cast<T>(8.5L)), static_cast<T>(20.51596541066649098875661375661375661376L), tolerance); | |
136 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(10, 12, static_cast<T>(12.5L)), static_cast<T>(-199.5560968456234671241181657848324514991L), tolerance); | |
137 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(50, 40, static_cast<T>(12.5L)), static_cast<T>(-4.996769495006119488583146995907246595400e16L), tolerance); | |
138 | } | |
139 |