]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/test/test_dist_overloads.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / math / test / test_dist_overloads.cpp
1 // Copyright John Maddock 2006.
2 // Copyright Paul A. Bristow 2007.
3
4 // Use, modification and distribution are subject to the
5 // Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE_1_0.txt
7 // or copy at http://www.boost.org/LICENSE_1_0.txt)
8
9 // test_dist_overloads.cpp
10
11 #include <boost/math/concepts/real_concept.hpp> // for real_concept
12 #include <boost/math/distributions/normal.hpp>
13 using boost::math::normal_distribution;
14
15 #define BOOST_TEST_MAIN
16 #include <boost/test/unit_test.hpp> // Boost.Test
17 #include <boost/test/tools/floating_point_comparison.hpp>
18
19 #include <iostream>
20 using std::cout;
21 using std::endl;
22 using std::setprecision;
23
24 template <class RealType>
25 void test_spots(RealType)
26 {
27 // Basic sanity checks,
28 // 2 eps as a percentage:
29 RealType tolerance = boost::math::tools::epsilon<RealType>() * 2 * 100;
30
31 cout << "Tolerance for type " << typeid(RealType).name() << " is " << tolerance << " %" << endl;
32
33 for(int i = -4; i <= 4; ++i)
34 {
35 BOOST_CHECK_CLOSE(
36 ::boost::math::cdf(normal_distribution<RealType>(), i),
37 ::boost::math::cdf(normal_distribution<RealType>(), static_cast<RealType>(i)),
38 tolerance);
39 BOOST_CHECK_CLOSE(
40 ::boost::math::pdf(normal_distribution<RealType>(), i),
41 ::boost::math::pdf(normal_distribution<RealType>(), static_cast<RealType>(i)),
42 tolerance);
43 BOOST_CHECK_CLOSE(
44 ::boost::math::cdf(complement(normal_distribution<RealType>(), i)),
45 ::boost::math::cdf(complement(normal_distribution<RealType>(), static_cast<RealType>(i))),
46 tolerance);
47 BOOST_CHECK_CLOSE(
48 ::boost::math::hazard(normal_distribution<RealType>(), i),
49 ::boost::math::hazard(normal_distribution<RealType>(), static_cast<RealType>(i)),
50 tolerance);
51 BOOST_CHECK_CLOSE(
52 ::boost::math::chf(normal_distribution<RealType>(), i),
53 ::boost::math::chf(normal_distribution<RealType>(), static_cast<RealType>(i)),
54 tolerance);
55 }
56 for(float f = 0.01f; f < 1; f += 0.01f)
57 {
58 BOOST_CHECK_CLOSE(
59 ::boost::math::quantile(normal_distribution<RealType>(), f),
60 ::boost::math::quantile(normal_distribution<RealType>(), static_cast<RealType>(f)),
61 tolerance);
62 BOOST_CHECK_CLOSE(
63 ::boost::math::quantile(complement(normal_distribution<RealType>(), f)),
64 ::boost::math::quantile(complement(normal_distribution<RealType>(), static_cast<RealType>(f))),
65 tolerance);
66 }
67 } // template <class RealType>void test_spots(RealType)
68
69 BOOST_AUTO_TEST_CASE( test_main )
70 {
71 // Basic sanity-check spot values.
72 // (Parameter value, arbitrarily zero, only communicates the floating point type).
73 test_spots(0.0F); // Test float. OK at decdigits = 0 tolerance = 0.0001 %
74 test_spots(0.0); // Test double. OK at decdigits 7, tolerance = 1e07 %
75 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
76 test_spots(0.0L); // Test long double.
77 #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
78 test_spots(boost::math::concepts::real_concept(0.)); // Test real concept.
79 #endif
80 #else
81 std::cout << "<note>The long double tests have been disabled on this platform "
82 "either because the long double overloads of the usual math functions are "
83 "not available at all, or because they are too inaccurate for these tests "
84 "to pass.</note>" << std::endl;
85 #endif
86
87 } // BOOST_AUTO_TEST_CASE( test_main )
88
89 /*
90
91 Output:
92
93 Running 1 test case...
94 Tolerance for type float is 2.38419e-005 %
95 Tolerance for type double is 4.44089e-014 %
96 Tolerance for type long double is 4.44089e-014 %
97 Tolerance for type class boost::math::concepts::real_concept is 4.44089e-014 %
98 *** No errors detected
99
100 */
101