Skip to content

Commit

Permalink
Add arcsine dist testing
Browse files Browse the repository at this point in the history
  • Loading branch information
mborland committed Jul 18, 2024
1 parent d10faa8 commit b51f61b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 57 deletions.
1 change: 1 addition & 0 deletions test/cmake_jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ run test_autodiff_1.cpp ;
run test_polynomial.cpp ;

# Distributions
run test_arcsine.cpp ;
run test_binomial.cpp ;
113 changes: 56 additions & 57 deletions test/test_arcsine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

// Tests for the arcsine Distribution.

#include <pch.hpp> // Must be 1st include, and include_directory /libs/math/src/tr1/ is needed.
// #include <pch.hpp> // Must be 1st include, and include_directory /libs/math/src/tr1/ is needed.

#ifdef _MSC_VER
# pragma warning(disable: 4127) // Conditional expression is constant.
Expand All @@ -20,7 +20,6 @@

#include <boost/math/concepts/real_concept.hpp> // for real_concept.
using ::boost::math::concepts::real_concept;
#include <boost/math/tools/test.hpp> // for real_concept.

#include <boost/math/distributions/arcsine.hpp> // for arcsine_distribution.
using boost::math::arcsine_distribution;
Expand Down Expand Up @@ -272,7 +271,7 @@ void test_spots(RealType)
BOOST_CHECK_EQUAL(kurtosis_excess(arcsine_01), -1.5); // 3/2
BOOST_CHECK_EQUAL(support(arcsine_01).first, 0); //
BOOST_CHECK_EQUAL(range(arcsine_01).first, 0); //
BOOST_MATH_CHECK_THROW(mode(arcsine_01), std::domain_error); // Two modes at x_min and x_max, so throw instead.
BOOST_CHECK_THROW(mode(arcsine_01), std::domain_error); // Two modes at x_min and x_max, so throw instead.

// PDF
// pdf of x = 1/4 is same as reflected value at x = 3/4.
Expand Down Expand Up @@ -439,135 +438,135 @@ void test_spots(RealType)
BOOST_CHECK_CLOSE_FRACTION(quantile(complement(as_m2m1, static_cast<RealType>(0.85643370687129372924905811522494428117838480010259L))), -static_cast<RealType>(1.95L), 4 * tolerance);

// Tests that should throw:
BOOST_MATH_CHECK_THROW(mode(arcsine_distribution<RealType>(static_cast<RealType>(0), static_cast<RealType>(1))), std::domain_error);
BOOST_CHECK_THROW(mode(arcsine_distribution<RealType>(static_cast<RealType>(0), static_cast<RealType>(1))), std::domain_error);
// mode is undefined, and must throw domain_error!


BOOST_MATH_CHECK_THROW( // For various bad arguments.
BOOST_CHECK_THROW( // For various bad arguments.
pdf(
arcsine_distribution<RealType>(static_cast<RealType>(+1), static_cast<RealType>(-1)), // min_x > max_x
static_cast<RealType>(1)), std::domain_error);

BOOST_MATH_CHECK_THROW(
BOOST_CHECK_THROW(
pdf(
arcsine_distribution<RealType>(static_cast<RealType>(1), static_cast<RealType>(0)), // bad constructor parameters.
static_cast<RealType>(1)), std::domain_error);

BOOST_MATH_CHECK_THROW(
BOOST_CHECK_THROW(
pdf(
arcsine_distribution<RealType>(static_cast<RealType>(1), static_cast<RealType>(-1)), // bad constructor parameters.
static_cast<RealType>(1)), std::domain_error);

BOOST_MATH_CHECK_THROW(
BOOST_CHECK_THROW(
pdf(
arcsine_distribution<RealType>(static_cast<RealType>(1), static_cast<RealType>(1)), // equal constructor parameters.
static_cast<RealType>(-1)), std::domain_error);

BOOST_MATH_CHECK_THROW(
BOOST_CHECK_THROW(
pdf(
arcsine_distribution<RealType>(static_cast<RealType>(0), static_cast<RealType>(1)), // bad x > 1.
static_cast<RealType>(999)), std::domain_error);

BOOST_MATH_CHECK_THROW( // For various bad arguments.
BOOST_CHECK_THROW( // For various bad arguments.
logpdf(
arcsine_distribution<RealType>(static_cast<RealType>(+1), static_cast<RealType>(-1)), // min_x > max_x
static_cast<RealType>(1)), std::domain_error);

BOOST_MATH_CHECK_THROW(
BOOST_CHECK_THROW(
logpdf(
arcsine_distribution<RealType>(static_cast<RealType>(1), static_cast<RealType>(0)), // bad constructor parameters.
static_cast<RealType>(1)), std::domain_error);

BOOST_MATH_CHECK_THROW(
BOOST_CHECK_THROW(
logpdf(
arcsine_distribution<RealType>(static_cast<RealType>(1), static_cast<RealType>(-1)), // bad constructor parameters.
static_cast<RealType>(1)), std::domain_error);

BOOST_MATH_CHECK_THROW(
BOOST_CHECK_THROW(
logpdf(
arcsine_distribution<RealType>(static_cast<RealType>(1), static_cast<RealType>(1)), // equal constructor parameters.
static_cast<RealType>(-1)), std::domain_error);

BOOST_MATH_CHECK_THROW(
BOOST_CHECK_THROW(
logpdf(
arcsine_distribution<RealType>(static_cast<RealType>(0), static_cast<RealType>(1)), // bad x > 1.
static_cast<RealType>(999)), std::domain_error);

// Checks on things that are errors.

// Construction with 'bad' parameters.
BOOST_MATH_CHECK_THROW(arcsine_distribution<RealType>(+1, -1), std::domain_error); // max < min.
BOOST_MATH_CHECK_THROW(arcsine_distribution<RealType>(+1, 0), std::domain_error); // max < min.
BOOST_CHECK_THROW(arcsine_distribution<RealType>(+1, -1), std::domain_error); // max < min.
BOOST_CHECK_THROW(arcsine_distribution<RealType>(+1, 0), std::domain_error); // max < min.

arcsine_distribution<> dist;
BOOST_MATH_CHECK_THROW(pdf(dist, -1), std::domain_error);
BOOST_MATH_CHECK_THROW(logpdf(dist, -1), std::domain_error);
BOOST_MATH_CHECK_THROW(cdf(dist, -1), std::domain_error);
BOOST_MATH_CHECK_THROW(cdf(complement(dist, -1)), std::domain_error);
BOOST_MATH_CHECK_THROW(quantile(dist, -1), std::domain_error);
BOOST_MATH_CHECK_THROW(quantile(complement(dist, -1)), std::domain_error);
BOOST_MATH_CHECK_THROW(quantile(dist, -1), std::domain_error);
BOOST_MATH_CHECK_THROW(quantile(complement(dist, -1)), std::domain_error);
BOOST_CHECK_THROW(pdf(dist, -1), std::domain_error);
BOOST_CHECK_THROW(logpdf(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::domain_error);
BOOST_CHECK_THROW(quantile(complement(dist, -1)), std::domain_error);
BOOST_CHECK_THROW(quantile(dist, -1), std::domain_error);
BOOST_CHECK_THROW(quantile(complement(dist, -1)), std::domain_error);

// Various combinations of bad constructor and member function parameters.
BOOST_MATH_CHECK_THROW(pdf(boost::math::arcsine_distribution<RealType>(0, 1), -1), std::domain_error);
BOOST_MATH_CHECK_THROW(pdf(boost::math::arcsine_distribution<RealType>(-1, 1), +2), std::domain_error);
BOOST_MATH_CHECK_THROW(logpdf(boost::math::arcsine_distribution<RealType>(0, 1), -1), std::domain_error);
BOOST_MATH_CHECK_THROW(logpdf(boost::math::arcsine_distribution<RealType>(-1, 1), +2), std::domain_error);
BOOST_MATH_CHECK_THROW(quantile(boost::math::arcsine_distribution<RealType>(1, 1), -1), std::domain_error);
BOOST_MATH_CHECK_THROW(quantile(boost::math::arcsine_distribution<RealType>(1, 1), 2), std::domain_error);
BOOST_CHECK_THROW(pdf(boost::math::arcsine_distribution<RealType>(0, 1), -1), std::domain_error);
BOOST_CHECK_THROW(pdf(boost::math::arcsine_distribution<RealType>(-1, 1), +2), std::domain_error);
BOOST_CHECK_THROW(logpdf(boost::math::arcsine_distribution<RealType>(0, 1), -1), std::domain_error);
BOOST_CHECK_THROW(logpdf(boost::math::arcsine_distribution<RealType>(-1, 1), +2), std::domain_error);
BOOST_CHECK_THROW(quantile(boost::math::arcsine_distribution<RealType>(1, 1), -1), std::domain_error);
BOOST_CHECK_THROW(quantile(boost::math::arcsine_distribution<RealType>(1, 1), 2), std::domain_error);

// No longer allow any parameter to be NaN or inf, so all these tests should throw.
if (std::numeric_limits<RealType>::has_quiet_NaN)
{
// Attempt to construct from non-finite parameters should throw.
RealType nan = std::numeric_limits<RealType>::quiet_NaN();
#ifndef BOOST_NO_EXCEPTIONS
BOOST_MATH_CHECK_THROW(arcsine_distribution<RealType> w(nan), std::domain_error);
BOOST_MATH_CHECK_THROW(arcsine_distribution<RealType> w(1, nan), std::domain_error);
BOOST_MATH_CHECK_THROW(arcsine_distribution<RealType> w(nan, 1), std::domain_error);
BOOST_CHECK_THROW(arcsine_distribution<RealType> w(nan), std::domain_error);
BOOST_CHECK_THROW(arcsine_distribution<RealType> w(1, nan), std::domain_error);
BOOST_CHECK_THROW(arcsine_distribution<RealType> w(nan, 1), std::domain_error);
#else
BOOST_MATH_CHECK_THROW(arcsine_distribution<RealType>(nan), std::domain_error);
BOOST_MATH_CHECK_THROW(arcsine_distribution<RealType>(1, nan), std::domain_error);
BOOST_MATH_CHECK_THROW(arcsine_distribution<RealType>(nan, 1), std::domain_error);
BOOST_CHECK_THROW(arcsine_distribution<RealType>(nan), std::domain_error);
BOOST_CHECK_THROW(arcsine_distribution<RealType>(1, nan), std::domain_error);
BOOST_CHECK_THROW(arcsine_distribution<RealType>(nan, 1), std::domain_error);
#endif

arcsine_distribution<RealType> w(RealType(-1), RealType(+1));
// NaN parameters to member functions should throw.
BOOST_MATH_CHECK_THROW(pdf(w, +nan), std::domain_error); // x = NaN
BOOST_MATH_CHECK_THROW(logpdf(w, +nan), std::domain_error); // x = NaN
BOOST_MATH_CHECK_THROW(cdf(w, +nan), std::domain_error); // x = NaN
BOOST_MATH_CHECK_THROW(cdf(complement(w, +nan)), std::domain_error); // x = + nan
BOOST_MATH_CHECK_THROW(quantile(w, +nan), std::domain_error); // p = + nan
BOOST_MATH_CHECK_THROW(quantile(complement(w, +nan)), std::domain_error); // p = + nan
BOOST_CHECK_THROW(pdf(w, +nan), std::domain_error); // x = NaN
BOOST_CHECK_THROW(logpdf(w, +nan), std::domain_error); // x = NaN
BOOST_CHECK_THROW(cdf(w, +nan), std::domain_error); // x = NaN
BOOST_CHECK_THROW(cdf(complement(w, +nan)), std::domain_error); // x = + nan
BOOST_CHECK_THROW(quantile(w, +nan), std::domain_error); // p = + nan
BOOST_CHECK_THROW(quantile(complement(w, +nan)), std::domain_error); // p = + nan
} // has_quiet_NaN

if (std::numeric_limits<RealType>::has_infinity)
{
// Attempt to construct from non-finite should throw.
RealType inf = std::numeric_limits<RealType>::infinity();
#ifndef BOOST_NO_EXCEPTIONS
BOOST_MATH_CHECK_THROW(arcsine_distribution<RealType> w(inf), std::domain_error);
BOOST_MATH_CHECK_THROW(arcsine_distribution<RealType> w(1, inf), std::domain_error);
BOOST_CHECK_THROW(arcsine_distribution<RealType> w(inf), std::domain_error);
BOOST_CHECK_THROW(arcsine_distribution<RealType> w(1, inf), std::domain_error);
#else
BOOST_MATH_CHECK_THROW(arcsine_distribution<RealType>(inf), std::domain_error);
BOOST_MATH_CHECK_THROW(arcsine_distribution<RealType>(1, inf), std::domain_error);
BOOST_CHECK_THROW(arcsine_distribution<RealType>(inf), std::domain_error);
BOOST_CHECK_THROW(arcsine_distribution<RealType>(1, inf), std::domain_error);
#endif
// Infinite parameters to member functions should throw.
arcsine_distribution<RealType> w(RealType(0), RealType(1));
#ifndef BOOST_NO_EXCEPTIONS
BOOST_MATH_CHECK_THROW(arcsine_distribution<RealType> w(inf), std::domain_error);
BOOST_MATH_CHECK_THROW(arcsine_distribution<RealType> w(1, inf), std::domain_error);
BOOST_CHECK_THROW(arcsine_distribution<RealType> w(inf), std::domain_error);
BOOST_CHECK_THROW(arcsine_distribution<RealType> w(1, inf), std::domain_error);
#else
BOOST_MATH_CHECK_THROW(arcsine_distribution<RealType>(inf), std::domain_error);
BOOST_MATH_CHECK_THROW(arcsine_distribution<RealType>(1, inf), std::domain_error);
BOOST_CHECK_THROW(arcsine_distribution<RealType>(inf), std::domain_error);
BOOST_CHECK_THROW(arcsine_distribution<RealType>(1, inf), std::domain_error);
#endif
BOOST_MATH_CHECK_THROW(pdf(w, +inf), std::domain_error); // x = inf
BOOST_MATH_CHECK_THROW(logpdf(w, +inf), std::domain_error); // x = inf
BOOST_MATH_CHECK_THROW(cdf(w, +inf), std::domain_error); // x = inf
BOOST_MATH_CHECK_THROW(cdf(complement(w, +inf)), std::domain_error); // x = + inf
BOOST_MATH_CHECK_THROW(quantile(w, +inf), std::domain_error); // p = + inf
BOOST_MATH_CHECK_THROW(quantile(complement(w, +inf)), std::domain_error); // p = + inf
BOOST_CHECK_THROW(pdf(w, +inf), std::domain_error); // x = inf
BOOST_CHECK_THROW(logpdf(w, +inf), std::domain_error); // x = inf
BOOST_CHECK_THROW(cdf(w, +inf), std::domain_error); // x = inf
BOOST_CHECK_THROW(cdf(complement(w, +inf)), std::domain_error); // x = + inf
BOOST_CHECK_THROW(quantile(w, +inf), std::domain_error); // p = + inf
BOOST_CHECK_THROW(quantile(complement(w, +inf)), std::domain_error); // p = + inf
} // has_infinity

// Error handling checks:
Expand Down Expand Up @@ -601,7 +600,7 @@ void test_spots(RealType)
BOOST_CHECK_EQUAL(kurtosis_excess(as), -1.5); // 3/2
BOOST_CHECK_EQUAL(support(as).first, 0); //
BOOST_CHECK_EQUAL(range(as).first, 0); //
BOOST_MATH_CHECK_THROW(mode(as), std::domain_error); // Two modes at x_min and x_max, so throw instead.
BOOST_CHECK_THROW(mode(as), std::domain_error); // Two modes at x_min and x_max, so throw instead.

// (Parameter value, arbitrarily zero, only communicates the floating point type).
test_spots(0.0F); // Test float.
Expand Down

0 comments on commit b51f61b

Please sign in to comment.