Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / math / test / test_nc_chi_squared.cpp
1 // test_nc_chi_squared.cpp
2
3 // Copyright John Maddock 2008.
4
5 // Use, modification and distribution are subject to the
6 // Boost Software License, Version 1.0.
7 // (See accompanying file LICENSE_1_0.txt
8 // or copy at http://www.boost.org/LICENSE_1_0.txt)
9
10 #include <pch.hpp>
11
12 #ifdef _MSC_VER
13 #pragma warning (disable:4127 4512)
14 #endif
15
16 #if !defined(TEST_FLOAT) && !defined(TEST_DOUBLE) && !defined(TEST_LDOUBLE) && !defined(TEST_REAL_CONCEPT)
17 #  define TEST_FLOAT
18 #  define TEST_DOUBLE
19 #  define TEST_LDOUBLE
20 #  define TEST_REAL_CONCEPT
21 #endif
22
23 #include <boost/math/tools/test.hpp>
24 #include <boost/math/concepts/real_concept.hpp> // for real_concept
25 #include <boost/math/distributions/non_central_chi_squared.hpp> // for chi_squared_distribution
26 #include <boost/math/special_functions/cbrt.hpp> // for chi_squared_distribution
27 #define BOOST_TEST_MAIN
28 #include <boost/test/unit_test.hpp> // for test_main
29 #include <boost/test/results_collector.hpp>
30 #include <boost/test/unit_test.hpp>
31 #include <boost/test/tools/floating_point_comparison.hpp> // for BOOST_CHECK_CLOSE
32 #include "test_out_of_range.hpp"
33
34 #include "functor.hpp"
35 #include "handle_test_result.hpp"
36 #include "test_nccs_hooks.hpp"
37 #include "table_type.hpp"
38 #include "test_nc_chi_squared.hpp"
39
40 #include <iostream>
41 #include <iomanip>
42 using std::cout;
43 using std::endl;
44 #include <limits>
45 using std::numeric_limits;
46
47 void expected_results()
48 {
49    //
50    // Define the max and mean errors expected for
51    // various compilers and platforms.
52    //
53    const char* largest_type;
54 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
55    if(boost::math::policies::digits<double, boost::math::policies::policy<> >() == boost::math::policies::digits<long double, boost::math::policies::policy<> >())
56    {
57       largest_type = "(long\\s+)?double|real_concept";
58    }
59    else
60    {
61       largest_type = "long double|real_concept";
62    }
63 #else
64    largest_type = "(long\\s+)?double|real_concept";
65 #endif
66
67    add_expected_result(
68       "[^|]*",                          // compiler
69       "[^|]*",                          // stdlib
70       "Mac OS",                          // platform
71       largest_type,                     // test type(s)
72       "[^|]*medium[^|]*",                   // test data group
73       "[^|]*", 550, 100);                  // test function
74    //
75    // Catch all cases come last:
76    //
77    add_expected_result(
78       "[^|]*",                          // compiler
79       "[^|]*",                          // stdlib
80       "[^|]*",                          // platform
81       largest_type,                     // test type(s)
82       "[^|]*medium[^|]*",                   // test data group
83       "[^|]*", 350, 100);                  // test function
84    add_expected_result(
85       "[^|]*",                          // compiler
86       "[^|]*",                          // stdlib
87       "[^|]*",                          // platform
88       largest_type,                     // test type(s)
89       "[^|]*large[^|]*",                   // test data group
90       "[^|]*", 17000, 3000);                  // test function
91
92    //
93    // Allow some long double error to creep into
94    // the double results:
95    //
96    add_expected_result(
97       "[^|]*",                          // compiler
98       "[^|]*",                          // stdlib
99       "[^|]*",                          // platform
100       "double",                         // test type(s)
101       "[^|]*",                   // test data group
102       "[^|]*", 3, 2);                  // test function
103
104    //
105    // Finish off by printing out the compiler/stdlib/platform names,
106    // we do this to make it easier to mark up expected error rates.
107    //
108    std::cout << "Tests run with " << BOOST_COMPILER << ", " 
109       << BOOST_STDLIB << ", " << BOOST_PLATFORM << std::endl;
110 }
111
112 BOOST_AUTO_TEST_CASE( test_main )
113 {
114    BOOST_MATH_CONTROL_FP;
115    // Basic sanity-check spot values.
116    expected_results();
117    // (Parameter value, arbitrarily zero, only communicates the floating point type).
118 #ifdef TEST_FLOAT
119    test_spots(0.0F); // Test float.
120 #endif
121 #ifdef TEST_DOUBLE
122    test_spots(0.0); // Test double.
123 #endif
124 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
125 #ifdef TEST_LDOUBLE
126    test_spots(0.0L); // Test long double.
127 #endif
128 #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
129 #ifdef TEST_REAL_CONCEPT
130    test_spots(boost::math::concepts::real_concept(0.)); // Test real concept.
131 #endif
132 #endif
133 #endif
134
135 #ifdef TEST_FLOAT
136    test_accuracy(0.0F, "float"); // Test float.
137 #endif
138 #ifdef TEST_DOUBLE
139    test_accuracy(0.0, "double"); // Test double.
140 #endif
141 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
142 #ifdef TEST_LDOUBLE
143    test_accuracy(0.0L, "long double"); // Test long double.
144 #endif
145 #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
146 #ifdef TEST_REAL_CONCEPT
147    test_accuracy(boost::math::concepts::real_concept(0.), "real_concept"); // Test real concept.
148 #endif
149 #endif
150 #endif
151    
152 } // BOOST_AUTO_TEST_CASE( test_main )
153
154