]>
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 | #ifdef _MSC_VER | |
8 | # pragma warning (disable : 4996) // POSIX name for this item is deprecated | |
9 | # pragma warning (disable : 4224) // nonstandard extension used : formal parameter 'arg' was previously defined as a type | |
10 | # pragma warning (disable : 4180) // qualifier applied to function type has no meaning; ignored | |
11 | #endif | |
12 | ||
13 | #include <boost/math/concepts/real_concept.hpp> | |
14 | #define BOOST_TEST_MAIN | |
15 | #include <boost/test/unit_test.hpp> | |
92f5a8d4 | 16 | #include <boost/test/tools/floating_point_comparison.hpp> |
7c673cae FG |
17 | #include <boost/math/special_functions/math_fwd.hpp> |
18 | #include <boost/math/tools/stats.hpp> | |
19 | #include <boost/math/tools/test.hpp> | |
20 | #include <boost/math/constants/constants.hpp> | |
21 | #include <boost/type_traits/is_floating_point.hpp> | |
22 | #include <boost/array.hpp> | |
23 | #include "functor.hpp" | |
24 | ||
25 | #include "handle_test_result.hpp" | |
26 | #include "table_type.hpp" | |
27 | ||
28 | #undef small // VC++ #defines small char !!!!!! | |
29 | ||
30 | #ifndef SC_ | |
31 | #define SC_(x) static_cast<typename table_type<T>::type>(BOOST_JOIN(x, L)) | |
32 | #endif | |
33 | ||
34 | template <class Real, class T> | |
35 | void do_test_beta(const T& data, const char* type_name, const char* test_name) | |
36 | { | |
37 | #if !(defined(ERROR_REPORTING_MODE) && !defined(BETA_FUNCTION_TO_TEST)) | |
38 | typedef Real value_type; | |
39 | ||
40 | typedef value_type (*pg)(value_type, value_type); | |
41 | #ifdef BETA_FUNCTION_TO_TEST | |
42 | pg funcp = BETA_FUNCTION_TO_TEST; | |
43 | #elif defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS) | |
44 | pg funcp = boost::math::beta<value_type, value_type>; | |
45 | #else | |
46 | pg funcp = boost::math::beta; | |
47 | #endif | |
48 | ||
49 | boost::math::tools::test_result<value_type> result; | |
50 | ||
51 | std::cout << "Testing " << test_name << " with type " << type_name | |
52 | << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"; | |
53 | ||
54 | // | |
55 | // test beta against data: | |
56 | // | |
57 | result = boost::math::tools::test_hetero<Real>( | |
58 | data, | |
59 | bind_func<Real>(funcp, 0, 1), | |
60 | extract_result<Real>(2)); | |
61 | handle_test_result(result, data[result.worst()], result.worst(), type_name, "beta", test_name); | |
62 | std::cout << std::endl; | |
63 | #endif | |
64 | } | |
65 | template <class T> | |
66 | void test_beta(T, const char* name) | |
67 | { | |
68 | // | |
69 | // The actual test data is rather verbose, so it's in a separate file | |
70 | // | |
71 | // The contents are as follows, each row of data contains | |
72 | // three items, input value a, input value b and beta(a, b): | |
73 | // | |
74 | # include "beta_small_data.ipp" | |
75 | ||
76 | do_test_beta<T>(beta_small_data, name, "Beta Function: Small Values"); | |
77 | ||
78 | # include "beta_med_data.ipp" | |
79 | ||
80 | do_test_beta<T>(beta_med_data, name, "Beta Function: Medium Values"); | |
81 | ||
82 | # include "beta_exp_data.ipp" | |
83 | ||
84 | do_test_beta<T>(beta_exp_data, name, "Beta Function: Divergent Values"); | |
85 | } | |
86 | ||
87 | template <class T> | |
88 | void test_spots(T) | |
89 | { | |
90 | // | |
91 | // Basic sanity checks, tolerance is 20 epsilon expressed as a percentage: | |
92 | // | |
93 | T tolerance = boost::math::tools::epsilon<T>() * 20 * 100; | |
94 | T small = boost::math::tools::epsilon<T>() / 1024; | |
95 | BOOST_CHECK_CLOSE(::boost::math::beta(static_cast<T>(1), static_cast<T>(1)), static_cast<T>(1), tolerance); | |
96 | BOOST_CHECK_CLOSE(::boost::math::beta(static_cast<T>(1), static_cast<T>(4)), static_cast<T>(0.25), tolerance); | |
97 | BOOST_CHECK_CLOSE(::boost::math::beta(static_cast<T>(4), static_cast<T>(1)), static_cast<T>(0.25), tolerance); | |
98 | BOOST_CHECK_CLOSE(::boost::math::beta(small, static_cast<T>(4)), 1/small, tolerance); | |
99 | BOOST_CHECK_CLOSE(::boost::math::beta(static_cast<T>(4), small), 1/small, tolerance); | |
100 | BOOST_CHECK_CLOSE(::boost::math::beta(static_cast<T>(4), static_cast<T>(20)), static_cast<T>(0.00002823263692828910220214568040654997176736L), tolerance); | |
1e59de90 TL |
101 | if (std::numeric_limits<T>::digits < 100) |
102 | { | |
103 | // Inexact input, so disable for ultra precise long doubles: | |
104 | BOOST_CHECK_CLOSE(::boost::math::beta(static_cast<T>(0.0125L), static_cast<T>(0.000023L)), static_cast<T>(43558.24045647538375006349016083320744662L), tolerance * 2); | |
105 | } | |
7c673cae FG |
106 | } |
107 |