From 3621b083e2edb096d6750124094b5efbf94adea8 Mon Sep 17 00:00:00 2001 From: sguazt Date: Fri, 22 Aug 2014 16:37:35 +0200 Subject: [PATCH] [distributions] Hyper-Exponential: registered tests and fixed some test-related issue. --- .../math/distributions/hyperexponential.hpp | 16 ++++++------ test/Jamfile.v2 | 2 ++ .../dist_hyperexponential_incl_test.cpp | 26 +++++++++++++++++++ 3 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 test/compile_test/dist_hyperexponential_incl_test.cpp diff --git a/include/boost/math/distributions/hyperexponential.hpp b/include/boost/math/distributions/hyperexponential.hpp index f81b2e89a..45162dda4 100644 --- a/include/boost/math/distributions/hyperexponential.hpp +++ b/include/boost/math/distributions/hyperexponential.hpp @@ -68,12 +68,12 @@ template bool iszero(T x) { #ifdef FP_ZERO - return boost::math::fpclassify(x) == FP_ZERO; + return (boost::math::fpclassify)(x) == FP_ZERO; // Alternatively, we could use std::fpclassify (but this is available from ISO C99) //return std::fpclassify(x) == FP_ZERO; #else - return = ((x < 0) ? bool(-x < (std::numeric_limits::min)()) - : bool(+x < (std::numeric_limits::min)())); + return ((x < 0) ? bool(-x < (std::numeric_limits::min)()) + : bool(+x < (std::numeric_limits::min)())); #endif // FP_ZERO } @@ -112,7 +112,7 @@ bool check_probabilities(char const* function, std::vector const& probabi { if (probabilities[i] < 0 || probabilities[i] > 1 - || !boost::math::isfinite(probabilities[i])) + || !(boost::math::isfinite)(probabilities[i])) { *presult = policies::raise_domain_error(function, "The elements of parameter \"probabilities\" must be >= 0 and <= 1, but at least one of them was: %1%.", @@ -142,7 +142,7 @@ bool check_rates(char const* function, std::vector const& rates, RealT* p for (std::size_t i = 0; i < n; ++i) { if (rates[i] <= 0 - || !boost::math::isfinite(rates[i])) + || !(boost::math::isfinite)(rates[i])) { *presult = policies::raise_domain_error(function, "The elements of parameter \"rates\" must be > 0, but at least one of them is: %1%.", @@ -173,7 +173,7 @@ bool check_dist(char const* function, std::vector const& probabilities, s template bool check_x(char const* function, RealT x, RealT* presult, PolicyT const& pol) { - if (x < 0 || boost::math::isnan(x)) + if (x < 0 || (boost::math::isnan)(x)) { *presult = policies::raise_domain_error(function, "The random variable must be >= 0, but is: %1%.", x, pol); return false; @@ -184,7 +184,7 @@ bool check_x(char const* function, RealT x, RealT* presult, PolicyT const& pol) template bool check_probability(char const* function, RealT p, RealT* presult, PolicyT const& pol) { - if (p < 0 || p > 1 || boost::math::isnan(p)) + if (p < 0 || p > 1 || (boost::math::isnan)(p)) { *presult = policies::raise_domain_error(function, "The probability be >= 0 and <= 1, but is: %1%.", p, pol); return false; @@ -470,7 +470,7 @@ RealT variance(hyperexponential_distribution const& dist) result += probs[i]/(rates[i]*rates[i]); } - const RealT mean = mean(dist); + const RealT mean = boost::math::mean(dist); result = 2.0*result-mean*mean; diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 19392dc44..131943151 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -211,6 +211,7 @@ run test_gamma_dist.cpp pch ../../test/build//boost_unit_test_framework ; run test_geometric.cpp ../../test/build//boost_unit_test_framework ; run test_hankel.cpp ../../test/build//boost_unit_test_framework ; run test_hermite.cpp test_instances//test_instances pch_light ../../test/build//boost_unit_test_framework ; +run test_hyperexponential_dist.cpp ../../test/build//boost_unit_test_framework ; run test_hypergeometric_dist.cpp ../../test/build//boost_unit_test_framework : # command line : # input files @@ -746,6 +747,7 @@ run compile_test/dist_fisher_f_incl_test.cpp compile_test_main ; run compile_test/dist_gamma_incl_test.cpp compile_test_main ; run compile_test/dist_inv_gamma_incl_test.cpp compile_test_main ; run compile_test/dist_inv_chi_sq_incl_test.cpp compile_test_main ; +run compile_test/dist_hyperexponential_incl_test.cpp compile_test_main ; run compile_test/dist_hypergeo_incl_test.cpp compile_test_main ; run compile_test/dist_laplace_incl_test.cpp compile_test_main ; run compile_test/dist_logistic_incl_test.cpp compile_test_main ; diff --git a/test/compile_test/dist_hyperexponential_incl_test.cpp b/test/compile_test/dist_hyperexponential_incl_test.cpp new file mode 100644 index 000000000..4de172d32 --- /dev/null +++ b/test/compile_test/dist_hyperexponential_incl_test.cpp @@ -0,0 +1,26 @@ +// Copyright 2014 Marco Guazzone (marco.guazzone@gmail.com) +// +// 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) +// +// Basic sanity check that header +// #includes all the files that it needs to. +// +#include +// +// Note this header includes no other headers, this is +// important if this test is to be meaningful: +// +#include "test_compile_result.hpp" + +void compile_and_link_test() +{ + TEST_DIST_FUNC(hyperexponential) +} + +template class boost::math::hyperexponential_distribution >; +template class boost::math::hyperexponential_distribution >; +#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS +template class boost::math::hyperexponential_distribution >; +#endif