Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r79837 - trunk/libs/math/test
From: pbristow_at_[hidden]
Date: 2012-08-01 13:12:01


Author: pbristow
Date: 2012-08-01 13:12:00 EDT (Wed, 01 Aug 2012)
New Revision: 79837
URL: http://svn.boost.org/trac/boost/changeset/79837

Log:
Back to plan A! not defined for v <= k - no infinity from moments.
(TODO use normal for df = infinity?)
Text files modified:
   trunk/libs/math/test/test_students_t.cpp | 95 ++++++++++++++++++---------------------
   1 files changed, 43 insertions(+), 52 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-08-01 13:12:00 EDT (Wed, 01 Aug 2012)
@@ -472,7 +472,7 @@
          9);
 
 
- // Checks added for Trac #7717 report by Thomas Mang
+ // Checks added for Trac #7717 report by Thomas Mang.
     RealType inf = std::numeric_limits<RealType>::infinity();
     RealType nan = std::numeric_limits<RealType>::quiet_NaN();
 
@@ -480,7 +480,6 @@
     BOOST_CHECK_THROW(quantile(dist, 2), std::domain_error);
     BOOST_CHECK_THROW(pdf(students_t_distribution<RealType>(0), 0), std::domain_error);
     BOOST_CHECK_THROW(pdf(students_t_distribution<RealType>(-1), 0), std::domain_error);
-
   
     // Check on df for mean (moment k = 1)
     BOOST_CHECK_THROW(mean(students_t_distribution<RealType>(-1)), std::domain_error);
@@ -495,9 +494,9 @@
     BOOST_CHECK_THROW(variance(students_t_distribution<RealType>(-1)), std::domain_error);
     BOOST_CHECK_THROW(variance(students_t_distribution<RealType>(0)), std::domain_error);
     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 ==
+ BOOST_CHECK_THROW(variance(students_t_distribution<RealType>(static_cast<RealType>(1.99999L))), std::domain_error);
+ BOOST_CHECK_THROW(variance(students_t_distribution<RealType>(static_cast<RealType>(1.99999L))), std::domain_error);
+ BOOST_CHECK_THROW(variance(students_t_distribution<RealType>(2)), std::domain_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.
 
@@ -517,9 +516,9 @@
     BOOST_CHECK_THROW(kurtosis_excess(students_t_distribution<RealType>(1)), std::domain_error);
     BOOST_CHECK_THROW(kurtosis_excess(students_t_distribution<RealType>(1.5L)), std::domain_error);
     BOOST_CHECK_THROW(kurtosis_excess(students_t_distribution<RealType>(2)), std::domain_error);
- BOOST_CHECK_THROW(kurtosis(students_t_distribution<RealType>(static_cast<RealType>(2.1))), std::overflow_error);
- BOOST_CHECK_THROW(kurtosis_excess(students_t_distribution<RealType>(3)), std::overflow_error);
- BOOST_CHECK_THROW(kurtosis_excess(students_t_distribution<RealType>(4)), std::overflow_error); // df == k
+ BOOST_CHECK_THROW(kurtosis(students_t_distribution<RealType>(static_cast<RealType>(2.1))), std::domain_error);
+ BOOST_CHECK_THROW(kurtosis_excess(students_t_distribution<RealType>(3)), std::domain_error);
+ BOOST_CHECK_THROW(kurtosis_excess(students_t_distribution<RealType>(4)), std::domain_error); // df == k
     BOOST_CHECK_EQUAL(kurtosis_excess(students_t_distribution<RealType>(5)), 6); // OK.
 
     // Check on df for kurtosis (moment 4)
@@ -527,9 +526,9 @@
     BOOST_CHECK_THROW(kurtosis(students_t_distribution<RealType>(0)), std::domain_error);
     BOOST_CHECK_THROW(kurtosis(students_t_distribution<RealType>(1)), std::domain_error);
     BOOST_CHECK_THROW(kurtosis(students_t_distribution<RealType>(2)), std::domain_error);
- BOOST_CHECK_THROW(kurtosis(students_t_distribution<RealType>(static_cast<RealType>(2.0001L))), std::overflow_error);
- BOOST_CHECK_THROW(kurtosis(students_t_distribution<RealType>(3)), std::overflow_error);
- BOOST_CHECK_THROW(kurtosis(students_t_distribution<RealType>(4)), std::overflow_error); // df == k
+ BOOST_CHECK_THROW(kurtosis(students_t_distribution<RealType>(static_cast<RealType>(2.0001L))), std::domain_error);
+ BOOST_CHECK_THROW(kurtosis(students_t_distribution<RealType>(3)), std::domain_error);
+ BOOST_CHECK_THROW(kurtosis(students_t_distribution<RealType>(4)), std::domain_error); // df == k
     BOOST_CHECK_EQUAL(kurtosis(students_t_distribution<RealType>(5)), 9); // OK.
 
     // Use a new distribution ignore_error_students_t with a custom policy to ignore all errors,
@@ -577,70 +576,62 @@
   typedef students_t_distribution<RealType, my_ignore_policy> ignore_error_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.
+ // Integers are always converted to RealType,
+ // others requires static cast to RealType from long double.
 
- // Mean
   if(std::numeric_limits<RealType>::has_quiet_NaN)
   {
+ // Mean
     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)))));
+ BOOST_CHECK(boost::math::isnan(variance(ignore_error_students_t(static_cast<RealType>(1.7L)))));
+ BOOST_CHECK(boost::math::isnan(variance(ignore_error_students_t(2))));
 
   // 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(std::numeric_limits<RealType>::quiet_NaN()))));
     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?).
+ // Kurtosis
     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::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::isnan(kurtosis(ignore_error_students_t(static_cast<RealType>(2.0001L)))));
+ BOOST_CHECK(boost::math::isnan(kurtosis(ignore_error_students_t(3))));
+ BOOST_CHECK(boost::math::isnan(kurtosis(ignore_error_students_t(4))));
+
+ // Kurtosis excess
+ BOOST_CHECK(boost::math::isnan(kurtosis_excess(ignore_error_students_t(std::numeric_limits<RealType>::quiet_NaN()))));
+ BOOST_CHECK(boost::math::isnan(kurtosis_excess(ignore_error_students_t(std::numeric_limits<RealType>::infinity()))));
+ BOOST_CHECK(boost::math::isnan(kurtosis_excess(ignore_error_students_t(-1))));
+ BOOST_CHECK(boost::math::isnan(kurtosis_excess(ignore_error_students_t(0))));
+ BOOST_CHECK(boost::math::isnan(kurtosis_excess(ignore_error_students_t(1))));
+ BOOST_CHECK(boost::math::isnan(kurtosis_excess(ignore_error_students_t(2))));
+ BOOST_CHECK(boost::math::isnan(kurtosis_excess(ignore_error_students_t(static_cast<RealType>(2.0001L)))));
+ BOOST_CHECK(boost::math::isnan(kurtosis_excess(ignore_error_students_t(3))));
+ BOOST_CHECK(boost::math::isnan(kurtosis_excess(ignore_error_students_t(4))));
+ } // has_quiet_NaN
+
+ BOOST_CHECK(boost::math::isfinite(mean(ignore_error_students_t(1 + std::numeric_limits<RealType>::epsilon()))));
   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(variance(ignore_error_students_t(static_cast<RealType>(2.0001L)))));
+ BOOST_CHECK(boost::math::isfinite(variance(ignore_error_students_t(2 + 2 * std::numeric_limits<RealType>::epsilon()))));
+ BOOST_CHECK(boost::math::isfinite(skewness(ignore_error_students_t(3 + 3 * std::numeric_limits<RealType>::epsilon()))));
+ BOOST_CHECK(boost::math::isfinite(kurtosis(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);


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