Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

add support for inequalities

Commit
37e1e243093052b540de78dd50c78be51b5728d2
Author
Jonathan B. Coe ·
Committer
Martin Hořeňovský
Parents
5a4dde4b5d34

Files · Download .tar.gz

Changes

 include/internal/catch_approx.hpp | 20 ++++++++++++++++++++
 projects/SelfTest/ApproxTests.cpp | 30 ++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+)

diff --git a/include/internal/catch_approx.hpp b/include/internal/catch_approx.hpp
index f5dba61a..163d2680 100644
--- a/include/internal/catch_approx.hpp
+++ b/include/internal/catch_approx.hpp
@@ -58,6 +58,26 @@ namespace Detail {
             return !operator==( rhs, lhs );
         }
 
+        friend bool operator <= ( double lhs, Approx const& rhs )
+        {
+          return lhs < rhs.m_value || lhs == rhs;
+        }
+
+        friend bool operator <= ( Approx const& lhs, double rhs )
+        {
+          return lhs.m_value < rhs || lhs == rhs;
+        }
+
+        friend bool operator >= ( double lhs, Approx const& rhs )
+        {
+          return lhs > rhs.m_value || lhs == rhs;
+        }
+
+        friend bool operator >= ( Approx const& lhs, double rhs )
+        {
+          return lhs.m_value > rhs || lhs == rhs;
+        }
+
         Approx& epsilon( double newEpsilon ) {
             m_epsilon = newEpsilon;
             return *this;
diff --git a/projects/SelfTest/ApproxTests.cpp b/projects/SelfTest/ApproxTests.cpp
index 53656596..cd708f2d 100644
--- a/projects/SelfTest/ApproxTests.cpp
+++ b/projects/SelfTest/ApproxTests.cpp
@@ -39,6 +39,36 @@ TEST_CASE
     REQUIRE( d == Approx( 1.231 ).epsilon( 0.1 ) );
 }
 
+///////////////////////////////////////////////////////////////////////////////
+TEST_CASE
+(
+ "Less-than inequalities with different epsilons",
+ "[Approx]"
+)
+{
+  double d = 1.23;
+
+  REQUIRE( d <= Approx( 1.24 ) );
+  REQUIRE( d <= Approx( 1.23 ) );
+  REQUIRE_FALSE( d <= Approx( 1.22 ) );
+  REQUIRE( d <= Approx( 1.22 ).epsilon(0.1) );
+}
+
+///////////////////////////////////////////////////////////////////////////////
+TEST_CASE
+(
+ "Greater-than inequalities with different epsilons",
+ "[Approx]"
+)
+{
+  double d = 1.23;
+
+  REQUIRE( d >= Approx( 1.22 ) );
+  REQUIRE( d >= Approx( 1.23 ) );
+  REQUIRE_FALSE( d >= Approx( 1.24 ) );
+  REQUIRE( d >= Approx( 1.24 ).epsilon(0.1) );
+}
+
 ///////////////////////////////////////////////////////////////////////////////
 TEST_CASE
 (