Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r78773 - in trunk: boost/math/distributions libs/math/test
From: john_at_[hidden]
Date: 2012-05-30 14:15:43


Author: johnmaddock
Date: 2012-05-30 14:15:41 EDT (Wed, 30 May 2012)
New Revision: 78773
URL: http://svn.boost.org/trac/boost/changeset/78773

Log:
Add extra error tests for negative_binomial to laplace distros.
Refs #6934.
Text files modified:
   trunk/boost/math/distributions/logistic.hpp | 4 +++-
   trunk/boost/math/distributions/lognormal.hpp | 31 +++++++++++++++++++++++++++++++
   trunk/libs/math/test/test_laplace.cpp | 5 +++++
   trunk/libs/math/test/test_logistic_dist.cpp | 12 ++++++++++++
   trunk/libs/math/test/test_lognormal.cpp | 5 ++++-
   trunk/libs/math/test/test_negative_binomial.cpp | 8 ++++++++
   trunk/libs/math/test/test_out_of_range.hpp | 9 +++++++++
   7 files changed, 72 insertions(+), 2 deletions(-)

Modified: trunk/boost/math/distributions/logistic.hpp
==============================================================================
--- trunk/boost/math/distributions/logistic.hpp (original)
+++ trunk/boost/math/distributions/logistic.hpp 2012-05-30 14:15:41 EDT (Wed, 30 May 2012)
@@ -53,7 +53,9 @@
     inline const std::pair<RealType, RealType> range(const logistic_distribution<RealType, Policy>& /* dist */)
     { // Range of permissible values for random variable x.
       using boost::math::tools::max_value;
- return std::pair<RealType, RealType>(-max_value<RealType>(), max_value<RealType>()); // - to + infinity
+ return std::pair<RealType, RealType>(
+ std::numeric_limits<RealType>::has_infinity ? -std::numeric_limits<RealType>::infinity() : -max_value<RealType>(),
+ std::numeric_limits<RealType>::has_infinity ? std::numeric_limits<RealType>::infinity() : max_value<RealType>());
     }
     
     template <class RealType, class Policy>

Modified: trunk/boost/math/distributions/lognormal.hpp
==============================================================================
--- trunk/boost/math/distributions/lognormal.hpp (original)
+++ trunk/boost/math/distributions/lognormal.hpp 2012-05-30 14:15:41 EDT (Wed, 30 May 2012)
@@ -53,6 +53,7 @@
    {
       RealType result;
       detail::check_scale("boost::math::lognormal_distribution<%1%>::lognormal_distribution", scale, &result, Policy());
+ detail::check_location("boost::math::lognormal_distribution<%1%>::lognormal_distribution", location, &result, Policy());
    }
 
    RealType location()const
@@ -102,6 +103,8 @@
    RealType result = 0;
    if(0 == detail::check_scale(function, sigma, &result, Policy()))
       return result;
+ if(0 == detail::check_location(function, mu, &result, Policy()))
+ return result;
    if(0 == detail::check_lognormal_x(function, x, &result, Policy()))
       return result;
 
@@ -126,6 +129,10 @@
    static const char* function = "boost::math::cdf(const lognormal_distribution<%1%>&, %1%)";
 
    RealType result = 0;
+ if(0 == detail::check_scale(function, dist.scale(), &result, Policy()))
+ return result;
+ if(0 == detail::check_location(function, dist.location(), &result, Policy()))
+ return result;
    if(0 == detail::check_lognormal_x(function, x, &result, Policy()))
       return result;
 
@@ -144,6 +151,10 @@
    static const char* function = "boost::math::quantile(const lognormal_distribution<%1%>&, %1%)";
 
    RealType result = 0;
+ if(0 == detail::check_scale(function, dist.scale(), &result, Policy()))
+ return result;
+ if(0 == detail::check_location(function, dist.location(), &result, Policy()))
+ return result;
    if(0 == detail::check_probability(function, p, &result, Policy()))
       return result;
 
@@ -164,6 +175,10 @@
    static const char* function = "boost::math::cdf(const lognormal_distribution<%1%>&, %1%)";
 
    RealType result = 0;
+ if(0 == detail::check_scale(function, c.dist.scale(), &result, Policy()))
+ return result;
+ if(0 == detail::check_location(function, c.dist.location(), &result, Policy()))
+ return result;
    if(0 == detail::check_lognormal_x(function, c.param, &result, Policy()))
       return result;
 
@@ -182,6 +197,10 @@
    static const char* function = "boost::math::quantile(const lognormal_distribution<%1%>&, %1%)";
 
    RealType result = 0;
+ if(0 == detail::check_scale(function, c.dist.scale(), &result, Policy()))
+ return result;
+ if(0 == detail::check_location(function, c.dist.location(), &result, Policy()))
+ return result;
    if(0 == detail::check_probability(function, c.param, &result, Policy()))
       return result;
 
@@ -205,6 +224,8 @@
    RealType result = 0;
    if(0 == detail::check_scale("boost::math::mean(const lognormal_distribution<%1%>&)", sigma, &result, Policy()))
       return result;
+ if(0 == detail::check_location("boost::math::mean(const lognormal_distribution<%1%>&)", mu, &result, Policy()))
+ return result;
 
    return exp(mu + sigma * sigma / 2);
 }
@@ -220,6 +241,8 @@
    RealType result = 0;
    if(0 == detail::check_scale("boost::math::variance(const lognormal_distribution<%1%>&)", sigma, &result, Policy()))
       return result;
+ if(0 == detail::check_location("boost::math::variance(const lognormal_distribution<%1%>&)", mu, &result, Policy()))
+ return result;
 
    return boost::math::expm1(sigma * sigma, Policy()) * exp(2 * mu + sigma * sigma);
 }
@@ -235,6 +258,8 @@
    RealType result = 0;
    if(0 == detail::check_scale("boost::math::mode(const lognormal_distribution<%1%>&)", sigma, &result, Policy()))
       return result;
+ if(0 == detail::check_location("boost::math::mode(const lognormal_distribution<%1%>&)", mu, &result, Policy()))
+ return result;
 
    return exp(mu - sigma * sigma);
 }
@@ -261,6 +286,8 @@
    RealType result = 0;
    if(0 == detail::check_scale("boost::math::skewness(const lognormal_distribution<%1%>&)", sigma, &result, Policy()))
       return result;
+ if(0 == detail::check_location("boost::math::skewness(const lognormal_distribution<%1%>&)", dist.location(), &result, Policy()))
+ return result;
 
    return (ess + 2) * sqrt(boost::math::expm1(ss, Policy()));
 }
@@ -277,6 +304,8 @@
    RealType result = 0;
    if(0 == detail::check_scale("boost::math::kurtosis(const lognormal_distribution<%1%>&)", sigma, &result, Policy()))
       return result;
+ if(0 == detail::check_location("boost::math::kurtosis(const lognormal_distribution<%1%>&)", dist.location(), &result, Policy()))
+ return result;
 
    return exp(4 * ss) + 2 * exp(3 * ss) + 3 * exp(2 * ss) - 3;
 }
@@ -293,6 +322,8 @@
    RealType result = 0;
    if(0 == detail::check_scale("boost::math::kurtosis_excess(const lognormal_distribution<%1%>&)", sigma, &result, Policy()))
       return result;
+ if(0 == detail::check_location("boost::math::kurtosis_excess(const lognormal_distribution<%1%>&)", dist.location(), &result, Policy()))
+ return result;
 
    return exp(4 * ss) + 2 * exp(3 * ss) + 3 * exp(2 * ss) - 6;
 }

Modified: trunk/libs/math/test/test_laplace.cpp
==============================================================================
--- trunk/libs/math/test/test_laplace.cpp (original)
+++ trunk/libs/math/test/test_laplace.cpp 2012-05-30 14:15:41 EDT (Wed, 30 May 2012)
@@ -62,6 +62,7 @@
 #include <boost/test/unit_test.hpp>
 #include <boost/math/constants/constants.hpp>
 #include <boost/math/distributions/laplace.hpp>
+#include "test_out_of_range.hpp"
 using boost::math::laplace_distribution;
 
 /*
@@ -281,6 +282,10 @@
    // static_cast<RealType>(0.93233235838169L),
       static_cast<RealType>(0.93233235838169365405300025251375779829618422688019L),
    tolerance);
+
+ check_out_of_range<laplace_distribution<RealType> >(0, 1);
+ BOOST_CHECK_THROW(laplace_distribution<RealType>(0, 0), std::domain_error);
+ BOOST_CHECK_THROW(laplace_distribution<RealType>(0, -1), std::domain_error);
 }
 
 template <class RealType>

Modified: trunk/libs/math/test/test_logistic_dist.cpp
==============================================================================
--- trunk/libs/math/test/test_logistic_dist.cpp (original)
+++ trunk/libs/math/test/test_logistic_dist.cpp 2012-05-30 14:15:41 EDT (Wed, 30 May 2012)
@@ -13,6 +13,7 @@
 
 #include <boost/test/test_exec_monitor.hpp> // Boost.Test
 #include <boost/test/floating_point_comparison.hpp>
+#include "test_out_of_range.hpp"
 
 
 #include <iostream>
@@ -215,6 +216,17 @@
    //1. domain errors for scale and location
    //2. x being NAN
    //3. Probabilies being outside (0,1)
+ check_out_of_range<logistic_distribution<RealType> >(0, 1);
+ if(std::numeric_limits<RealType>::has_infinity)
+ {
+ RealType inf = std::numeric_limits<RealType>::infinity();
+ BOOST_CHECK_EQUAL(pdf(logistic_distribution<RealType>(0, 1), inf), 0);
+ BOOST_CHECK_EQUAL(pdf(logistic_distribution<RealType>(0, 1), -inf), 0);
+ BOOST_CHECK_EQUAL(cdf(logistic_distribution<RealType>(0, 1), inf), 1);
+ BOOST_CHECK_EQUAL(cdf(logistic_distribution<RealType>(0, 1), -inf), 0);
+ BOOST_CHECK_EQUAL(cdf(complement(logistic_distribution<RealType>(0, 1), inf)), 0);
+ BOOST_CHECK_EQUAL(cdf(complement(logistic_distribution<RealType>(0, 1), -inf)), 1);
+ }
 
    //location/scale can't be infinity
    if(std::numeric_limits<RealType>::has_infinity) {

Modified: trunk/libs/math/test/test_lognormal.cpp
==============================================================================
--- trunk/libs/math/test/test_lognormal.cpp (original)
+++ trunk/libs/math/test/test_lognormal.cpp 2012-05-30 14:15:41 EDT (Wed, 30 May 2012)
@@ -15,6 +15,7 @@
 #include <boost/math/distributions/lognormal.hpp>
     using boost::math::lognormal_distribution;
 #include <boost/math/tools/test.hpp>
+#include "test_out_of_range.hpp"
 
 #include <iostream>
    using std::cout;
@@ -248,12 +249,14 @@
    //
    // Error checks:
    //
- BOOST_CHECK_THROW(lognormal_distribution<RealType>(0, -1), std::domain_error);
+ BOOST_CHECK_THROW(lognormal_distribution<RealType>(0, 0), std::domain_error);
+ BOOST_CHECK_THROW(lognormal_distribution<RealType>(2, -1), std::domain_error);
    BOOST_CHECK_THROW(pdf(dist, -1), std::domain_error);
    BOOST_CHECK_THROW(cdf(dist, -1), std::domain_error);
    BOOST_CHECK_THROW(cdf(complement(dist, -1)), std::domain_error);
    BOOST_CHECK_THROW(quantile(dist, 1), std::overflow_error);
    BOOST_CHECK_THROW(quantile(complement(dist, 0)), std::overflow_error);
+ check_out_of_range<lognormal_distribution<RealType> >(1, 2);
 
 } // template <class RealType>void test_spots(RealType)
 

Modified: trunk/libs/math/test/test_negative_binomial.cpp
==============================================================================
--- trunk/libs/math/test/test_negative_binomial.cpp (original)
+++ trunk/libs/math/test/test_negative_binomial.cpp 2012-05-30 14:15:41 EDT (Wed, 30 May 2012)
@@ -38,6 +38,7 @@
 #include <boost/test/test_exec_monitor.hpp> // for test_main
 #include <boost/test/floating_point_comparison.hpp> // for BOOST_CHECK_CLOSE
 #include "table_type.hpp"
+#include "test_out_of_range.hpp"
 
 #include <iostream>
 using std::cout;
@@ -302,6 +303,13 @@
   // Wolfram 0.517304753506834882009032744488738352004003696396461766326713
   // JM nonLanczos 0.51730475350664229 differs at the 13th decimal digit.
   // MathCAD 0.51730475342603199 differs at 10th decimal digit.
+
+ // Error tests:
+ check_out_of_range<negative_binomial_distribution<RealType> >(20, 0.5);
+ BOOST_CHECK_THROW(negative_binomial_distribution<RealType>(0, 0.5), std::domain_error);
+ BOOST_CHECK_THROW(negative_binomial_distribution<RealType>(-2, 0.5), std::domain_error);
+ BOOST_CHECK_THROW(negative_binomial_distribution<RealType>(20, -0.5), std::domain_error);
+ BOOST_CHECK_THROW(negative_binomial_distribution<RealType>(20, 1.5), std::domain_error);
 }
  // End of single spot tests using RealType
 

Modified: trunk/libs/math/test/test_out_of_range.hpp
==============================================================================
--- trunk/libs/math/test/test_out_of_range.hpp (original)
+++ trunk/libs/math/test/test_out_of_range.hpp 2012-05-30 14:15:41 EDT (Wed, 30 May 2012)
@@ -30,6 +30,11 @@
 because these are specific to each distribution.
 */
 
+#ifdef BOOST_MSVC
+#pragma warning(push)
+#pragma warning(disable:4127)
+#endif
+
 template <class Distro>
 void check_support(const Distro& d)
 { // Checks that
@@ -157,4 +162,8 @@
    }
 }
 
+#ifdef BOOST_MSVC
+#pragma warning(pop)
+#endif
+
 #endif // BOOST_MATH_TEST_OUT_OF_RANGE_HPP


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