Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/src/catch2
diff options
context:
space:
mode:
authorMartin Hořeňovský2023-02-26 00:14:32 +0100
committerMartin Hořeňovský2023-02-26 00:14:32 +0100
commit6fbb3f07235311d0c228b17b52406343a7aed8f2 (patch)
tree9c1d0397f24cef4b8db3b27e85beea113ec8773a /src/catch2
parent9ff3cde87b1d8c61d2d97c34bdc71f0ec0a34a9c (diff)
downloadcatch3-6fbb3f07235311d0c228b17b52406343a7aed8f2.tar.gz
Add IsNaN matcher
Diffstat (limited to 'src/catch2')
-rw-r--r--src/catch2/matchers/catch_matchers_floating_point.cpp14
-rw-r--r--src/catch2/matchers/catch_matchers_floating_point.hpp30
2 files changed, 36 insertions, 8 deletions
diff --git a/src/catch2/matchers/catch_matchers_floating_point.cpp b/src/catch2/matchers/catch_matchers_floating_point.cpp
index 719fb51f..6e596466 100644
--- a/src/catch2/matchers/catch_matchers_floating_point.cpp
+++ b/src/catch2/matchers/catch_matchers_floating_point.cpp
@@ -225,5 +225,17 @@ WithinRelMatcher WithinRel(float target) {
}
-} // namespace Matchers
+
+bool IsNaNMatcher::match( double const& matchee ) const {
+ return std::isnan( matchee );
+}
+
+std::string IsNaNMatcher::describe() const {
+ using namespace std::string_literals;
+ return "is NaN"s;
+}
+
+IsNaNMatcher IsNaN() { return IsNaNMatcher(); }
+
+ } // namespace Matchers
} // namespace Catch
diff --git a/src/catch2/matchers/catch_matchers_floating_point.hpp b/src/catch2/matchers/catch_matchers_floating_point.hpp
index abdaf159..76816633 100644
--- a/src/catch2/matchers/catch_matchers_floating_point.hpp
+++ b/src/catch2/matchers/catch_matchers_floating_point.hpp
@@ -27,6 +27,11 @@ namespace Matchers {
double m_margin;
};
+ //! Creates a matcher that accepts numbers within certain range of target
+ WithinAbsMatcher WithinAbs( double target, double margin );
+
+
+
class WithinUlpsMatcher final : public MatcherBase<double> {
public:
WithinUlpsMatcher( double target,
@@ -40,6 +45,13 @@ namespace Matchers {
Detail::FloatingPointKind m_type;
};
+ //! Creates a matcher that accepts doubles within certain ULP range of target
+ WithinUlpsMatcher WithinULP(double target, uint64_t maxUlpDiff);
+ //! Creates a matcher that accepts floats within certain ULP range of target
+ WithinUlpsMatcher WithinULP(float target, uint64_t maxUlpDiff);
+
+
+
// Given IEEE-754 format for floats and doubles, we can assume
// that float -> double promotion is lossless. Given this, we can
// assume that if we do the standard relative comparison of
@@ -56,13 +68,6 @@ namespace Matchers {
double m_epsilon;
};
- //! Creates a matcher that accepts doubles within certain ULP range of target
- WithinUlpsMatcher WithinULP(double target, uint64_t maxUlpDiff);
- //! Creates a matcher that accepts floats within certain ULP range of target
- WithinUlpsMatcher WithinULP(float target, uint64_t maxUlpDiff);
- //! Creates a matcher that accepts numbers within certain range of target
- WithinAbsMatcher WithinAbs(double target, double margin);
-
//! Creates a matcher that accepts doubles within certain relative range of target
WithinRelMatcher WithinRel(double target, double eps);
//! Creates a matcher that accepts doubles within 100*DBL_EPS relative range of target
@@ -72,6 +77,17 @@ namespace Matchers {
//! Creates a matcher that accepts floats within 100*FLT_EPS relative range of target
WithinRelMatcher WithinRel(float target);
+
+
+ class IsNaNMatcher final : public MatcherBase<double> {
+ public:
+ IsNaNMatcher() = default;
+ bool match( double const& matchee ) const override;
+ std::string describe() const override;
+ };
+
+ IsNaNMatcher IsNaN();
+
} // namespace Matchers
} // namespace Catch