]>
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/tools/stats.hpp> |
12 | #include <boost/math/tools/test.hpp> | |
13 | #include <boost/type_traits/is_floating_point.hpp> | |
14 | #include <boost/array.hpp> | |
15 | #include <boost/math/special_functions/math_fwd.hpp> | |
16 | #include "functor.hpp" | |
17 | ||
18 | #include "handle_test_result.hpp" | |
19 | #include "table_type.hpp" | |
20 | ||
21 | #ifndef SC_ | |
22 | #define SC_(x) static_cast<typename table_type<T>::type>(BOOST_JOIN(x, L)) | |
23 | #endif | |
24 | ||
25 | template <class Real> | |
26 | struct negative_cbrt | |
27 | { | |
28 | negative_cbrt(){} | |
29 | ||
30 | template <class S> | |
31 | Real operator()(const S& row) | |
32 | { | |
33 | return boost::math::cbrt(Real(-Real(row[1]))); | |
34 | } | |
35 | }; | |
36 | ||
37 | ||
38 | template <class Real, class T> | |
39 | void do_test_cbrt(const T& data, const char* type_name, const char* test_name) | |
40 | { | |
41 | #if !(defined(ERROR_REPORTING_MODE) && !defined(CBRT_FUNCTION_TO_TEST)) | |
42 | typedef Real value_type; | |
43 | ||
44 | typedef value_type (*pg)(value_type); | |
45 | #ifdef CBRT_FUNCTION_TO_TEST | |
46 | pg funcp = boost::math::cbrt<value_type>; | |
47 | #elif defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS) | |
48 | pg funcp = boost::math::cbrt<value_type>; | |
49 | #else | |
50 | pg funcp = boost::math::cbrt; | |
51 | #endif | |
52 | ||
53 | boost::math::tools::test_result<value_type> result; | |
54 | ||
55 | std::cout << "Testing " << test_name << " with type " << type_name | |
56 | << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"; | |
57 | ||
58 | // | |
59 | // test cbrt against data: | |
60 | // | |
61 | result = boost::math::tools::test_hetero<Real>( | |
62 | data, | |
63 | bind_func<Real>(funcp, 1), | |
64 | extract_result<Real>(0)); | |
65 | result += boost::math::tools::test_hetero<Real>( | |
66 | data, | |
67 | negative_cbrt<Real>(), | |
68 | negate<Real>(extract_result<Real>(0))); | |
69 | handle_test_result(result, data[result.worst()], result.worst(), type_name, "cbrt", test_name); | |
70 | std::cout << std::endl; | |
71 | #endif | |
72 | } | |
73 | template <class T> | |
74 | void test_cbrt(T, const char* name) | |
75 | { | |
76 | // | |
77 | // The actual test data is rather verbose, so it's in a separate file. | |
78 | // | |
79 | // The contents are as follows, each row of data contains | |
80 | // three items, input value a, input value b and erf(a, b): | |
81 | // | |
82 | # include "cbrt_data.ipp" | |
83 | ||
84 | do_test_cbrt<T>(cbrt_data, name, "cbrt Function"); | |
85 | ||
86 | } | |
87 |