Add constructor arg checking to WithinAbsMatcher

Also tests :-)
This commit is contained in:
Martin Hořeňovský
2017-12-06 15:37:13 +01:00
parent d19b7292b3
commit 0c122c135d
6 changed files with 143 additions and 7 deletions

View File

@@ -79,7 +79,11 @@ namespace Catch {
namespace Matchers {
namespace Floating {
WithinAbsMatcher::WithinAbsMatcher(double target, double margin)
:m_target{ target }, m_margin{ margin } {}
:m_target{ target }, m_margin{ margin } {
if (m_margin < 0) {
throw std::domain_error("Allowed margin difference has to be >= 0");
}
}
// Performs equivalent check of std::fabs(lhs - rhs) <= margin
// But without the subtraction to allow for INFINITY in comparison
@@ -95,7 +99,7 @@ namespace Floating {
WithinUlpsMatcher::WithinUlpsMatcher(double target, int ulps, FloatingPointKind baseType)
:m_target{ target }, m_ulps{ ulps }, m_type{ baseType } {
if (m_ulps < 0) {
throw std::domain_error("Expected ulp difference has to be >0");
throw std::domain_error("Allowed ulp difference has to be >= 0");
}
}