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)
7 #include <boost/math/concepts/real_concept.hpp>
8 #define BOOST_TEST_MAIN
9 #include <boost/test/unit_test.hpp>
10 #include <boost/test/tools/floating_point_comparison.hpp>
11 #include <boost/math/special_functions/binomial.hpp>
12 #include <boost/math/special_functions/trunc.hpp>
13 #include <boost/math/tools/test.hpp>
14 #include "functor.hpp"
15 #include <boost/array.hpp>
19 #include "handle_test_result.hpp"
20 #include "table_type.hpp"
23 #define SC_(x) static_cast<typename table_type<T>::type>(BOOST_JOIN(x, L))
27 T binomial_wrapper(T n, T k)
29 #ifdef BINOMIAL_FUNCTION_TO_TEST
30 return BINOMIAL_FUNCTION_TO_TEST(
31 boost::math::itrunc(n),
32 boost::math::itrunc(k));
34 return boost::math::binomial_coefficient<T>(
35 boost::math::itrunc(n),
36 boost::math::itrunc(k));
41 void test_binomial(T, const char* type_name)
43 #if !(defined(ERROR_REPORTING_MODE) && !defined(BINOMIAL_FUNCTION_TO_TEST))
46 typedef T (*func_t)(T, T);
47 #if defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
48 func_t f = &binomial_wrapper<T>;
50 func_t f = &binomial_wrapper;
53 #include "binomial_data.ipp"
55 boost::math::tools::test_result<T> result = boost::math::tools::test_hetero<T>(
57 bind_func<T>(f, 0, 1),
58 extract_result<T>(2));
60 std::cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"
61 "Test results for small arguments and type " << type_name << std::endl << std::endl;
62 std::cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
63 handle_test_result(result, binomial_data[result.worst()], result.worst(), type_name, "binomial_coefficient", "Binomials: small arguments");
64 std::cout << std::endl;
66 #include "binomial_large_data.ipp"
68 result = boost::math::tools::test_hetero<T>(
70 bind_func<T>(f, 0, 1),
71 extract_result<T>(2));
73 std::cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"
74 "Test results for large arguments and type " << type_name << std::endl << std::endl;
75 std::cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
76 handle_test_result(result, binomial_large_data[result.worst()], result.worst(), type_name, "binomial_coefficient", "Binomials: large arguments");
77 std::cout << std::endl;