Imported Upstream version 1.57.0
[platform/upstream/boost.git] / libs / math / test / test_ibeta.cpp
1 //  (C) Copyright John Maddock 2006.
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)
5
6 #include <pch_light.hpp>
7 #include "test_ibeta.hpp"
8
9 #if !defined(TEST_FLOAT) && !defined(TEST_DOUBLE) && !defined(TEST_LDOUBLE) && !defined(TEST_REAL_CONCEPT)
10 #  define TEST_FLOAT
11 #  define TEST_DOUBLE
12 #  define TEST_LDOUBLE
13 #  define TEST_REAL_CONCEPT
14 #endif
15
16 //
17 // DESCRIPTION:
18 // ~~~~~~~~~~~~
19 //
20 // This file tests the incomplete beta functions beta, 
21 // betac, ibeta and ibetac.  There are two sets of tests, spot
22 // tests which compare our results with selected values computed
23 // using the online special function calculator at 
24 // functions.wolfram.com, while the bulk of the accuracy tests
25 // use values generated with NTL::RR at 1000-bit precision
26 // and our generic versions of these functions.
27 //
28 // Note that when this file is first run on a new platform many of
29 // these tests will fail: the default accuracy is 1 epsilon which
30 // is too tight for most platforms.  In this situation you will 
31 // need to cast a human eye over the error rates reported and make
32 // a judgement as to whether they are acceptable.  Either way please
33 // report the results to the Boost mailing list.  Acceptable rates of
34 // error are marked up below as a series of regular expressions that
35 // identify the compiler/stdlib/platform/data-type/test-data/test-function
36 // along with the maximum expected peek and RMS mean errors for that
37 // test.
38 //
39
40 void expected_results()
41 {
42    //
43    // Define the max and mean errors expected for
44    // various compilers and platforms.
45    //
46    const char* largest_type;
47 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
48    if(boost::math::policies::digits<double, boost::math::policies::policy<> >() == boost::math::policies::digits<long double, boost::math::policies::policy<> >())
49    {
50       largest_type = "(long\\s+)?double";
51    }
52    else
53    {
54       largest_type = "long double";
55    }
56 #else
57    largest_type = "(long\\s+)?double";
58 #endif
59    //
60    // Darwin: just one special case for real_concept:
61    //
62    add_expected_result(
63       "[^|]*",                          // compiler
64       "[^|]*",                          // stdlib
65       "Mac OS",                          // platform
66       "real_concept",                   // test type(s)
67       "(?i).*large.*",                      // test data group
68       ".*", 400000, 50000);             // test function
69
70    //
71    // Linux - results depend quite a bit on the
72    // processor type, and how good the std::pow
73    // function is for that processor.
74    //
75    add_expected_result(
76       "[^|]*",                          // compiler
77       "[^|]*",                          // stdlib
78       "linux",                          // platform
79       largest_type,                     // test type(s)
80       "(?i).*small.*",                  // test data group
81       ".*", 350, 100);  // test function
82    add_expected_result(
83       "[^|]*",                          // compiler
84       "[^|]*",                          // stdlib
85       "linux",                          // platform
86       largest_type,                     // test type(s)
87       "(?i).*medium.*",                     // test data group
88       ".*", 300, 80);  // test function
89    //
90    // Deficiencies in pow function really kick in here for
91    // large arguments.  Note also that the tests here get
92    // *very* extreme due to the increased exponent range
93    // of 80-bit long doubles.  Also effect Mac OS.
94    //
95    add_expected_result(
96       "[^|]*",                          // compiler
97       "[^|]*",                          // stdlib
98       "linux|Mac OS",                          // platform
99       largest_type,                     // test type(s)
100       "(?i).*large.*",                      // test data group
101       ".*", 200000, 10000);                 // test function
102 #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
103    add_expected_result(
104       "[^|]*",                          // compiler
105       "[^|]*",                          // stdlib
106       "linux|Mac OS|Sun.*",             // platform
107       "double",                     // test type(s)
108       "(?i).*large.*",                      // test data group
109       ".*", 40, 20);                 // test function
110 #endif
111    add_expected_result(
112       "[^|]*",                          // compiler
113       "[^|]*",                          // stdlib
114       "linux|Mac OS",                          // platform
115       "real_concept",                   // test type(s)
116       "(?i).*medium.*",                 // test data group
117       ".*", 350, 100);  // test function
118
119    //
120    // HP-UX:
121    //
122    // Large value tests include some with *very* extreme
123    // results, thanks to the large exponent range of
124    // 128-bit long doubles.
125    //
126    add_expected_result(
127       "[^|]*",                          // compiler
128       "[^|]*",                          // stdlib
129       "HP-UX",                          // platform
130       largest_type,                     // test type(s)
131       "(?i).*large.*",                      // test data group
132       ".*", 200000, 10000);                 // test function
133    //
134    // Tru64:
135    //
136    add_expected_result(
137       ".*Tru64.*",                          // compiler
138       ".*",                          // stdlib
139       ".*",                          // platform
140       largest_type,                     // test type(s)
141       "(?i).*large.*",                      // test data group
142       ".*", 130000, 10000);                 // test function
143    //
144    // Sun OS:
145    //
146    add_expected_result(
147       "[^|]*",                          // compiler
148       "[^|]*",                          // stdlib
149       "Sun.*",                          // platform
150       largest_type,                     // test type(s)
151       "(?i).*large.*",                      // test data group
152       ".*", 130000, 10000);                 // test function
153    add_expected_result(
154       "[^|]*",                          // compiler
155       "[^|]*",                          // stdlib
156       "Sun.*",                          // platform
157       largest_type,                     // test type(s)
158       "(?i).*small.*",                      // test data group
159       ".*", 130, 30);                 // test function
160    add_expected_result(
161       "[^|]*",                          // compiler
162       "[^|]*",                          // stdlib
163       "Sun.*",                          // platform
164       largest_type,                     // test type(s)
165       "(?i).*medium.*",                 // test data group
166       ".*", 200, 40);                   // test function
167    add_expected_result(
168       "[^|]*",                          // compiler
169       "[^|]*",                          // stdlib
170       "Sun.*",                          // platform
171       "real_concept",                   // test type(s)
172       "(?i).*medium.*",                 // test data group
173       ".*", 200, 40);                   // test function
174    add_expected_result(
175       "[^|]*",                          // compiler
176       "[^|]*",                          // stdlib
177       "Sun.*",                          // platform
178       "real_concept",                     // test type(s)
179       "(?i).*small.*",                      // test data group
180       ".*", 130, 30);                 // test function
181    //
182    // MinGW:
183    //
184    add_expected_result(
185       "GNU[^|]*",                          // compiler
186       "[^|]*",                          // stdlib
187       "Win32[^|]*",                          // platform
188       "real_concept",                   // test type(s)
189       "(?i).*medium.*",                     // test data group
190       ".*", 400, 50);  // test function
191    add_expected_result(
192       "GNU.*",                          // compiler
193       ".*",                          // stdlib
194       "Win32.*",                          // platform
195       "double",                     // test type(s)
196       "(?i).*large.*",                      // test data group
197       ".*", 20, 10);                 // test function
198    add_expected_result(
199       "GNU.*",                          // compiler
200       ".*",                          // stdlib
201       "Win32.*",                          // platform
202       largest_type,                     // test type(s)
203       "(?i).*large.*",                      // test data group
204       ".*", 200000, 10000);                 // test function
205
206 #ifdef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
207    //
208    // No long doubles:
209    //
210    add_expected_result(
211       "[^|]*",                          // compiler
212       "[^|]*",                          // stdlib
213       BOOST_PLATFORM,                          // platform
214       largest_type,                     // test type(s)
215       "(?i).*large.*",                      // test data group
216       ".*", 13000, 500);                 // test function
217 #endif
218    //
219    // Catch all cases come last:
220    //
221    add_expected_result(
222       "[^|]*",                          // compiler
223       "[^|]*",                          // stdlib
224       "[^|]*",                          // platform
225       largest_type,                     // test type(s)
226       "(?i).*small.*",                  // test data group
227       ".*", 90, 25);  // test function
228    add_expected_result(
229       "[^|]*",                          // compiler
230       "[^|]*",                          // stdlib
231       "[^|]*",                          // platform
232       largest_type,                     // test type(s)
233       "(?i).*medium.*",                     // test data group
234       ".*", 350, 50);  // test function
235    add_expected_result(
236       "[^|]*",                          // compiler
237       "[^|]*",                          // stdlib
238       "[^|]*",                          // platform
239       largest_type,                     // test type(s)
240       "(?i).*large.*",                      // test data group
241       ".*", 5000, 500);                 // test function
242
243    add_expected_result(
244       "[^|]*",                          // compiler
245       "[^|]*",                          // stdlib
246       "[^|]*",                          // platform
247       "real_concept",                   // test type(s)
248       "(?i).*small.*",                      // test data group
249       ".*", 90, 25);  // test function
250    add_expected_result(
251       "[^|]*",                          // compiler
252       "[^|]*",                          // stdlib
253       "[^|]*",                          // platform
254       "real_concept",                   // test type(s)
255       "(?i).*medium.*",                     // test data group
256       ".*", 200, 50);  // test function
257    add_expected_result(
258       "[^|]*",                          // compiler
259       "[^|]*",                          // stdlib
260       "[^|]*",                          // platform
261       "real_concept",                   // test type(s)
262       "(?i).*large.*",                      // test data group
263       ".*", 200000, 50000);             // test function
264
265    // catch all default is 2eps for all types:
266    add_expected_result(
267       "[^|]*",                          // compiler
268       "[^|]*",                          // stdlib
269       "[^|]*",                          // platform
270       "[^|]*",                          // test type(s)
271       "[^|]*",                          // test data group
272       ".*", 2, 2);                      // test function
273    //
274    // Finish off by printing out the compiler/stdlib/platform names,
275    // we do this to make it easier to mark up expected error rates.
276    //
277    std::cout << "Tests run with " << BOOST_COMPILER << ", " 
278       << BOOST_STDLIB << ", " << BOOST_PLATFORM << std::endl;
279 }
280
281 BOOST_AUTO_TEST_CASE( test_main )
282 {
283    expected_results();
284    BOOST_MATH_CONTROL_FP;
285 #ifdef TEST_GSL
286    gsl_set_error_handler_off();
287 #endif
288 #ifdef TEST_FLOAT
289    test_spots(0.0F);
290 #endif
291 #ifdef TEST_DOUBLE
292    test_spots(0.0);
293 #endif
294 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
295 #ifdef TEST_LDOUBLE
296    test_spots(0.0L);
297 #endif
298 #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
299 #ifdef TEST_REAL_CONCEPT
300    test_spots(boost::math::concepts::real_concept(0.1));
301 #endif
302 #endif
303 #endif
304
305 #ifdef TEST_FLOAT
306    test_beta(0.1F, "float");
307 #endif
308 #ifdef TEST_DOUBLE
309    test_beta(0.1, "double");
310 #endif
311 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
312 #ifdef TEST_LDOUBLE
313    test_beta(0.1L, "long double");
314 #endif
315 #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
316 #ifdef TEST_REAL_CONCEPT
317    test_beta(boost::math::concepts::real_concept(0.1), "real_concept");
318 #endif
319 #endif
320 #else
321    std::cout << "<note>The long double tests have been disabled on this platform "
322       "either because the long double overloads of the usual math functions are "
323       "not available at all, or because they are too inaccurate for these tests "
324       "to pass.</note>" << std::cout;
325 #endif
326    
327 }
328
329
330
331
332