Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r78767 - trunk/libs/math/test
From: pbristow_at_[hidden]
Date: 2012-05-30 12:32:13


Author: pbristow
Date: 2012-05-30 12:32:12 EDT (Wed, 30 May 2012)
New Revision: 78767
URL: http://svn.boost.org/trac/boost/changeset/78767

Log:
Added out of range checks
Text files modified:
   trunk/libs/math/test/test_binomial.cpp | 32 +++++++++++++++++++-------
   trunk/libs/math/test/test_cauchy.cpp | 47 +++++++++++----------------------------
   2 files changed, 37 insertions(+), 42 deletions(-)

Modified: trunk/libs/math/test/test_binomial.cpp
==============================================================================
--- trunk/libs/math/test/test_binomial.cpp (original)
+++ trunk/libs/math/test/test_binomial.cpp 2012-05-30 12:32:12 EDT (Wed, 30 May 2012)
@@ -21,6 +21,10 @@
 
 #ifdef _MSC_VER
 # pragma warning(disable: 4127) // conditional expression is constant.
+# pragma warning(disable: 4100) // unreferenced formal parameter.
+// Seems an entirely spurious warning - formal parameter T IS used - get error if /* T */
+//# pragma warning(disable: 4535) // calling _set_se_translator() requires /EHa (in Boost.test)
+// Enable C++ Exceptions Yes With SEH Exceptions (/EHa) prevents warning 4535.
 #endif
 
 #include <boost/math/concepts/real_concept.hpp> // for real_concept
@@ -33,6 +37,8 @@
 #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;
 using std::endl;
@@ -209,7 +215,7 @@
 }
 
 template <class RealType> // Any floating-point type RealType.
-void test_spots(RealType)
+void test_spots(RealType T)
 {
   // Basic sanity checks, test data is to double precision only
   // so set tolerance to 100eps expressed as a persent, or
@@ -222,7 +228,8 @@
   tolerance *= 100 * 1000;
   RealType tol2 = boost::math::tools::epsilon<RealType>() * 5 * 100; // 5 eps as a persent
 
- cout << "Tolerance = " << tolerance << "%." << endl;
+ cout << "Tolerance for type " << typeid(T).name() << " is " << tolerance << " %" << endl;
+
 
   // Sources of spot test values:
 
@@ -705,6 +712,9 @@
 #endif
   }
 
+ check_out_of_range<boost::math::binomial_distribution<RealType> >(1, 1); // (All) valid constructor parameter values.
+
+
 } // template <class RealType>void test_spots(RealType)
 
 int test_main(int, char* [])
@@ -748,12 +758,16 @@
 
 Output is:
 
-Autorun "i:\boost-06-05-03-1300\libs\math\test\Math_test\debug\test_binomial.exe"
-Running 1 test case...
-Tolerance = 0.0119209%.
-Tolerance = 2.22045e-011%.
-Tolerance = 2.22045e-011%.
-Tolerance = 2.22045e-011%.
-*** No errors detected
+ Description: Autorun "J:\Cpp\MathToolkit\test\Math_test\Debug\test_binomial.exe"
+ Running 1 test case...
+ Tolerance for type float is 0.0119209 %
+ Tolerance for type double is 2.22045e-011 %
+ Tolerance for type long double is 2.22045e-011 %
+ Tolerance for type class boost::math::concepts::real_concept is 2.22045e-011 %
+
+ *** No errors detected
+
+========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
+
 
 */

Modified: trunk/libs/math/test/test_cauchy.cpp
==============================================================================
--- trunk/libs/math/test/test_cauchy.cpp (original)
+++ trunk/libs/math/test/test_cauchy.cpp 2012-05-30 12:32:12 EDT (Wed, 30 May 2012)
@@ -23,6 +23,8 @@
 #include <boost/math/distributions/cauchy.hpp>
     using boost::math::cauchy_distribution;
 
+#include "test_out_of_range.hpp"
+
 #include <boost/test/test_exec_monitor.hpp> // Boost.Test
 #include <boost/test/floating_point_comparison.hpp>
 
@@ -33,38 +35,16 @@
 template <class RealType>
 void test_spots(RealType T)
 {
- // Check some bad parameters to the distribution,
- BOOST_CHECK_THROW(boost::math::cauchy_distribution<RealType> nbad1(0, 0), std::domain_error); // zero sd
- BOOST_CHECK_THROW(boost::math::cauchy_distribution<RealType> nbad1(0, -1), std::domain_error); // negative scale (shape)
+ // Check some bad parameters to construct the distribution,
+ BOOST_CHECK_THROW(boost::math::cauchy_distribution<RealType> nbad1(0, 0), std::domain_error); // zero scale.
+ BOOST_CHECK_THROW(boost::math::cauchy_distribution<RealType> nbad1(0, -1), std::domain_error); // negative scale (shape).
+
   cauchy_distribution<RealType> C01;
 
   BOOST_CHECK_EQUAL(C01.location(), 0); // Check standard values.
   BOOST_CHECK_EQUAL(C01.scale(), 1);
 
- // Tests on extreme values of random variate x, if has numeric_limit infinity etc.
- if(std::numeric_limits<RealType>::has_infinity)
- {
- BOOST_CHECK_EQUAL(pdf(C01, +std::numeric_limits<RealType>::infinity()), 0); // x = + infinity, pdf = 0
- BOOST_CHECK_EQUAL(pdf(C01, -std::numeric_limits<RealType>::infinity()), 0); // x = - infinity, pdf = 0
- BOOST_CHECK_EQUAL(cdf(C01, +std::numeric_limits<RealType>::infinity()), 1); // x = + infinity, cdf = 1
- BOOST_CHECK_EQUAL(cdf(C01, -std::numeric_limits<RealType>::infinity()), 0); // x = - infinity, cdf = 0
- BOOST_CHECK_EQUAL(cdf(complement(C01, +std::numeric_limits<RealType>::infinity())), 0); // x = + infinity, cdf = 0
- BOOST_CHECK_EQUAL(cdf(complement(C01, -std::numeric_limits<RealType>::infinity())), 1); // x = - infinity, cdf = 1
- BOOST_CHECK_THROW(boost::math::cauchy_distribution<RealType> nbad1(std::numeric_limits<RealType>::infinity(), static_cast<RealType>(1)), std::domain_error); // +infinite mean
- BOOST_CHECK_THROW(boost::math::cauchy_distribution<RealType> nbad1(-std::numeric_limits<RealType>::infinity(), static_cast<RealType>(1)), std::domain_error); // -infinite mean
- BOOST_CHECK_THROW(boost::math::cauchy_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, so these tests should throw.
- BOOST_CHECK_THROW(pdf(C01, +std::numeric_limits<RealType>::quiet_NaN()), std::domain_error); // x = NaN
- BOOST_CHECK_THROW(cdf(C01, +std::numeric_limits<RealType>::quiet_NaN()), std::domain_error); // x = NaN
- BOOST_CHECK_THROW(cdf(complement(C01, +std::numeric_limits<RealType>::quiet_NaN())), std::domain_error); // x = + infinity
- BOOST_CHECK_THROW(quantile(C01, +std::numeric_limits<RealType>::quiet_NaN()), std::domain_error); // p = + infinity
- BOOST_CHECK_THROW(quantile(complement(C01, +std::numeric_limits<RealType>::quiet_NaN())), std::domain_error); // p = + infinity
- }
-
- // Basic sanity checks.
+ // Basic sanity checks.
   // 50eps as a percentage, up to a maximum of double precision
   // (that's the limit of our test data).
   RealType tolerance = (std::max)(
@@ -709,16 +689,19 @@
        quantile(complement(dist, RealType(1.0))),
        std::overflow_error);
 
+ check_out_of_range<boost::math::cauchy_distribution<RealType> >(0, 1); // (All) valid constructor parameter values.
+
+
 
 } // template <class RealType>void test_spots(RealType)
 
 int test_main(int, char* [])
 {
- BOOST_MATH_CONTROL_FP;
+ BOOST_MATH_CONTROL_FP;
    // Check that can generate cauchy distribution using the two convenience methods:
- boost::math::cauchy mycd1(1.); // Using typedef
- cauchy_distribution<> mycd2(1.); // Using default RealType double.
- cauchy_distribution<> C01; // Using default RealType double for Standard Cauchy.
+ boost::math::cauchy mycd1(1.); // Using typedef
+ cauchy_distribution<> mycd2(1.); // Using default RealType double.
+ cauchy_distribution<> C01; // Using default RealType double for Standard Cauchy.
   BOOST_CHECK_EQUAL(C01.location(), 0); // Check standard values.
   BOOST_CHECK_EQUAL(C01.scale(), 1);
 
@@ -741,7 +724,6 @@
    return 0;
 } // int test_main(int, char* [])
 
-
 /*
 Output:
 
@@ -752,5 +734,4 @@
 Tolerance for type class boost::math::concepts::real_concept is 1.11022e-012 %
 *** No errors detected
 
-
 */


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