Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r78778 - in trunk: boost/math/distributions libs/math/test
From: john_at_[hidden]
Date: 2012-05-31 06:18:03


Author: johnmaddock
Date: 2012-05-31 06:18:02 EDT (Thu, 31 May 2012)
New Revision: 78778
URL: http://svn.boost.org/trac/boost/changeset/78778

Log:
Update more distribution tests, from Inverse* down to gamma.
Refs #6934.
Text files modified:
   trunk/boost/math/distributions/inverse_gaussian.hpp | 2 +-
   trunk/libs/math/test/test_gamma_dist.cpp | 8 ++++++++
   trunk/libs/math/test/test_geometric.cpp | 2 ++
   trunk/libs/math/test/test_inverse_chi_squared_distribution.cpp | 2 ++
   trunk/libs/math/test/test_inverse_gamma_distribution.cpp | 3 ++-
   trunk/libs/math/test/test_inverse_gaussian.cpp | 32 ++++++--------------------------
   6 files changed, 21 insertions(+), 28 deletions(-)

Modified: trunk/boost/math/distributions/inverse_gaussian.hpp
==============================================================================
--- trunk/boost/math/distributions/inverse_gaussian.hpp (original)
+++ trunk/boost/math/distributions/inverse_gaussian.hpp 2012-05-31 06:18:02 EDT (Thu, 31 May 2012)
@@ -380,7 +380,7 @@
       return result;
    if(false == detail::check_location(function, mean, &result, Policy()))
       return result;
- if(false == detail::check_x(function, x, &result, Policy()))
+ if(false == detail::check_positive_x(function, x, &result, Policy()))
       return result;
 
    normal_distribution<RealType> n01;

Modified: trunk/libs/math/test/test_gamma_dist.cpp
==============================================================================
--- trunk/libs/math/test/test_gamma_dist.cpp (original)
+++ trunk/libs/math/test/test_gamma_dist.cpp 2012-05-31 06:18:02 EDT (Thu, 31 May 2012)
@@ -24,6 +24,7 @@
 #include <boost/math/distributions/gamma.hpp>
     using boost::math::gamma_distribution;
 #include <boost/math/tools/test.hpp>
+#include "test_out_of_range.hpp"
 
 #include <iostream>
    using std::cout;
@@ -213,6 +214,13 @@
        (std::max)(tol2, static_cast<RealType>(std::numeric_limits<double>::epsilon() * 2 * 100))); // 2 eps as persent
     // Rely on default definition in derived accessors.
 
+ // error tests
+ check_out_of_range<gamma_distribution<RealType> >(1, 1);
+ BOOST_CHECK_THROW(gamma_distribution<RealType>(0, 1), std::domain_error);
+ BOOST_CHECK_THROW(gamma_distribution<RealType>(-1, 1), std::domain_error);
+ BOOST_CHECK_THROW(gamma_distribution<RealType>(1, 0), std::domain_error);
+ BOOST_CHECK_THROW(gamma_distribution<RealType>(1, -1), std::domain_error);
+
 } // template <class RealType>void test_spots(RealType)
 
 int test_main(int, char* [])

Modified: trunk/libs/math/test/test_geometric.cpp
==============================================================================
--- trunk/libs/math/test/test_geometric.cpp (original)
+++ trunk/libs/math/test/test_geometric.cpp 2012-05-31 06:18:02 EDT (Thu, 31 May 2012)
@@ -37,6 +37,7 @@
 
 #include <boost/test/test_exec_monitor.hpp> // for test_main
 #include <boost/test/floating_point_comparison.hpp> // for BOOST_CHECK_CLOSE_FRACTION
+#include "test_out_of_range.hpp"
 
 #include <iostream>
 using std::cout;
@@ -719,6 +720,7 @@
   quantile( // Success_fraction > 1!
   geometric_distribution<RealType>(static_cast<RealType>(1.25)),
   static_cast<RealType>(0)), std::domain_error);
+ check_out_of_range<geometric_distribution<RealType> >(0.5);
   // End of check throwing 'duff' out-of-domain values.
 
   { // Compare geometric and negative binomial functions.

Modified: trunk/libs/math/test/test_inverse_chi_squared_distribution.cpp
==============================================================================
--- trunk/libs/math/test/test_inverse_chi_squared_distribution.cpp (original)
+++ trunk/libs/math/test/test_inverse_chi_squared_distribution.cpp 2012-05-31 06:18:02 EDT (Thu, 31 May 2012)
@@ -20,6 +20,7 @@
 //#include <boost/math/tools/test.hpp>
 #include <boost/test/test_exec_monitor.hpp> // for test_main
 #include <boost/test/floating_point_comparison.hpp> // for BOOST_CHECK_CLOSE_FRACTION
+#include "test_out_of_range.hpp"
 
 #include <boost/math/distributions/inverse_chi_squared.hpp> // for inverse_chisquared_distribution
 using boost::math::inverse_chi_squared_distribution;
@@ -142,6 +143,7 @@
   BOOST_CHECK_THROW(boost::math::inverse_chi_squared_distribution<RealType> ichsqbad1(-1), std::domain_error); // negative degrees_of_freedom.
   BOOST_CHECK_THROW(boost::math::inverse_chi_squared_distribution<RealType> ichsqbad2(1, -1), std::domain_error); // negative scale.
   BOOST_CHECK_THROW(boost::math::inverse_chi_squared_distribution<RealType> ichsqbad3(-1, -1), std::domain_error); // negative scale and degrees_of_freedom.
+ check_out_of_range<boost::math::inverse_chi_squared_distribution<RealType> >(1, 1);
 
   inverse_chi_squared_distribution<RealType> ichsq;
 

Modified: trunk/libs/math/test/test_inverse_gamma_distribution.cpp
==============================================================================
--- trunk/libs/math/test/test_inverse_gamma_distribution.cpp (original)
+++ trunk/libs/math/test/test_inverse_gamma_distribution.cpp 2012-05-31 06:18:02 EDT (Thu, 31 May 2012)
@@ -20,6 +20,7 @@
 //#include <boost/math/tools/test.hpp>
 #include <boost/test/test_exec_monitor.hpp> // for test_main
 #include <boost/test/floating_point_comparison.hpp> // for BOOST_CHECK_CLOSE_FRACTION
+#include "test_out_of_range.hpp"
 
 #include <boost/math/distributions/inverse_gamma.hpp> // for inverse_gamma_distribution
 using boost::math::inverse_gamma_distribution;
@@ -323,7 +324,7 @@
     inverse_gamma_distribution<RealType>(static_cast<RealType>(8)),
     static_cast<RealType>(1.1))), std::domain_error
     );
-
+ check_out_of_range<inverse_gamma_distribution<RealType> >(1, 1);
 } // template <class RealType>void test_spots(RealType)
 
 int test_main(int, char* [])

Modified: trunk/libs/math/test/test_inverse_gaussian.cpp
==============================================================================
--- trunk/libs/math/test/test_inverse_gaussian.cpp (original)
+++ trunk/libs/math/test/test_inverse_gaussian.cpp 2012-05-31 06:18:02 EDT (Thu, 31 May 2012)
@@ -25,6 +25,7 @@
 using boost::math::inverse_gaussian;
 
 #include <boost/math/tools/test.hpp>
+#include "test_out_of_range.hpp"
 
 #include <iostream>
 using std::cout;
@@ -90,33 +91,12 @@
   BOOST_CHECK_THROW(boost::math::inverse_gaussian_distribution<RealType> nbad1(0, 0), std::domain_error); // zero scale
   BOOST_CHECK_THROW(boost::math::inverse_gaussian_distribution<RealType> nbad1(0, -1), std::domain_error); // negative scale
 
- // Tests on extreme values of random variate x, if has numeric_limit infinity etc.
-
- // Infinity is not allowed, so all should throw.
   inverse_gaussian_distribution<RealType> w11;
- if(std::numeric_limits<RealType>::has_infinity)
- {
- BOOST_CHECK_THROW(pdf(w11, +std::numeric_limits<RealType>::infinity()), std::domain_error);
- BOOST_CHECK_THROW(pdf(w11, -std::numeric_limits<RealType>::infinity()), std::domain_error);
- BOOST_CHECK_THROW(cdf(w11, +std::numeric_limits<RealType>::infinity()), std::domain_error);
- BOOST_CHECK_THROW(cdf(w11, -std::numeric_limits<RealType>::infinity()), std::domain_error);
- BOOST_CHECK_THROW(cdf(complement(w11, +std::numeric_limits<RealType>::infinity())), std::domain_error); // x = + infinity,
- BOOST_CHECK_THROW(cdf(complement(w11, -std::numeric_limits<RealType>::infinity())), std::domain_error); // x = - infinity,
- BOOST_CHECK_THROW(boost::math::inverse_gaussian_distribution<RealType> nbad1(std::numeric_limits<RealType>::infinity(), static_cast<RealType>(1)), std::domain_error); // +infinite mean
- BOOST_CHECK_THROW(boost::math::inverse_gaussian_distribution<RealType> nbad1(-std::numeric_limits<RealType>::infinity(), static_cast<RealType>(1)), std::domain_error); // -infinite mean
- BOOST_CHECK_THROW(boost::math::inverse_gaussian_distribution<RealType> nbad1(static_cast<RealType>(0), std::numeric_limits<RealType>::infinity()), std::domain_error); // infinite scale
- }
-
- if (std::numeric_limits<RealType>::has_quiet_NaN)
- {
- // No longer allow x to be NaN, so these tests should throw.
- BOOST_CHECK_THROW(pdf(w11, +std::numeric_limits<RealType>::quiet_NaN()), std::domain_error); // x = NaN
- BOOST_CHECK_THROW(cdf(w11, +std::numeric_limits<RealType>::quiet_NaN()), std::domain_error); // x = NaN
- BOOST_CHECK_THROW(cdf(complement(w11, +std::numeric_limits<RealType>::quiet_NaN())), std::domain_error); // x = + infinity
- BOOST_CHECK_THROW(quantile(w11, +std::numeric_limits<RealType>::quiet_NaN()), std::domain_error); // p = + infinity
- BOOST_CHECK_THROW(quantile(complement(w11, +std::numeric_limits<RealType>::quiet_NaN())), std::domain_error); // p = + infinity
- }
- // Check complements.
+
+ // Error tests:
+ check_out_of_range<inverse_gaussian_distribution<RealType> >(0, 1);
+
+ // Check complements.
 
     BOOST_CHECK_CLOSE_FRACTION(
      cdf(complement(w11, 1.)), static_cast<RealType>(1) - cdf(w11, 1.), tolerance); // cdf complement


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