2
0
mirror of https://github.com/boostorg/math.git synced 2026-01-19 04:22:09 +00:00

Chebyshev coverage improvements.

This commit is contained in:
jzmaddock
2024-02-22 11:56:17 +00:00
parent 1cb31dfa11
commit 3dcc909803
3 changed files with 22 additions and 1 deletions

View File

@@ -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<T>(function, "The binomial coefficient is undefined for k > n, but got k = %1%.", static_cast<T>(k), pol);
T result;
T result; // LCOV_EXCL_LINE
if((k == 0) || (k == n))
return static_cast<T>(1);
if((k == 1) || (k == n-1))

View File

@@ -85,6 +85,13 @@ void test_clenshaw_recurrence()
std::array<Real, 6> c5 = { {0, 0, 0, 0, 0, 1} };
std::array<Real, 7> 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;

View File

@@ -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