From d424e2ef23b6c0c54b3dced2ee1924743e1a06dc Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Sun, 24 Aug 2014 18:40:21 +0100 Subject: [PATCH] Fix some more warnings and enable tests for all the test types. --- .../math/distributions/hyperexponential.hpp | 10 +- test/test_hyperexponential_dist.cpp | 188 +++++------------- 2 files changed, 60 insertions(+), 138 deletions(-) diff --git a/include/boost/math/distributions/hyperexponential.hpp b/include/boost/math/distributions/hyperexponential.hpp index edd457a69..f0ca821c1 100644 --- a/include/boost/math/distributions/hyperexponential.hpp +++ b/include/boost/math/distributions/hyperexponential.hpp @@ -478,7 +478,7 @@ RealT variance(hyperexponential_distribution const& dist) const RealT mean = boost::math::mean(dist); - result = 2.0*result-mean*mean; + result = 2*result-mean*mean; return result; } @@ -509,8 +509,8 @@ RealT skewness(hyperexponential_distribution const& dist) const RealT s1s1 = s1*s1; - const RealT num = (6.0*s3 - (3.0*(2.0*s2 - s1s1) + s1s1)*s1); - const RealT den = (2.0*s2 - s1s1); + const RealT num = (6*s3 - (3*(2*s2 - s1s1) + s1s1)*s1); + const RealT den = (2*s2 - s1s1); return num / pow(den, static_cast(1.5)); } @@ -544,8 +544,8 @@ RealT kurtosis(hyperexponential_distribution const& dist) const RealT s1s1 = s1*s1; - const RealT num = (24.0*s4 - 24.0*s3*s1 + 3.0*(2.0*(2.0*s2 - s1s1) + s1s1)*s1s1); - const RealT den = (2.0*s2 - s1s1); + const RealT num = (24*s4 - 24*s3*s1 + 3*(2*(2*s2 - s1s1) + s1s1)*s1s1); + const RealT den = (2*s2 - s1s1); return num/(den*den); } diff --git a/test/test_hyperexponential_dist.cpp b/test/test_hyperexponential_dist.cpp index 5ff149e00..77f3782b6 100644 --- a/test/test_hyperexponential_dist.cpp +++ b/test/test_hyperexponential_dist.cpp @@ -20,6 +20,7 @@ #include #include +typedef boost::mpl::list test_types; template RealT make_tolerance() @@ -55,39 +56,44 @@ RealT make_tolerance() tol *= 20; // real_concept special functions are less accurate } */ - - const RealT tol = boost::math::tools::epsilon() * 100 * 100; + // Current test data is limited to double precision: + const RealT tol = (std::max)(static_cast(boost::math::tools::epsilon()), boost::math::tools::epsilon()) * 100 * 100; //std::cout << "[" << __func__ << "] Tolerance: " << tol << "%" << std::endl; return tol; } -template -void test_range() +BOOST_AUTO_TEST_CASE_TEMPLATE(range, RealT, test_types) { const RealT tol = make_tolerance(); - const RealT probs[] = {0.2, 0.3, 0.5}; - const RealT rates[] = {0.5, 1.0, 1.5}; - const std::size_t n = sizeof(probs)/sizeof(RealT); + const RealT probs[] = { static_cast(0.2L), static_cast(0.3L), static_cast(0.5L) }; + const RealT rates[] = { static_cast(0.5L), static_cast(1.0L), static_cast(1.5L) }; + const std::size_t n = sizeof(probs) / sizeof(RealT); boost::math::hyperexponential_distribution dist(probs, probs+n, rates, rates+n); std::pair res; res = boost::math::range(dist); - BOOST_CHECK_CLOSE( res.first, 0, tol ); - BOOST_CHECK_EQUAL( res.second, std::numeric_limits::infinity() ); + BOOST_CHECK_CLOSE( res.first, static_cast(0), tol ); + if(std::numeric_limits::has_infinity) + { + BOOST_CHECK_EQUAL(res.second, std::numeric_limits::infinity()); + } + else + { + BOOST_CHECK_EQUAL(res.second, boost::math::tools::max_value()); + } } -template -void test_support() +BOOST_AUTO_TEST_CASE_TEMPLATE(support, RealT, test_types) { const RealT tol = make_tolerance(); - const RealT probs[] = {0.2, 0.3, 0.5}; - const RealT rates[] = {0.5, 1.0, 1.5}; + const RealT probs[] = { static_cast(0.2L), static_cast(0.3L), static_cast(0.5L) }; + const RealT rates[] = { static_cast(0.5L), static_cast(1), static_cast(1.5L) }; const std::size_t n = sizeof(probs)/sizeof(RealT); boost::math::hyperexponential_distribution dist(probs, probs+n, rates, rates+n); @@ -99,13 +105,12 @@ void test_support() BOOST_CHECK_CLOSE( res.second, boost::math::tools::max_value(), tol ); } -template -void test_pdf() +BOOST_AUTO_TEST_CASE_TEMPLATE(pdf, RealT, test_types) { const RealT tol = make_tolerance(); - const RealT probs[] = {0.2, 0.3, 0.5}; - const RealT rates[] = {0.5, 1.0, 1.5}; + const RealT probs[] = { static_cast(0.2L), static_cast(0.3L), static_cast(0.5L) }; + const RealT rates[] = { static_cast(0.5L), static_cast(1), static_cast(1.5) }; const std::size_t n = sizeof(probs)/sizeof(RealT); boost::math::hyperexponential_distribution dist(probs, probs+n, rates, rates+n); @@ -118,13 +123,12 @@ void test_pdf() BOOST_CHECK_CLOSE( boost::math::pdf(dist, static_cast(4)), static_cast(0.02088728412278129), tol ); } -template -void test_cdf() +BOOST_AUTO_TEST_CASE_TEMPLATE(cdf, RealT, test_types) { const RealT tol = make_tolerance(); - const RealT probs[] = {0.2, 0.3, 0.5}; - const RealT rates[] = {0.5, 1.0, 1.5}; + const RealT probs[] = { static_cast(0.2L), static_cast(0.3L), static_cast(0.5L) }; + const RealT rates[] = { static_cast(0.5L), static_cast(1.0L), static_cast(1.5L) }; const std::size_t n = sizeof(probs)/sizeof(RealT); boost::math::hyperexponential_distribution dist(probs, probs+n, rates, rates+n); @@ -138,13 +142,12 @@ void test_cdf() } -template -void test_quantile() +BOOST_AUTO_TEST_CASE_TEMPLATE(quantile, RealT, test_types) { const RealT tol = make_tolerance(); - const RealT probs[] = {0.2, 0.3, 0.5}; - const RealT rates[] = {0.5, 1.0, 1.5}; + const RealT probs[] = { static_cast(0.2L), static_cast(0.3L), static_cast(0.5L) }; + const RealT rates[] = { static_cast(0.5L), static_cast(1.0L), static_cast(1.5L) }; const std::size_t n = sizeof(probs)/sizeof(RealT); boost::math::hyperexponential_distribution dist(probs, probs+n, rates, rates+n); @@ -157,13 +160,12 @@ void test_quantile() BOOST_CHECK_CLOSE( boost::math::quantile(dist, static_cast(0.966198875597724)), static_cast(3.9999999999999964), tol ); } -template -void test_ccdf() +BOOST_AUTO_TEST_CASE_TEMPLATE(ccdf, RealT, test_types) { const RealT tol = make_tolerance(); - const RealT probs[] = {0.2, 0.3, 0.5}; - const RealT rates[] = {0.5, 1.0, 1.5}; + const RealT probs[] = { static_cast(0.2L), static_cast(0.3L), static_cast(0.5L) }; + const RealT rates[] = { static_cast(0.5L), static_cast(1.0L), static_cast(1.5L) }; const std::size_t n = sizeof(probs)/sizeof(RealT); boost::math::hyperexponential_distribution dist(probs, probs+n, rates, rates+n); @@ -177,14 +179,13 @@ void test_ccdf() } -template -void test_cquantile() +BOOST_AUTO_TEST_CASE_TEMPLATE(cquantile, RealT, test_types) { const RealT tol = make_tolerance(); - const RealT probs[] = {0.2, 0.3, 0.5}; - const RealT rates[] = {0.5, 1.0, 1.5}; - const std::size_t n = sizeof(probs)/sizeof(RealT); + const RealT probs[] = { static_cast(0.2L), static_cast(0.3L), static_cast(0.5L) }; + const RealT rates[] = { static_cast(0.5L), static_cast(1.0L), static_cast(1.5L) }; + const std::size_t n = sizeof(probs) / sizeof(RealT); boost::math::hyperexponential_distribution dist(probs, probs+n, rates, rates+n); @@ -196,14 +197,13 @@ void test_cquantile() BOOST_CHECK_CLOSE( boost::math::quantile(boost::math::complement(dist, static_cast(0.03380112440227598))), static_cast(3.9999999999999964), tol ); } -template -void test_mean() +BOOST_AUTO_TEST_CASE_TEMPLATE(mean, RealT, test_types) { const RealT tol = make_tolerance(); - const RealT probs[] = {0.2, 0.3, 0.5}; - const RealT rates[] = {0.5, 1.0, 1.5}; - const std::size_t n = sizeof(probs)/sizeof(RealT); + const RealT probs[] = { static_cast(0.2L), static_cast(0.3L), static_cast(0.5L) }; + const RealT rates[] = { static_cast(0.5L), static_cast(1.0L), static_cast(1.5L) }; + const std::size_t n = sizeof(probs) / sizeof(RealT); boost::math::hyperexponential_distribution dist(probs, probs+n, rates, rates+n); @@ -211,14 +211,13 @@ void test_mean() BOOST_CHECK_CLOSE( boost::math::mean(dist), static_cast(1.0333333333333332), tol ); } -template -void test_variance() +BOOST_AUTO_TEST_CASE_TEMPLATE(variance, RealT, test_types) { const RealT tol = make_tolerance(); - const RealT probs[] = {0.2, 0.3, 0.5}; - const RealT rates[] = {0.5, 1.0, 1.5}; - const std::size_t n = sizeof(probs)/sizeof(RealT); + const RealT probs[] = { static_cast(0.2L), static_cast(0.3L), static_cast(0.5L) }; + const RealT rates[] = { static_cast(0.5L), static_cast(1.0L), static_cast(1.5L) }; + const std::size_t n = sizeof(probs) / sizeof(RealT); boost::math::hyperexponential_distribution dist(probs, probs+n, rates, rates+n); @@ -226,14 +225,13 @@ void test_variance() BOOST_CHECK_CLOSE( boost::math::variance(dist), static_cast(1.5766666666666673), tol ); } -template -void test_kurtosis() +BOOST_AUTO_TEST_CASE_TEMPLATE(kurtosis, RealT, test_types) { const RealT tol = make_tolerance(); - const RealT probs[] = {0.2, 0.3, 0.5}; - const RealT rates[] = {0.5, 1.0, 1.5}; - const std::size_t n = sizeof(probs)/sizeof(RealT); + const RealT probs[] = { static_cast(0.2L), static_cast(0.3L), static_cast(0.5L) }; + const RealT rates[] = { static_cast(0.5L), static_cast(1.0L), static_cast(1.5L) }; + const std::size_t n = sizeof(probs) / sizeof(RealT); boost::math::hyperexponential_distribution dist(probs, probs+n, rates, rates+n); @@ -242,14 +240,13 @@ void test_kurtosis() BOOST_CHECK_CLOSE( boost::math::kurtosis_excess(dist), static_cast(19.75073861680871)-static_cast(3), tol ); } -template -void test_skewness() +BOOST_AUTO_TEST_CASE_TEMPLATE(skewness, RealT, test_types) { const RealT tol = make_tolerance(); - const RealT probs[] = {0.2, 0.3, 0.5}; - const RealT rates[] = {0.5, 1.0, 1.5}; - const std::size_t n = sizeof(probs)/sizeof(RealT); + const RealT probs[] = { static_cast(0.2L), static_cast(0.3L), static_cast(0.5L) }; + const RealT rates[] = { static_cast(0.5L), static_cast(1.0L), static_cast(1.5L) }; + const std::size_t n = sizeof(probs) / sizeof(RealT); boost::math::hyperexponential_distribution dist(probs, probs+n, rates, rates+n); @@ -257,91 +254,16 @@ void test_skewness() BOOST_CHECK_CLOSE( boost::math::skewness(dist), static_cast(3.181138744996378), tol ); } -template -void test_mode() +BOOST_AUTO_TEST_CASE_TEMPLATE(mode, RealT, test_types) { const RealT tol = make_tolerance(); - const RealT probs[] = {0.2, 0.3, 0.5}; - const RealT rates[] = {0.5, 1.0, 1.5}; - const std::size_t n = sizeof(probs)/sizeof(RealT); + const RealT probs[] = { static_cast(0.2L), static_cast(0.3L), static_cast(0.5L) }; + const RealT rates[] = { static_cast(0.5L), static_cast(1.0L), static_cast(1.5L) }; + const std::size_t n = sizeof(probs) / sizeof(RealT); boost::math::hyperexponential_distribution dist(probs, probs+n, rates, rates+n); BOOST_CHECK_CLOSE( boost::math::mode(dist), static_cast(0), tol ); } - -BOOST_AUTO_TEST_CASE( range ) -{ - test_range(); - test_range(); - //test_range(); -} - -BOOST_AUTO_TEST_CASE( support ) -{ - test_support(); - test_support(); -} - -BOOST_AUTO_TEST_CASE( pdf ) -{ - test_pdf(); - test_pdf(); -} - -BOOST_AUTO_TEST_CASE( cdf ) -{ - test_cdf(); - test_cdf(); -} - -BOOST_AUTO_TEST_CASE( quantile ) -{ - test_quantile(); - test_quantile(); -} - -BOOST_AUTO_TEST_CASE( ccdf ) -{ - test_ccdf(); - test_ccdf(); -} - -BOOST_AUTO_TEST_CASE( cquantile ) -{ - test_cquantile(); - test_cquantile(); -} - -BOOST_AUTO_TEST_CASE( mean ) -{ - test_mean(); - test_mean(); -} - -BOOST_AUTO_TEST_CASE( variance ) -{ - test_variance(); - test_variance(); -} - -BOOST_AUTO_TEST_CASE( kurtosis ) -{ - test_kurtosis(); - test_kurtosis(); -} - -BOOST_AUTO_TEST_CASE( skewness ) -{ - test_skewness(); - test_skewness(); -} - -BOOST_AUTO_TEST_CASE( mode ) -{ - test_mode(); - test_mode(); -} -