|
Boost-Commit : |
From: pbristow_at_[hidden]
Date: 2007-09-16 06:10:32
Author: pbristow
Date: 2007-09-16 06:10:31 EDT (Sun, 16 Sep 2007)
New Revision: 39311
URL: http://svn.boost.org/trac/boost/changeset/39311
Log:
tests changed to allow pdf and cdf infinity.
Text files modified:
sandbox/math_toolkit/libs/math/test/test_normal.cpp | 51 +++++++++++++++++++++++++--------------
1 files changed, 33 insertions(+), 18 deletions(-)
Modified: sandbox/math_toolkit/libs/math/test/test_normal.cpp
==============================================================================
--- sandbox/math_toolkit/libs/math/test/test_normal.cpp (original)
+++ sandbox/math_toolkit/libs/math/test/test_normal.cpp 2007-09-16 06:10:31 EDT (Sun, 16 Sep 2007)
@@ -15,6 +15,11 @@
// From MathWorld--A Wolfram Web Resource.
// http://mathworld.wolfram.com/NormalDistribution.html
+#ifdef _MSC_VER
+#pragma warning (disable: 4127) // conditional expression is constant
+#endif
+
+
#include <boost/math/concepts/real_concept.hpp> // for real_concept
#include <boost/test/included/test_exec_monitor.hpp> // Boost.Test
#include <boost/test/floating_point_comparison.hpp>
@@ -78,8 +83,34 @@
RealType tolerance = static_cast<RealType>(std::pow(10., -(4-2))); // 1e-4 (as %)
// Some tests only pass at 1e-4 because values generated by
// http://faculty.vassar.edu/lowry/VassarStats.html
- // give only 5 or 6 *fixed* places, so small values have fewer
- // digits.
+ // give only 5 or 6 *fixed* places, so small values have fewer digits.
+
+ // Check some bad parameters to the distribution,
+ BOOST_CHECK_THROW(boost::math::normal_distribution<RealType> nbad1(0, 0), std::domain_error); // zero sd
+ BOOST_CHECK_THROW(boost::math::normal_distribution<RealType> nbad1(0, -1), std::domain_error); // negative sd
+
+ // Tests on extreme values of random variate x, if has numeric_limit infinity etc.
+ normal_distribution<RealType> N01;
+ if(std::numeric_limits<RealType>::has_infinity)
+ {
+ BOOST_CHECK_EQUAL(pdf(N01, +std::numeric_limits<double>::infinity()), 0); // x = + infinity, pdf = 0
+ BOOST_CHECK_EQUAL(pdf(N01, -std::numeric_limits<double>::infinity()), 0); // x = - infinity, pdf = 0
+ BOOST_CHECK_EQUAL(cdf(N01, +std::numeric_limits<double>::infinity()), 1); // x = + infinity, cdf = 1
+ BOOST_CHECK_EQUAL(cdf(N01, -std::numeric_limits<double>::infinity()), 0); // x = - infinity, cdf = 0
+ BOOST_CHECK_THROW(boost::math::normal_distribution<RealType> nbad1(std::numeric_limits<RealType>::infinity(), static_cast<RealType>(1)), std::domain_error); // +infinite mean
+ BOOST_CHECK_THROW(boost::math::normal_distribution<RealType> nbad1(-std::numeric_limits<RealType>::infinity(), static_cast<RealType>(1)), std::domain_error); // -infinite mean
+ BOOST_CHECK_THROW(boost::math::normal_distribution<RealType> nbad1(static_cast<RealType>(0), std::numeric_limits<RealType>::infinity()), std::domain_error); // infinite sd
+ }
+
+ if (std::numeric_limits<RealType>::has_quiet_NaN)
+ {
+ // No longer allow x to be NaN, then these tests should throw.
+ BOOST_CHECK_THROW(pdf(N01, +std::numeric_limits<RealType>::quiet_NaN()), std::domain_error); // x = NaN
+ BOOST_CHECK_THROW(cdf(N01, +std::numeric_limits<RealType>::quiet_NaN()), std::domain_error); // x = NaN
+ BOOST_CHECK_THROW(cdf(complement(N01, +std::numeric_limits<RealType>::quiet_NaN())), std::domain_error); // x = + infinity
+ BOOST_CHECK_THROW(quantile(N01, +std::numeric_limits<RealType>::quiet_NaN()), std::domain_error); // p = + infinity
+ BOOST_CHECK_THROW(quantile(complement(N01, +std::numeric_limits<RealType>::quiet_NaN())), std::domain_error); // p = + infinity
+ }
cout << "Tolerance for type " << typeid(RealType).name() << " is " << tolerance << " %" << endl;
@@ -259,22 +290,6 @@
BOOST_CHECK_EQUAL(myn01.mean(), myn01.location());
BOOST_CHECK_EQUAL(myn01.standard_deviation(), myn01.scale());
- // Check some bad parameters to the distribution,
- // using just double because it has numeric_limit infinity etc.
- BOOST_CHECK_THROW(boost::math::normal nbad1(+std::numeric_limits<double>::infinity(), 1), std::domain_error); // +infinite mean
- BOOST_CHECK_THROW(boost::math::normal nbad1(-std::numeric_limits<double>::infinity(), 1), std::domain_error); // -infinite mean
- BOOST_CHECK_THROW(boost::math::normal nbad1(0, std::numeric_limits<double>::infinity()), std::domain_error); // infinite sd
- BOOST_CHECK_THROW(boost::math::normal nbad1(0, 0), std::domain_error); // zero sd
- BOOST_CHECK_THROW(boost::math::normal nbad1(0, -1), std::domain_error); // negative sd
-
- // Test on extreme values of random variate x, using just double because it has numeric_limit infinity etc..
- // No longer allow x to be + or - infinity, then these tests should throw.
- BOOST_CHECK_THROW(pdf(myn01, +std::numeric_limits<double>::infinity()), std::domain_error); // x = + infinity
- BOOST_CHECK_THROW(cdf(myn01, +std::numeric_limits<double>::infinity()), std::domain_error); // x = + infinity
- BOOST_CHECK_THROW(cdf(complement(myn01, +std::numeric_limits<double>::infinity())), std::domain_error); // x = + infinity
- BOOST_CHECK_THROW(quantile(myn01, +std::numeric_limits<double>::infinity()), std::domain_error); // p = + infinity
- BOOST_CHECK_THROW(quantile(complement(myn01, +std::numeric_limits<double>::infinity())), std::domain_error); // p = + infinity
-
// 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 %
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