|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r78751 - in trunk: boost/math/distributions libs/math/test
From: john_at_[hidden]
Date: 2012-05-29 13:43:18
Author: johnmaddock
Date: 2012-05-29 13:43:16 EDT (Tue, 29 May 2012)
New Revision: 78751
URL: http://svn.boost.org/trac/boost/changeset/78751
Log:
Add boilerplate code for testing most domain errors in the distributions.
Update the non-central distributions to make use of it.
Added:
trunk/libs/math/test/test_out_of_range.hpp (contents, props changed)
Text files modified:
trunk/boost/math/distributions/fisher_f.hpp | 4 ++--
trunk/libs/math/test/test_nc_chi_squared.cpp | 9 +++++++++
trunk/libs/math/test/test_nc_f.cpp | 10 ++++++++++
trunk/libs/math/test/test_nc_t.cpp | 8 ++++++++
4 files changed, 29 insertions(+), 2 deletions(-)
Modified: trunk/boost/math/distributions/fisher_f.hpp
==============================================================================
--- trunk/boost/math/distributions/fisher_f.hpp (original)
+++ trunk/boost/math/distributions/fisher_f.hpp 2012-05-29 13:43:16 EDT (Tue, 29 May 2012)
@@ -169,12 +169,12 @@
RealType df2 = dist.degrees_of_freedom2();
// Error check:
RealType error_result = 0;
- if(false == detail::check_df(
+ if(false == (detail::check_df(
function, df1, &error_result, Policy())
&& detail::check_df(
function, df2, &error_result, Policy())
&& detail::check_probability(
- function, p, &error_result, Policy()))
+ function, p, &error_result, Policy())))
return error_result;
// With optimizations turned on, gcc wrongly warns about y being used
Modified: trunk/libs/math/test/test_nc_chi_squared.cpp
==============================================================================
--- trunk/libs/math/test/test_nc_chi_squared.cpp (original)
+++ trunk/libs/math/test/test_nc_chi_squared.cpp 2012-05-29 13:43:16 EDT (Tue, 29 May 2012)
@@ -27,6 +27,7 @@
#include <boost/test/results_collector.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/test/floating_point_comparison.hpp> // for BOOST_CHECK_CLOSE
+#include "test_out_of_range.hpp"
#include "functor.hpp"
#include "handle_test_result.hpp"
@@ -344,6 +345,14 @@
BOOST_CHECK_CLOSE(
kurtosis_excess(dist)
, static_cast<RealType>(0.65625), tol2);
+
+ // Error handling checks:
+ check_out_of_range<boost::math::non_central_chi_squared_distribution<RealType> >(1, 1);
+ BOOST_CHECK_THROW(pdf(boost::math::non_central_chi_squared_distribution<RealType>(0, 1), 0), std::domain_error);
+ BOOST_CHECK_THROW(pdf(boost::math::non_central_chi_squared_distribution<RealType>(-1, 1), 0), std::domain_error);
+ BOOST_CHECK_THROW(pdf(boost::math::non_central_chi_squared_distribution<RealType>(1, -1), 0), std::domain_error);
+ BOOST_CHECK_THROW(quantile(boost::math::non_central_chi_squared_distribution<RealType>(1, 1), -1), std::domain_error);
+ BOOST_CHECK_THROW(quantile(boost::math::non_central_chi_squared_distribution<RealType>(1, 1), 2), std::domain_error);
} // template <class RealType>void test_spots(RealType)
template <class T>
Modified: trunk/libs/math/test/test_nc_f.cpp
==============================================================================
--- trunk/libs/math/test/test_nc_f.cpp (original)
+++ trunk/libs/math/test/test_nc_f.cpp 2012-05-29 13:43:16 EDT (Tue, 29 May 2012)
@@ -26,6 +26,7 @@
#include <boost/test/results_collector.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/test/floating_point_comparison.hpp> // for BOOST_CHECK_CLOSE
+#include "test_out_of_range.hpp"
#include "functor.hpp"
#include "handle_test_result.hpp"
@@ -282,6 +283,15 @@
BOOST_CHECK_CLOSE(
kurtosis_excess(dist)
, static_cast<RealType>(13.225781681053154767604638331440974359675882226873L), tol2);
+
+ // Error handling checks:
+ check_out_of_range<boost::math::non_central_f_distribution<RealType> >(1, 1, 1);
+ BOOST_CHECK_THROW(pdf(boost::math::non_central_f_distribution<RealType>(0, 1, 1), 0), std::domain_error);
+ BOOST_CHECK_THROW(pdf(boost::math::non_central_f_distribution<RealType>(-1, 1, 1), 0), std::domain_error);
+ BOOST_CHECK_THROW(pdf(boost::math::non_central_f_distribution<RealType>(1, 0, 1), 0), std::domain_error);
+ BOOST_CHECK_THROW(pdf(boost::math::non_central_f_distribution<RealType>(1, -1, 1), 0), std::domain_error);
+ BOOST_CHECK_THROW(quantile(boost::math::non_central_f_distribution<RealType>(1, 1, 1), -1), std::domain_error);
+ BOOST_CHECK_THROW(quantile(boost::math::non_central_f_distribution<RealType>(1, 1, 1), 2), std::domain_error);
} // template <class RealType>void test_spots(RealType)
int test_main(int, char* [])
Modified: trunk/libs/math/test/test_nc_t.cpp
==============================================================================
--- trunk/libs/math/test/test_nc_t.cpp (original)
+++ trunk/libs/math/test/test_nc_t.cpp 2012-05-29 13:43:16 EDT (Tue, 29 May 2012)
@@ -30,6 +30,7 @@
#include "functor.hpp"
#include "handle_test_result.hpp"
#include "table_type.hpp"
+#include "test_out_of_range.hpp"
#include <iostream>
using std::cout;
@@ -330,6 +331,13 @@
BOOST_CHECK_CLOSE(pdf(boost::math::non_central_t_distribution<RealType>(126, -2), -4), static_cast<RealType>(5.797932289365814702402873546466798025787e-2L), tolerance);
BOOST_CHECK_CLOSE(pdf(boost::math::non_central_t_distribution<RealType>(126, 2), 4), static_cast<RealType>(5.797932289365814702402873546466798025787e-2L), tolerance);
BOOST_CHECK_CLOSE(pdf(boost::math::non_central_t_distribution<RealType>(126, 2), 0), static_cast<RealType>(5.388394890639957139696546086044839573749e-2L), tolerance);
+
+ // Error handling checks:
+ check_out_of_range<boost::math::non_central_t_distribution<RealType> >(1, 1);
+ BOOST_CHECK_THROW(pdf(boost::math::non_central_t_distribution<RealType>(0, 1), 0), std::domain_error);
+ BOOST_CHECK_THROW(pdf(boost::math::non_central_t_distribution<RealType>(-1, 1), 0), std::domain_error);
+ BOOST_CHECK_THROW(quantile(boost::math::non_central_t_distribution<RealType>(1, 1), -1), std::domain_error);
+ BOOST_CHECK_THROW(quantile(boost::math::non_central_t_distribution<RealType>(1, 1), 2), std::domain_error);
} // template <class RealType>void test_spots(RealType)
template <class T>
Added: trunk/libs/math/test/test_out_of_range.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/math/test/test_out_of_range.hpp 2012-05-29 13:43:16 EDT (Tue, 29 May 2012)
@@ -0,0 +1,127 @@
+// Copyright John Maddock 2012.
+
+// Use, modification and distribution are subject to the
+// Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt
+// or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_MATH_TEST_OUT_OF_RANGE_HPP
+#define BOOST_MATH_TEST_OUT_OF_RANGE_HPP
+
+#include <boost/math/special_functions/next.hpp>
+#include <boost/test/test_tools.hpp>
+
+template <class Distro>
+void check_support(const Distro& d)
+{
+ typedef typename Distro::value_type value_type;
+ if(range(d).first != -boost::math::tools::max_value<value_type>())
+ {
+ value_type m = boost::math::float_prior(range(d).first);
+ BOOST_ASSERT(m != range(d).first);
+ BOOST_ASSERT(m < range(d).first);
+ BOOST_CHECK_THROW(pdf(d, m), std::domain_error);
+ BOOST_CHECK_THROW(cdf(d, m), std::domain_error);
+ BOOST_CHECK_THROW(cdf(complement(d, m)), std::domain_error);
+ }
+ if(range(d).second != boost::math::tools::max_value<value_type>())
+ {
+ value_type m = boost::math::float_next(range(d).second);
+ BOOST_ASSERT(m != range(d).first);
+ BOOST_ASSERT(m > range(d).first);
+ BOOST_CHECK_THROW(pdf(d, m), std::domain_error);
+ BOOST_CHECK_THROW(cdf(d, m), std::domain_error);
+ BOOST_CHECK_THROW(cdf(complement(d, m)), std::domain_error);
+ }
+ if(std::numeric_limits<value_type>::has_infinity)
+ {
+ BOOST_CHECK_THROW(pdf(d, std::numeric_limits<value_type>::infinity()), std::domain_error);
+ BOOST_CHECK_THROW(cdf(d, std::numeric_limits<value_type>::infinity()), std::domain_error);
+ BOOST_CHECK_THROW(cdf(complement(d, std::numeric_limits<value_type>::infinity())), std::domain_error);
+ BOOST_CHECK_THROW(pdf(d, -std::numeric_limits<value_type>::infinity()), std::domain_error);
+ BOOST_CHECK_THROW(cdf(d, -std::numeric_limits<value_type>::infinity()), std::domain_error);
+ BOOST_CHECK_THROW(cdf(complement(d, -std::numeric_limits<value_type>::infinity())), std::domain_error);
+ BOOST_CHECK_THROW(quantile(d, std::numeric_limits<value_type>::infinity()), std::domain_error);
+ BOOST_CHECK_THROW(quantile(d, -std::numeric_limits<value_type>::infinity()), std::domain_error);
+ BOOST_CHECK_THROW(quantile(complement(d, std::numeric_limits<value_type>::infinity())), std::domain_error);
+ BOOST_CHECK_THROW(quantile(complement(d, -std::numeric_limits<value_type>::infinity())), std::domain_error);
+ }
+ if(std::numeric_limits<value_type>::has_quiet_NaN)
+ {
+ BOOST_CHECK_THROW(pdf(d, std::numeric_limits<value_type>::quiet_NaN()), std::domain_error);
+ BOOST_CHECK_THROW(cdf(d, std::numeric_limits<value_type>::quiet_NaN()), std::domain_error);
+ BOOST_CHECK_THROW(cdf(complement(d, std::numeric_limits<value_type>::quiet_NaN())), std::domain_error);
+ BOOST_CHECK_THROW(pdf(d, -std::numeric_limits<value_type>::quiet_NaN()), std::domain_error);
+ BOOST_CHECK_THROW(cdf(d, -std::numeric_limits<value_type>::quiet_NaN()), std::domain_error);
+ BOOST_CHECK_THROW(cdf(complement(d, -std::numeric_limits<value_type>::quiet_NaN())), std::domain_error);
+ BOOST_CHECK_THROW(quantile(d, std::numeric_limits<value_type>::quiet_NaN()), std::domain_error);
+ BOOST_CHECK_THROW(quantile(d, -std::numeric_limits<value_type>::quiet_NaN()), std::domain_error);
+ BOOST_CHECK_THROW(quantile(complement(d, std::numeric_limits<value_type>::quiet_NaN())), std::domain_error);
+ BOOST_CHECK_THROW(quantile(complement(d, -std::numeric_limits<value_type>::quiet_NaN())), std::domain_error);
+ }
+ BOOST_CHECK_THROW(quantile(d, -1), std::domain_error);
+ BOOST_CHECK_THROW(quantile(d, 2), std::domain_error);
+ BOOST_CHECK_THROW(quantile(complement(d, -1)), std::domain_error);
+ BOOST_CHECK_THROW(quantile(complement(d, 2)), std::domain_error);
+}
+
+template <class Distro>
+void check_out_of_range()
+{
+ Distro d;
+ check_support(d);
+}
+template <class Distro>
+void check_out_of_range(typename Distro::value_type p1)
+{
+ typedef typename Distro::value_type value_type;
+ Distro d(p1);
+ check_support(d);
+ if(std::numeric_limits<value_type>::has_infinity)
+ {
+ BOOST_CHECK_THROW(pdf(Distro(std::numeric_limits<value_type>::infinity()), range(d).first), std::domain_error);
+ }
+ if(std::numeric_limits<value_type>::has_quiet_NaN)
+ {
+ BOOST_CHECK_THROW(pdf(Distro(std::numeric_limits<value_type>::quiet_NaN()), range(d).first), std::domain_error);
+ }
+}
+template <class Distro>
+void check_out_of_range(typename Distro::value_type p1, typename Distro::value_type p2)
+{
+ typedef typename Distro::value_type value_type;
+ Distro d(p1, p2);
+ check_support(d);
+ if(std::numeric_limits<value_type>::has_infinity)
+ {
+ BOOST_CHECK_THROW(pdf(Distro(std::numeric_limits<value_type>::infinity(), p2), range(d).first), std::domain_error);
+ BOOST_CHECK_THROW(pdf(Distro(p1, std::numeric_limits<value_type>::infinity()), range(d).first), std::domain_error);
+ }
+ if(std::numeric_limits<value_type>::has_quiet_NaN)
+ {
+ BOOST_CHECK_THROW(pdf(Distro(std::numeric_limits<value_type>::quiet_NaN(), p2), range(d).first), std::domain_error);
+ BOOST_CHECK_THROW(pdf(Distro(p1, std::numeric_limits<value_type>::quiet_NaN()), range(d).first), std::domain_error);
+ }
+}
+
+template <class Distro>
+void check_out_of_range(typename Distro::value_type p1, typename Distro::value_type p2, typename Distro::value_type p3)
+{
+ typedef typename Distro::value_type value_type;
+ Distro d(p1, p2, p3);
+ check_support(d);
+ if(std::numeric_limits<value_type>::has_infinity)
+ {
+ BOOST_CHECK_THROW(pdf(Distro(std::numeric_limits<value_type>::infinity(), p2, p3), range(d).first), std::domain_error);
+ BOOST_CHECK_THROW(pdf(Distro(p1, std::numeric_limits<value_type>::infinity(), p3), range(d).first), std::domain_error);
+ BOOST_CHECK_THROW(pdf(Distro(p1, p2, std::numeric_limits<value_type>::infinity()), range(d).first), std::domain_error);
+ }
+ if(std::numeric_limits<value_type>::has_quiet_NaN)
+ {
+ BOOST_CHECK_THROW(pdf(Distro(std::numeric_limits<value_type>::quiet_NaN(), p2, p3), range(d).first), std::domain_error);
+ BOOST_CHECK_THROW(pdf(Distro(p1, std::numeric_limits<value_type>::quiet_NaN(), p3), range(d).first), std::domain_error);
+ BOOST_CHECK_THROW(pdf(Distro(p1, p2, std::numeric_limits<value_type>::quiet_NaN()), range(d).first), std::domain_error);
+ }
+}
+
+#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