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

Made Approx a little more forgiving (to 100& epsilon of float) and added some more tests for it

Commit
cae44d8ace757609f31af1083e0c792f1c0a8e81
Author
Phil Nash ·
Parents
f5668fafd988

Files · Download .tar.gz

Changes

 include/internal/catch_approx.hpp |  2 +-
 projects/SelfTest/ApproxTests.cpp | 41 ++++++++++++++++++++++++++++++++++++++-
 2 files changed, 41 insertions(+), 2 deletions(-)

diff --git a/include/internal/catch_approx.hpp b/include/internal/catch_approx.hpp
index 37d54f37..8a98a735 100644
--- a/include/internal/catch_approx.hpp
+++ b/include/internal/catch_approx.hpp
@@ -29,7 +29,7 @@ namespace Catch
             (
                 double d
             )
-            :   m_epsilon( std::numeric_limits<double>::epsilon() ),
+            :   m_epsilon( std::numeric_limits<float>::epsilon()*100 ),
                 m_scale( 1.0 ),
                 m_d( d )
             {
diff --git a/projects/SelfTest/ApproxTests.cpp b/projects/SelfTest/ApproxTests.cpp
index 2c5aa71b..cdab6019 100644
--- a/projects/SelfTest/ApproxTests.cpp
+++ b/projects/SelfTest/ApproxTests.cpp
@@ -41,5 +41,44 @@ TEST_CASE
     
     REQUIRE( d != Approx( 1.231 ) );
     REQUIRE( d == Approx( 1.231 ).epsilon( 0.1 ) );
-//    REQUIRE( d != Approx( 1.232 ).epsilon( 0.1 ) );
+}
+
+///////////////////////////////////////////////////////////////////////////////
+TEST_CASE
+(
+    "./succeeding/Approx/float", 
+    "Approximate comparisons with floats"
+)
+{
+    REQUIRE( 1.23f == Approx( 1.23f ) );
+    REQUIRE( 0.0f == Approx( 0.0f ) );
+}
+
+///////////////////////////////////////////////////////////////////////////////
+TEST_CASE
+(
+    "./succeeding/Approx/int", 
+    "Approximate comparisons with ints"
+)
+{
+    REQUIRE( 1 == Approx( 1 ) );
+    REQUIRE( 0 == Approx( 0 ) );
+}
+
+///////////////////////////////////////////////////////////////////////////////
+TEST_CASE
+(
+    "./succeeding/Approx/mixed", 
+    "Approximate comparisons with mixed numeric types"
+)
+{
+    const double dZero = 0;
+    const double dSmall = 0.00001;
+    const double dMedium = 1.234;
+    
+    REQUIRE( 1.0f == Approx( 1 ) );
+    REQUIRE( 0 == Approx( dZero) );
+    REQUIRE( 0 == Approx( dSmall ).epsilon( 0.001 ) );
+    REQUIRE( 1.234f == Approx( dMedium ) );
+    REQUIRE( dMedium == Approx( 1.234f ) );
 }