1 // (C) Copyright John Maddock 2009.
2 // Use, modification and distribution are subject to the
3 // Boost Software License, Version 1.0. (See accompanying file
4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //#define BOOST_MATH_INSTRUMENT
8 #include <boost/math/bindings/rr.hpp>
9 #include <boost/test/included/test_exec_monitor.hpp>
10 #include <boost/math/distributions/hypergeometric.hpp>
11 #include <boost/math/special_functions/trunc.hpp>
12 #include <boost/math/constants/constants.hpp>
13 #include <boost/math/tools/test.hpp>
14 #include <boost/lexical_cast.hpp>
15 #include <boost/random/uniform_int.hpp>
18 #include <boost/math/tools/test_data.hpp>
20 using namespace boost::math::tools;
22 std::tr1::mt19937 rnd;
24 struct hypergeometric_generator
33 boost::math::ntl::RR> operator()(boost::math::ntl::RR rN, boost::math::ntl::RR rr, boost::math::ntl::RR rn)
36 using namespace boost;
37 using namespace boost::math;
39 if((rr > rN) || (rr < rn))
40 throw std::domain_error("");
46 boost::uniform_int<> ui((std::max)(0, n + r - N), (std::min)(n, r));
49 hypergeometric_distribution<ntl::RR> d(r, n, N);
51 ntl::RR p = pdf(d, k);
52 if((p == 1) || (p == 0))
54 // trivial case, don't clutter up our table with it:
55 throw std::domain_error("");
57 ntl::RR c = cdf(d, k);
58 ntl::RR cc = cdf(complement(d, k));
60 std::cout << "N = " << N << " r = " << r << " n = " << n << " PDF = " << p << " CDF = " << c << " CCDF = " << cc << std::endl;
62 return boost::math::make_tuple(r, n, N, k, p, c, cc);
64 catch(const std::exception& e)
66 std::cout << e.what() << std::endl;
67 throw std::domain_error("");
72 int test_main(int argc, char*argv [])
74 boost::math::ntl::RR::SetPrecision(1000);
75 boost::math::ntl::RR::SetOutputPrecision(100);
78 parameter_info<boost::math::ntl::RR> arg1, arg2, arg3;
79 test_data<boost::math::ntl::RR> data;
81 std::cout << "Welcome.\n"
82 "This program will generate spot tests hypergeoemtric distribution:\n";
84 arg1 = make_power_param(boost::math::ntl::RR(0), 1, 21);
85 arg2 = make_power_param(boost::math::ntl::RR(0), 1, 21);
86 arg3 = make_power_param(boost::math::ntl::RR(0), 1, 21);
88 arg1.type |= dummy_param;
89 arg2.type |= dummy_param;
90 arg3.type |= dummy_param;
92 data.insert(hypergeometric_generator(), arg1, arg2, arg3);
94 line = "hypergeometric_dist_data2.ipp";
95 std::ofstream ofs(line.c_str());
96 write_code(ofs, data, "hypergeometric_dist_data2");