Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / math / test / test_binomial_coeff.hpp
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>
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>
16 #include <iostream>
17 #include <iomanip>
18
19 #include "handle_test_result.hpp"
20 #include "table_type.hpp"
21
22 #ifndef SC_
23 #define SC_(x) static_cast<typename table_type<T>::type>(BOOST_JOIN(x, L))
24 #endif
25
26 template <class T>
27 T binomial_wrapper(T n, T k)
28 {
29 #ifdef BINOMIAL_FUNCTION_TO_TEST
30    return BINOMIAL_FUNCTION_TO_TEST(
31       boost::math::itrunc(n),
32       boost::math::itrunc(k));
33 #else
34    return boost::math::binomial_coefficient<T>(
35       boost::math::itrunc(n),
36       boost::math::itrunc(k));
37 #endif
38 }
39
40 template <class T>
41 void test_binomial(T, const char* type_name)
42 {
43 #if !(defined(ERROR_REPORTING_MODE) && !defined(BINOMIAL_FUNCTION_TO_TEST))
44    using namespace std;
45
46    typedef T (*func_t)(T, T);
47 #if defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
48    func_t f = &binomial_wrapper<T>;
49 #else
50    func_t f = &binomial_wrapper;
51 #endif
52
53 #include "binomial_data.ipp"
54
55    boost::math::tools::test_result<T> result = boost::math::tools::test_hetero<T>(
56       binomial_data, 
57       bind_func<T>(f, 0, 1), 
58       extract_result<T>(2));
59
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;
65
66 #include "binomial_large_data.ipp"
67
68    result = boost::math::tools::test_hetero<T>(
69       binomial_large_data, 
70       bind_func<T>(f, 0, 1), 
71       extract_result<T>(2));
72
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;
78 #endif
79 }
80