2
0
mirror of https://github.com/boostorg/math.git synced 2026-01-21 17:12:09 +00:00

updated to use argument promoted versions. PAB 27 Jun 2006

[SVN r3035]
This commit is contained in:
Paul A. Bristow
2006-06-27 09:48:29 +00:00
parent f6b8971322
commit dc28202d2d
2 changed files with 200 additions and 67 deletions

View File

@@ -9,7 +9,7 @@
// Basic sanity test for chisqr Cumulative Distribution Function.
// #define BOOST_MATH_THROW_ON_DOMAIN_ERROR
#define BOOST_MATH_THROW_ON_DOMAIN_ERROR
#ifdef _MSC_VER
# pragma warning(disable: 4127) // conditional expression is constant.
@@ -18,7 +18,7 @@
# pragma warning(disable: 4996) // 'std::char_traits<char>::copy' was declared deprecated.
#endif
#include <boost/math/special_functions/chisqr.hpp>
#include <boost/math/special_functions/chisqr.hpp> // for chisqr
using ::boost::math::chisqr;
#include <boost/math/concepts/real_concept.hpp> // for real_concept
using ::boost::math::concepts::real_concept;
@@ -26,6 +26,9 @@
#include <boost/test/included/test_exec_monitor.hpp> // for test_main
#include <boost/test/floating_point_comparison.hpp> // for BOOST_CHECK_CLOSE
#include <iostream>
using std::cout;
using std::endl;
#include <limits>
using std::numeric_limits;
@@ -103,30 +106,38 @@ void test_spots(FPT)
static_cast<FPT>(5.)), // chisqr
static_cast<FPT>(0.999999999999999999814527311613020069945), // probability.
tolerance);
/*
// Try bad degrees_of_freedom argument for chisqr.
BOOST_CHECK_CLOSE(
chisqr(
static_cast<FPT>(1), // degrees_of_freedom - as floating-point.
static_cast<FPT>(-2.)), // chisqr
static_cast<FPT>(0.999999999999999999), // probability.
tolerance);
// std::domain_error: Error in function float __cdecl boost::math::detail::chisqr_imp<float>(float,float): degrees of freedom argument is -1, but must be > 0 !
// Try bad argument for degrees_of_freedom.
//BOOST_CHECK_CLOSE(
// chisqr(
// static_cast<FPT>(-1), // degrees_of_freedom - as floating-point.
// static_cast<FPT>(-2.)), // chisqr
// static_cast<FPT>(0.999999999999999999), // probability.
//tolerance);
// Try bad argument for chisqr.
//BOOST_CHECK_CLOSE(
// chisqr(
// static_cast<FPT>(1), // degrees_of_freedom - as floating-point.
// static_cast<FPT>(-2.)), // chisqr
// static_cast<FPT>(0.999999999999999999), // probability.
//tolerance);
// Try bad chisqr argument for chisqr.
BOOST_CHECK_CLOSE(
chisqr(
static_cast<FPT>(1), // degrees_of_freedom - as floating-point.
static_cast<FPT>(-2.)), // chisqr
static_cast<FPT>(0.999999999999999999), // probability.
tolerance);
// std::domain_error: Error in function float __cdecl boost::math::detail::chisqr_imp<float>(float,float): chisqr argument is -2, but must be > 0 !
*/
} // template <class FPT>void test_spots(FPT)
int test_main(int, char* [])
{
// Basic sanity-check spot values.
#ifdef BOOST_MATH_THROW_ON_DOMAIN_ERROR
cout << "BOOST_MATH_THROW_ON_DOMAIN_ERROR" << " is defined to throw on domain error." << endl;
#else
cout << "BOOST_MATH_THROW_ON_DOMAIN_ERROR" << " is NOT defined, so NO throw on domain error." << endl;
#endif
// (Parameter value, arbitrarily zero, only communicates the floating point type).
test_spots(0.0F); // Test float.
test_spots(0.0); // Test double.
@@ -140,16 +151,49 @@ int test_main(int, char* [])
Output:
Compiling...
test_chisqr.cpp
Linking...
Embedding manifest...
Autorun "i:\boost-06-05-03-1300\libs\math\test\Math_test\debug\test_chisqr.exe"
Running 1 test case...
BOOST_MATH_THROW_ON_DOMAIN_ERROR is NOT defined so NO throw on domain error.
../../../../../../boost-sandbox/libs/math_functions/test/test_chisqr.cpp(116): error in "test_main_caller( argc, argv )": difference between chisqr( static_cast<FPT>(-1), static_cast<FPT>(-2.)){1.#QNAN} and static_cast<FPT>(0.999999999999999999){1} exceeds 0.0001%
../../../../../../boost-sandbox/libs/math_functions/test/test_chisqr.cpp(124): error in "test_main_caller( argc, argv )": difference between chisqr( static_cast<FPT>(1), static_cast<FPT>(-2.)){1.#QNAN} and static_cast<FPT>(0.999999999999999999){1} exceeds 0.0001%
../../../../../../boost-sandbox/libs/math_functions/test/test_chisqr.cpp(116): error in "test_main_caller( argc, argv )": difference between chisqr( static_cast<FPT>(-1), static_cast<FPT>(-2.)){1.#QNAN} and static_cast<FPT>(0.999999999999999999){1} exceeds 1e-013%
../../../../../../boost-sandbox/libs/math_functions/test/test_chisqr.cpp(124): error in "test_main_caller( argc, argv )": difference between chisqr( static_cast<FPT>(1), static_cast<FPT>(-2.)){1.#QNAN} and static_cast<FPT>(0.999999999999999999){1} exceeds 1e-013%
../../../../../../boost-sandbox/libs/math_functions/test/test_chisqr.cpp(116): error in "test_main_caller( argc, argv )": difference between chisqr( static_cast<FPT>(-1), static_cast<FPT>(-2.)){1.#QNAN} and static_cast<FPT>(0.999999999999999999){1} exceeds 1e-013%
../../../../../../boost-sandbox/libs/math_functions/test/test_chisqr.cpp(124): error in "test_main_caller( argc, argv )": difference between chisqr( static_cast<FPT>(1), static_cast<FPT>(-2.)){1.#QNAN} and static_cast<FPT>(0.999999999999999999){1} exceeds 1e-013%
unknown location(0): fatal error in "test_main_caller( argc, argv )": std::domain_error: Error in function class boost::math::concepts::real_concept __cdecl boost::math::detail::chisqr_imp<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept,class boost::math::concepts::real_concept): degrees of freedom argument is -1, but must be > 0 !
..\..\..\..\..\..\boost-sandbox\libs\math_functions\test\test_chisqr.cpp(116): last checkpoint
*** 7 failures detected in test suite "Test Program"
Project : error PRJ0019: A tool returned an error code from "Autorun "i:\boost-06-05-03-1300\libs\math\test\Math_test\debug\test_chisqr.exe""
*** No errors detected
Press any key to continue . . .
unknown location(0):
Compiling...
test_chisqr.cpp
Linking...
Embedding manifest...
Autorun "i:\boost-06-05-03-1300\libs\math\test\Math_test\debug\test_chisqr.exe"
Running 1 test case...
BOOST_MATH_THROW_ON_DOMAIN_ERROR is defined to throw on domain error.
unknown location(0): fatal error in "test_main_caller( argc, argv )": std::domain_error: Error in function float __cdecl boost::math::detail::chisqr_imp<float>(float,float): degrees of freedom argument is -1, but must be > 0 !
..\..\..\..\..\..\boost-sandbox\libs\math_functions\test\test_chisqr.cpp(116): last checkpoint
*** 1 failure detected in test suite "Test Program"
Project : error PRJ0019: A tool returned an error code from "Autorun "i:\boost-06-05-03-1300\libs\math\test\Math_test\debug\test_chisqr.exe""
fatal error in "test_main_caller( argc, argv )": std::domain_error: Error in function float __cdecl boost::math::chisqr<float,float>(float,float): degrees of freedom argument is -1, but must be > 0 !
Compiling...
test_chisqr.cpp
Linking...
Embedding manifest...
Autorun "i:\boost-06-05-03-1300\libs\math\test\Math_test\debug\test_chisqr.exe"
Running 1 test case...
BOOST_MATH_THROW_ON_DOMAIN_ERROR is defined to throw on domain error.
unknown location(0): fatal error in "test_main_caller( argc, argv )": std::domain_error: Error in function float __cdecl boost::math::detail::chisqr_imp<float>(float,float): chisqr argument is -2, but must be > 0 !
..\..\..\..\..\..\boost-sandbox\libs\math_functions\test\test_chisqr.cpp(116): last checkpoint
*** 1 failure detected in test suite "Test Program"
Project : error PRJ0019: A tool returned an error code from "Autorun "i:\boost-06-05-03-1300\libs\math\test\Math_test\debug\test_chisqr.exe""
..\..\..\..\..\..\boost-sandbox\libs\math_functions\test\test_chisqr.cpp(112): last checkpoint

View File

@@ -10,29 +10,52 @@
// http://en.wikipedia.org/wiki/Student%27s_t_distribution
// Basic sanity test for Student's t probability (quintile) (0. < p < 1).
// and Student's t probability Quintile (0. < p < 1).
#define BOOST_MATH_THROW_ON_DOMAIN_ERROR
#ifdef _MSC_VER
# pragma warning(disable: 4127) // conditional expression is constant.
# pragma warning(disable: 4100) // unreferenced formal parameter.
# pragma warning(disable: 4512) // assignment operator could not be generated.
# if !(defined _SCL_SECURE_NO_DEPRECATE) || (_SCL_SECURE_NO_DEPRECATE == 0)
# pragma warning(disable: 4996) // 'std::char_traits<char>::copy' was declared deprecated.
// #define _SCL_SECURE_NO_DEPRECATE = 1 // avoid C4996 warning.
# endif
//# pragma warning(disable: 4244) // conversion from 'double' to 'float', possible loss of data.
#endif
#include <boost/test/included/test_exec_monitor.hpp> // Boost.Test
#include <boost/test/floating_point_comparison.hpp>
#include <boost/math/special_functions/students_t.hpp>
using boost::math::students_t_inv;
using boost::math::students_t;
#include <boost/math/concepts/real_concept.hpp> // for real_concept
#include <boost/test/included/test_exec_monitor.hpp> // Test
#include <boost/test/floating_point_comparison.hpp>
#include <iostream>
using std::cout;
using std::endl;
using std::setprecision;
#include <limits>
using std::numeric_limits;
template <class FPT>
void test_spots(FPT)
{
//
// Basic sanity checks, tolerance is 6 decimal places
// expressed as a percentage (so -2) for BOOST_CHECK_CLOSE,
// One check per domain of the implementation:
// Basic sanity checks, tolerance is about numeric_limits<FPT>::digits10 decimal places,
// expressed as a percentage (so -2) for BOOST_CHECK_CLOSE,
FPT tolerance = static_cast<FPT>(std::pow(10., -(6-2))); // 1e-6 (as %)
// This test only passes at 1e-5 because probability value is less accurate,
// a digit in 6th decimla place, although calculated using
int decdigits = numeric_limits<FPT>::digits10; // guaranteed for type FPT, eg 6 for float, 15 for double,
decdigits -= 6; // Perhaps allow some decimal digits margin of numerical error.
FPT tolerance = static_cast<FPT>(std::pow(10., -(decdigits-2))); // (-2 so as %)
tolerance *= 1; // Allow some bit(s) small margin (2 means + or - 1 bit) of numerical error.
cout << "tolerance = " << tolerance << " %" << endl;
// FPT tolerance = static_cast<FPT>(std::pow(10., -(6-2))); // 1e-6 (as %)
// Some tests only pass at 1e-5 because probability value is less accurate,
// a digit in 6th decimal place, although calculated using
// a t-distribution generator (calimed 6 decimal digits) at
// http://faculty.vassar.edu/lowry/VassarStats.html
// http://faculty.vassar.edu/lowry/tsamp.html
@@ -56,95 +79,173 @@ void test_spots(FPT)
// gives accurate t of -3.1824463052837 and 3 degrees of freedom.
// Values below are from this source, saved as tquantiles.xls.
// DF are across the columns, probabilities down the rows
// and the t- values are shown.
// and the t- values (quantiles) are shown.
// These values are probably accurate to nearly 64-bit double
// (perhaps 14 decimal digits).
BOOST_CHECK_CLOSE(
::boost::math::students_t(
static_cast<FPT>(2.), // df
static_cast<FPT>(2.), // degrees_of_freedom
static_cast<FPT>(-6.96455673428326)), // t
static_cast<FPT>(0.01), // probability.
tolerance);
BOOST_CHECK_CLOSE(
::boost::math::students_t(
static_cast<FPT>(5.), // df
static_cast<FPT>(5.), // degrees_of_freedom
static_cast<FPT>(-3.36492999890721)), // t
static_cast<FPT>(0.01), // probability.
tolerance);
BOOST_CHECK_CLOSE(
::boost::math::students_t(
static_cast<FPT>(1.), // df
static_cast<FPT>(1.), // degrees_of_freedom
static_cast<FPT>(-31830.988607907)), // t
static_cast<FPT>(0.00001), // probability.
tolerance);
BOOST_CHECK_CLOSE(
::boost::math::students_t(
static_cast<FPT>(25.), // df
static_cast<FPT>(25.), // degrees_of_freedom
static_cast<FPT>(-5.2410429995425)), // t
static_cast<FPT>(0.00001), // probability.
tolerance);
BOOST_CHECK_CLOSE(
::boost::math::students_t(
static_cast<FPT>(1.), // df
static_cast<FPT>(1.), // degrees_of_freedom
static_cast<FPT>(-63661.97723)), // t
static_cast<FPT>(0.000005), // probability.
tolerance);
BOOST_CHECK_CLOSE(
::boost::math::students_t(
static_cast<FPT>(5.), // df
static_cast<FPT>(5.), // degrees_of_freedom
static_cast<FPT>(-17.89686614)), // t
static_cast<FPT>(0.000005), // probability.
tolerance);
BOOST_CHECK_CLOSE(
::boost::math::students_t(
static_cast<FPT>(25.), // df
static_cast<FPT>(25.), // degrees_of_freedom
static_cast<FPT>(-5.510848412)), // t
static_cast<FPT>(0.000005), // probability.
tolerance);
BOOST_CHECK_CLOSE(
::boost::math::students_t(
static_cast<FPT>(10.), // df
static_cast<FPT>(10.), // degrees_of_freedom
static_cast<FPT>(-1.812461123)), // t
static_cast<FPT>(0.05), // probability.
tolerance);
BOOST_CHECK_CLOSE(
::boost::math::students_t(
static_cast<FPT>(10.), // df
static_cast<FPT>(10.), // degrees_of_freedom
static_cast<FPT>(1.812461123)), // t
static_cast<FPT>(0.95), // probability.
tolerance);
BOOST_CHECK_CLOSE(
::boost::math::students_t(
static_cast<FPT>(10.), // df
static_cast<FPT>(10.), // degrees_of_freedom
static_cast<FPT>(9.751995491)), // t
static_cast<FPT>(0.999999), // probability.
tolerance);
BOOST_CHECK_CLOSE(
::boost::math::students_t(
static_cast<FPT>(10.), // df - for ALL df!
static_cast<FPT>(10.), // degrees_of_freedom - for ALL degrees_of_freedom!
static_cast<FPT>(0.)), // t
static_cast<FPT>(0.5), // probability.
tolerance);
// Student's t Inverse function tests.
// Special cases
BOOST_CHECK_EQUAL(boost::math::students_t_inv(
static_cast<FPT>(1.), // degrees_of_freedom (ignored).
static_cast<FPT>(0)), // probability == half - special case.
-numeric_limits<FPT>::infinity()); // t == -infinity.
BOOST_CHECK_EQUAL(boost::math::students_t_inv(
static_cast<FPT>(1.), // degrees_of_freedom (ignored).
static_cast<FPT>(1)), // probability == half - special case.
+numeric_limits<FPT>::infinity()); // t == +infinity.
BOOST_CHECK_EQUAL(boost::math::students_t_inv(
static_cast<FPT>(1.), // degrees_of_freedom (ignored).
static_cast<FPT>(0.5)), // probability == half - special case.
static_cast<FPT>(0)); // t == zero.
BOOST_CHECK_CLOSE(boost::math::students_t_inv(
static_cast<FPT>(1.), // degrees_of_freedom (ignored).
static_cast<FPT>(0.5)), // probability == half - special case.
static_cast<FPT>(0), // t == zero.
tolerance);
BOOST_CHECK_CLOSE( // Tests of p middling.
::boost::math::students_t(
static_cast<FPT>(5.), // degrees_of_freedom
static_cast<FPT>(-0.559429644)), // t
static_cast<FPT>(0.3), // probability.
tolerance);
BOOST_CHECK_CLOSE(
::boost::math::students_t_inv(
static_cast<FPT>(5.), // degrees_of_freedom
static_cast<FPT>(0.3)), // probability.
static_cast<FPT>(-0.559429644), // t
tolerance);
BOOST_CHECK_CLOSE( // Tests of p high.
::boost::math::students_t(
static_cast<FPT>(5.), // degrees_of_freedom
static_cast<FPT>(1.475884049)), // t
static_cast<FPT>(0.9), // probability.
tolerance);
BOOST_CHECK_CLOSE(
::boost::math::students_t_inv(
static_cast<FPT>(5.), // degrees_of_freedom
static_cast<FPT>(0.9)), // probability.
static_cast<FPT>(1.475884049), // t
tolerance);
BOOST_CHECK_CLOSE( // Tests of p low.
::boost::math::students_t(
static_cast<FPT>(5.), // degrees_of_freedom
static_cast<FPT>(-1.475884049)), // t
static_cast<FPT>(0.1), // probability.
tolerance);
BOOST_CHECK_CLOSE(
::boost::math::students_t_inv(
static_cast<FPT>(5.), // degrees_of_freedom
static_cast<FPT>(0.1)), // probability.
static_cast<FPT>(-1.475884049), // t
tolerance);
BOOST_CHECK_CLOSE(
::boost::math::students_t(
static_cast<FPT>(2.), // degrees_of_freedom
static_cast<FPT>(-6.96455673428326)), // t
static_cast<FPT>(0.01), // probability.
tolerance);
BOOST_CHECK_CLOSE(
::boost::math::students_t_inv(
static_cast<FPT>(2.), // degrees_of_freedom
static_cast<FPT>(0.01)), // probability.
static_cast<FPT>(-6.96455673428326), // t
tolerance);
} // template <class FPT>void test_spots(FPT)
int test_main(int, char* [])
{
// Basic sanity-check spot values.
// (Parameter value, arbitrarily zero, only communicates the floating point type).
test_spots(0.0F); // Test float.
test_spots(0.0); // Test double.
test_spots(0.0L); // Test long double.
test_spots(boost::math::concepts::real_concept(0.)); // Test real concept.
test_spots(0.0F); // Test float. OK at decdigits = 0 tolerance = 0.0001 %
// test_spots(0.0); // Test double. OK at decdigits 7, tolerance = 1e07 %
//test_spots(0.0L); // Test long double.
//test_spots(boost::math::concepts::real_concept(0.)); // Test real concept.
return 0;
} // int test_main(int, char* [])
@@ -153,28 +254,16 @@ int test_main(int, char* [])
Output:
Compiling...
test_students_t.cpp
Linking...
Embedding manifest...
Autorun "i:\boost-06-05-03-1300\libs\math\test\Math_test\debug\test_students_t.exe"
Running 1 test case...
tolerance = 100 %
*** No errors detected
Press any key to continue . . .
1>------ Build started: Project: test_students_t, Configuration: Debug Win32 ------
1>Compiling...
1>test_students_t.cpp
1>MSVC++ compiler Version 8.0
1>Linking...
1>Embedding manifest...
1>Autorun "i:\boost-06-05-03-1300\libs\math\test\Math_test\debug\test_students_t.exe"
1>Running 1 test case...
1>*** No errors detected
1>Build Time 0:05
1>Build log was saved at "file://i:\boost-06-05-03-1300\libs\math\test\Math_test\test_students_t\Debug\BuildLog.htm"
1>test_students_t - 0 error(s), 0 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
*/