|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r79795 - trunk/libs/math/test
From: pbristow_at_[hidden]
Date: 2012-07-29 05:45:43
Author: pbristow
Date: 2012-07-29 05:45:42 EDT (Sun, 29 Jul 2012)
New Revision: 79795
URL: http://svn.boost.org/trac/boost/changeset/79795
Log:
Further revision of students t tests, making inline to hope to avoid gcc compile problem.
Text files modified:
trunk/libs/math/test/test_students_t.cpp | 205 +++++++++++++++------------------------
1 files changed, 79 insertions(+), 126 deletions(-)
Modified: trunk/libs/math/test/test_students_t.cpp
==============================================================================
--- trunk/libs/math/test/test_students_t.cpp (original)
+++ trunk/libs/math/test/test_students_t.cpp 2012-07-29 05:45:42 EDT (Sun, 29 Jul 2012)
@@ -476,46 +476,6 @@
RealType inf = std::numeric_limits<RealType>::infinity();
RealType nan = std::numeric_limits<RealType>::quiet_NaN();
-//using boost::math::policies::policy;
-//// Types of error whose action can be altered by policies:.
-//using boost::math::policies::evaluation_error;
-//using boost::math::policies::domain_error;
-//using boost::math::policies::overflow_error;
-//using boost::math::policies::underflow_error;
-//using boost::math::policies::domain_error;
-//using boost::math::policies::pole_error;
-//
-//// Actions on error (in enum error_policy_type):
-//using boost::math::policies::errno_on_error;
-//using boost::math::policies::ignore_error;
-//using boost::math::policies::throw_on_error;
-//using boost::math::policies::denorm_error;
-//using boost::math::policies::pole_error;
-//using boost::math::policies::user_error;
-//
-//typedef policy<
-//domain_error<ignore_error>,
-//overflow_error<ignore_error>,
-//underflow_error<ignore_error>,
-//denorm_error<ignore_error>,
-//pole_error<ignore_error>,
-//evaluation_error<ignore_error>
-// > my_ignore_policy;
-//
-//// Define a new distribution with a custom policy to ignore_error
-//// (& thus perhaps return infinity or NaN for some arguments):
-//
-//using boost::math::students_t_distribution;
-//typedef students_t_distribution<long double, my_ignore_policy> c_students_t;
-//// typedef students_t_distribution<double, my_ignore_policy> c_students_t;
-//
-// cout << "mean(c_students_t(nan)) = " << mean(c_students_t(nan)) << endl;
-// cout << "variance(c_students_t(nan)) = " << variance(c_students_t(nan)) << endl;
-// cout << "skewness(c_students_t(nan)) = " << skewness(c_students_t(nan)) << endl;
-// cout << "kurtosis(c_students_t(nan)) = " << kurtosis(c_students_t(nan)) << endl;
-//
-//// All return zero (not NaN) for realconcept!!!
-
BOOST_CHECK_THROW(quantile(dist, -1), std::domain_error);
BOOST_CHECK_THROW(quantile(dist, 2), std::domain_error);
BOOST_CHECK_THROW(pdf(students_t_distribution<RealType>(0), 0), std::domain_error);
@@ -537,16 +497,7 @@
BOOST_CHECK_THROW(variance(students_t_distribution<RealType>(1)), std::domain_error);
BOOST_CHECK_THROW(variance(students_t_distribution<RealType>(static_cast<RealType>(1.99999L))), std::overflow_error);
BOOST_CHECK_THROW(variance(students_t_distribution<RealType>(static_cast<RealType>(1.99999L))), std::overflow_error);
- BOOST_CHECK_THROW(variance(students_t_distribution<RealType>(2)), std::overflow_error); // df == k
-
-
- //BOOST_CHECK_EQUAL(variance(c_students_t(static_cast<RealType>(2))), inf); //
- //BOOST_CHECK(boost::math::isnan(variance(c_students_t(nan))));
- //BOOST_CHECK(boost::math::isnan(variance(c_students_t(inf))));
- //BOOST_CHECK(boost::math::isnan(variance(c_students_t(-1))));
- //BOOST_CHECK(boost::math::isnan(variance(c_students_t(0))));
- //BOOST_CHECK(boost::math::isnan(variance(c_students_t(1))));
-
+ BOOST_CHECK_THROW(variance(students_t_distribution<RealType>(2)), std::overflow_error); // df ==
BOOST_CHECK_EQUAL(variance(students_t_distribution<RealType>(2.5)), 5); // OK.
BOOST_CHECK_EQUAL(variance(students_t_distribution<RealType>(3)), 3); // OK.
@@ -581,30 +532,10 @@
BOOST_CHECK_THROW(kurtosis(students_t_distribution<RealType>(4)), std::overflow_error); // df == k
BOOST_CHECK_EQUAL(kurtosis(students_t_distribution<RealType>(5)), 9); // OK.
- check_ignore_error_returns<RealType>(0); // Use a new distribution c_students_t with a custom policy to ignore_errors,
+ // Use a new distribution ignore_error_students_t with a custom policy to ignore all errors,
// and check returned values are as expected.
- check_out_of_range<students_t_distribution<RealType> >(1);
-} // template <class RealType>void test_spots(RealType)
-
-template<class RealType>
-void check_ignore_error_returns(RealType)
-{ // Define a new distribution c_students_t with a custom policy to ignore_errors
- // & thus be able to check that return infinity or NaN for some arguments:
-
- // Currently these tests would fail with real_concept which returns zero instead of NaN.
- if(!std::numeric_limits<RealType>::has_infinity)
- {
- return;
- }
- if(!std::numeric_limits<RealType>::has_quiet_NaN)
- {
- return;
- }
-
- using namespace boost::math;
-
- using boost::math::policies::policy;
+ using boost::math::policies::policy;
// Types of error whose action can be altered by policies:.
using boost::math::policies::evaluation_error;
using boost::math::policies::domain_error;
@@ -622,62 +553,85 @@
using boost::math::policies::user_error;
typedef policy<
- domain_error<ignore_error>,
- overflow_error<ignore_error>,
- underflow_error<ignore_error>,
- denorm_error<ignore_error>,
- pole_error<ignore_error>,
- evaluation_error<ignore_error>
+ domain_error<ignore_error>,
+ overflow_error<ignore_error>,
+ underflow_error<ignore_error>,
+ denorm_error<ignore_error>,
+ pole_error<ignore_error>,
+ evaluation_error<ignore_error>
> my_ignore_policy;
- long double inf = std::numeric_limits<long double>::infinity();
- long double nan = std::numeric_limits<long double>::quiet_NaN();
-
- using boost::math::students_t_distribution;
+ typedef students_t_distribution<RealType, my_ignore_policy> ignore_error_students_t;
- typedef students_t_distribution<long double, my_ignore_policy> c_students_t;
- // typedef students_t_distribution<double, my_ignore_policy> c_students_t;
+ // Only test NaN and infinity if type has these features (realconcept returns zero).
+ // Integers are always converted to RealType, others requires static cast.
- //cout << "mean(c_students_t(nan)) = " << mean(c_students_t(nan)) << endl;
- //cout << "variance(c_students_t(nan)) = " << variance(c_students_t(nan)) << endl;
- //cout << "skewness(c_students_t(nan)) = " << skewness(c_students_t(nan)) << endl;
- //cout << "kurtosis(c_students_t(nan)) = " << kurtosis(c_students_t(nan)) << endl;
-
- // Bad arguments - check on return from ignoring errors.
- BOOST_CHECK((boost::math::isnan)(mean(c_students_t(nan))));
- BOOST_CHECK(boost::math::isnan(mean(c_students_t(inf))));
- BOOST_CHECK(boost::math::isnan(mean(c_students_t(-1))));
- BOOST_CHECK(boost::math::isnan(mean(c_students_t(0))));
- BOOST_CHECK(boost::math::isnan(mean(c_students_t(1))));
-
- BOOST_CHECK(boost::math::isnan(variance(c_students_t(nan))));
- BOOST_CHECK(boost::math::isnan(variance(c_students_t(inf))));
- BOOST_CHECK(boost::math::isnan(variance(c_students_t(-1))));
- BOOST_CHECK(boost::math::isnan(variance(c_students_t(0))));
- BOOST_CHECK(boost::math::isnan(variance(c_students_t(1))));
- BOOST_CHECK(boost::math::isinf(variance(c_students_t(1.7L))));
- BOOST_CHECK(boost::math::isinf(variance(c_students_t(2))));
- BOOST_CHECK(boost::math::isfinite(variance(c_students_t(2.0001L))));
-
- BOOST_CHECK(boost::math::isnan(skewness(c_students_t(nan))));
- BOOST_CHECK(boost::math::isnan(skewness(c_students_t(inf))));
- BOOST_CHECK(boost::math::isnan(skewness(c_students_t(-1))));
- BOOST_CHECK(boost::math::isnan(skewness(c_students_t(0))));
- BOOST_CHECK(boost::math::isnan(skewness(c_students_t(1))));
- BOOST_CHECK(boost::math::isnan(skewness(c_students_t(2))));
- BOOST_CHECK(boost::math::isnan(skewness(c_students_t(3))));
-
- BOOST_CHECK(boost::math::isnan(kurtosis(c_students_t(nan))));
- BOOST_CHECK(boost::math::isnan(kurtosis(c_students_t(inf))));
- BOOST_CHECK(boost::math::isnan(kurtosis(c_students_t(-1))));
- BOOST_CHECK(boost::math::isnan(kurtosis(c_students_t(0))));
- BOOST_CHECK(boost::math::isnan(kurtosis(c_students_t(1))));
- BOOST_CHECK(boost::math::isnan(kurtosis(c_students_t(2))));
- BOOST_CHECK(boost::math::isinf(kurtosis(c_students_t(2.0001L))));
- BOOST_CHECK(boost::math::isinf(kurtosis(c_students_t(3))));
- BOOST_CHECK(boost::math::isinf(kurtosis(c_students_t(4))));
- BOOST_CHECK(boost::math::isfinite(kurtosis(c_students_t(4.0001L))));
-} // check_ignore_error_returns()
+ // Mean
+ if(std::numeric_limits<RealType>::has_quiet_NaN)
+ {
+ BOOST_CHECK(boost::math::isnan(mean(ignore_error_students_t(-1))));
+ BOOST_CHECK(boost::math::isnan(mean(ignore_error_students_t(0))));
+ BOOST_CHECK(boost::math::isnan(mean(ignore_error_students_t(1))));
+ BOOST_CHECK(boost::math::isfinite(mean(ignore_error_students_t(1 + std::numeric_limits<RealType>::epsilon()))));
+
+ // Variance
+ BOOST_CHECK(boost::math::isnan(variance(ignore_error_students_t(std::numeric_limits<RealType>::quiet_NaN()))));
+
+ if(!std::numeric_limits<RealType>::has_infinity)
+ {
+ BOOST_CHECK(boost::math::isnan(variance(ignore_error_students_t(std::numeric_limits<RealType>::infinity()))));
+ }
+
+ BOOST_CHECK(boost::math::isnan(variance(ignore_error_students_t(-1))));
+ BOOST_CHECK(boost::math::isnan(variance(ignore_error_students_t(0))));
+ BOOST_CHECK(boost::math::isnan(variance(ignore_error_students_t(1))));
+ }
+ if(std::numeric_limits<RealType>::has_infinity)
+ {
+ BOOST_CHECK(boost::math::isinf(variance(ignore_error_students_t(static_cast<RealType>(1.7L)))));
+ BOOST_CHECK(boost::math::isinf(variance(ignore_error_students_t(2))));
+ }
+ BOOST_CHECK(boost::math::isfinite(variance(ignore_error_students_t(2 + 2 * std::numeric_limits<RealType>::epsilon()))));
+ BOOST_CHECK(boost::math::isfinite(variance(ignore_error_students_t(static_cast<RealType>(2.0001L)))));
+
+ // Skewness
+ if(std::numeric_limits<RealType>::has_quiet_NaN)
+ {
+ BOOST_CHECK(boost::math::isnan(skewness(ignore_error_students_t(std::numeric_limits<RealType>::quiet_NaN()))));
+ if(!std::numeric_limits<RealType>::has_infinity)
+ {
+ BOOST_CHECK(boost::math::isnan(skewness(ignore_error_students_t(std::numeric_limits<RealType>::infinity()))));
+ }
+ BOOST_CHECK(boost::math::isnan(skewness(ignore_error_students_t(-1))));
+ BOOST_CHECK(boost::math::isnan(skewness(ignore_error_students_t(0))));
+ BOOST_CHECK(boost::math::isnan(skewness(ignore_error_students_t(1))));
+ BOOST_CHECK(boost::math::isnan(skewness(ignore_error_students_t(2))));
+ BOOST_CHECK(boost::math::isnan(skewness(ignore_error_students_t(3))));
+ BOOST_CHECK(boost::math::isfinite(skewness(ignore_error_students_t(3 + 3 * std::numeric_limits<RealType>::epsilon()))));
+
+ // Kurtosis (and assume this tests kurtosis excess too?).
+ BOOST_CHECK(boost::math::isnan(kurtosis(ignore_error_students_t(std::numeric_limits<RealType>::quiet_NaN()))));
+ if(std::numeric_limits<RealType>::has_infinity)
+ {
+ BOOST_CHECK(boost::math::isnan(kurtosis(ignore_error_students_t(std::numeric_limits<RealType>::infinity()))));
+ BOOST_CHECK(boost::math::isnan(kurtosis(ignore_error_students_t(-1))));
+ BOOST_CHECK(boost::math::isnan(kurtosis(ignore_error_students_t(0))));
+ BOOST_CHECK(boost::math::isnan(kurtosis(ignore_error_students_t(1))));
+ BOOST_CHECK(boost::math::isnan(kurtosis(ignore_error_students_t(2))));
+ }
+ }
+ BOOST_CHECK(boost::math::isfinite(variance(ignore_error_students_t(2 + 2 * std::numeric_limits<RealType>::epsilon()))));
+ if(std::numeric_limits<RealType>::has_infinity)
+ {
+ BOOST_CHECK(boost::math::isinf(kurtosis(ignore_error_students_t(static_cast<RealType>(2.0001L)))));
+ BOOST_CHECK(boost::math::isinf(kurtosis(ignore_error_students_t(3))));
+ BOOST_CHECK(boost::math::isinf(kurtosis(ignore_error_students_t(4))));
+ }
+ BOOST_CHECK(boost::math::isfinite(variance(ignore_error_students_t(4 + 4 * std::numeric_limits<RealType>::epsilon()))));
+ BOOST_CHECK(boost::math::isfinite(kurtosis(ignore_error_students_t(static_cast<RealType>(4.0001L)))));
+
+ check_out_of_range<students_t_distribution<RealType> >(1);
+} // template <class RealType>void test_spots(RealType)
int test_main(int, char* [])
{
@@ -687,8 +641,7 @@
students_t_distribution<> myst2(2); // Using default RealType double.
//students_t_distribution<double> myst3(2); // Using explicit RealType double.
-
- // Basic sanity-check spot values.
+ // Basic sanity-check spot values.
// (Parameter value, arbitrarily zero, only communicates the floating point type).
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 %
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk