From 3dcc9098033b5c38f849a0fef419d4e43caea69c Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Thu, 22 Feb 2024 11:56:17 +0000 Subject: [PATCH] Chebyshev coverage improvements. --- include/boost/math/special_functions/binomial.hpp | 2 +- test/chebyshev_test.cpp | 7 +++++++ test/math_unit_test.hpp | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/include/boost/math/special_functions/binomial.hpp b/include/boost/math/special_functions/binomial.hpp index 2220b2364..e776a90bb 100644 --- a/include/boost/math/special_functions/binomial.hpp +++ b/include/boost/math/special_functions/binomial.hpp @@ -26,7 +26,7 @@ T binomial_coefficient(unsigned n, unsigned k, const Policy& pol) static const char* function = "boost::math::binomial_coefficient<%1%>(unsigned, unsigned)"; if(k > n) return policies::raise_domain_error(function, "The binomial coefficient is undefined for k > n, but got k = %1%.", static_cast(k), pol); - T result; + T result; // LCOV_EXCL_LINE if((k == 0) || (k == n)) return static_cast(1); if((k == 1) || (k == n-1)) diff --git a/test/chebyshev_test.cpp b/test/chebyshev_test.cpp index be9323f2b..84117718c 100644 --- a/test/chebyshev_test.cpp +++ b/test/chebyshev_test.cpp @@ -85,6 +85,13 @@ void test_clenshaw_recurrence() std::array c5 = { {0, 0, 0, 0, 0, 1} }; std::array c6 = { {0, 0, 0, 0, 0, 0, 1} }; + // + // Error handling checks: + // + CHECK_THROW(chebyshev_clenshaw_recurrence(c0.data(), c0.size(), Real(-1), Real(1), Real(-2)), std::domain_error); + CHECK_THROW(chebyshev_clenshaw_recurrence(c0.data(), c0.size(), Real(-1), Real(1), Real(2)), std::domain_error); + CHECK_EQUAL(chebyshev_clenshaw_recurrence(c0.data(), 0, Real(-1), Real(1), Real(0.5)), Real(0)); + Real x = -1; // It's not clear from this test which one is more accurate; higher precision cast testing is required, and is done elsewhere: int ulps = 50; diff --git a/test/math_unit_test.hpp b/test/math_unit_test.hpp index 9554c38a5..648f7de9c 100644 --- a/test/math_unit_test.hpp +++ b/test/math_unit_test.hpp @@ -377,6 +377,18 @@ bool check_true(bool condition, std::string const & filename, std::string const return true; } +void report_non_throw(const std::string& file, int line) +{ + std::cerr << "Expected exception not thrown in test at: " << file << ":" << line << std::endl; + ++detail::global_error_count; +} + +void report_incorrect_throw(const std::string& file, int line) +{ + std::cerr << "Exception of the wrong type thrown in test at: " << file << ":" << line << std::endl; + ++detail::global_error_count; +} + int report_errors() { if (detail::global_error_count > 0) @@ -418,4 +430,6 @@ int report_errors() #define CHECK_TRUE(X) boost::math::test::check_true((X), __FILE__, __func__, __LINE__) +#define CHECK_THROW(x, what) try{ x; boost::math::test::report_non_throw(__FILE__, __LINE__); }catch(const what&){} catch(...){ boost::math::test::report_incorrect_throw(__FILE__, __LINE__); } + #endif