Skip to content
Snippets Groups Projects
Commit 557929a0 authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Improve error messages and add bound violation tests

parent fe78cc8e
No related branches found
No related tags found
No related merge requests found
...@@ -202,14 +202,14 @@ class [[nodiscard]] Polynomial1D ...@@ -202,14 +202,14 @@ class [[nodiscard]] Polynomial1D
PUGS_INLINE PUGS_INLINE
double& coefficient(const size_t i) double& coefficient(const size_t i)
{ {
Assert(i < m_coefficients.size()); Assert(i < m_coefficients.size(), "invalid coefficient number");
return m_coefficients[i]; return m_coefficients[i];
} }
PUGS_INLINE PUGS_INLINE
const double& coefficient(const size_t i) const const double& coefficient(const size_t i) const
{ {
Assert(i < m_coefficients.size()); Assert(i < m_coefficients.size(), "invalid coefficient number");
return m_coefficients[i]; return m_coefficients[i];
} }
......
...@@ -254,6 +254,15 @@ TEST_CASE("Polynomial1D", "[analysis]") ...@@ -254,6 +254,15 @@ TEST_CASE("Polynomial1D", "[analysis]")
} }
#ifndef NDEBUG #ifndef NDEBUG
SECTION("checking for bounds validation") {} SECTION("checking for bounds validation")
{
Polynomial1D p({-1, 0, 0, 1});
REQUIRE_THROWS_AS(p.coefficient(4), AssertError);
const Polynomial1D q({-1, 0, 0, 1});
REQUIRE_THROWS_AS(q.coefficient(4), AssertError);
REQUIRE_THROWS_AS(Polynomial1D{std::vector<double>{}}, AssertError);
}
#endif // NDEBUG #endif // NDEBUG
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment