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

Allow epsilon and scale to be specified

Commit
dfea75fc05432e4704c9de4f7058b594db14a6dd
Author
Phil Nash ·
Parents
d7b8b01f3e68

Files · Download .tar.gz

Changes

 include/internal/catch_approx.hpp | 37 +++++++++++++++++++++++++++++++++----
 1 file changed, 33 insertions(+), 4 deletions(-)

diff --git a/include/internal/catch_approx.hpp b/include/internal/catch_approx.hpp
index c77f8786..a8d540f2 100644
--- a/include/internal/catch_approx.hpp
+++ b/include/internal/catch_approx.hpp
@@ -15,6 +15,7 @@
 #include "catch_capture.hpp"
 
 #include <cmath>
+#include <limits>
 
 namespace Catch
 {
@@ -28,7 +29,7 @@ namespace Catch
             (
                 double d
             )
-            :   m_epsilon( 1e-10 ),
+            :   m_epsilon( std::numeric_limits<double>::epsilon() ),
                 m_scale( 1.0 ),
                 m_d( d )
             {
@@ -56,7 +57,37 @@ namespace Catch
             {
                 return !operator==( lhs, rhs );
             }
+
+
+            ///////////////////////////////////////////////////////////////////////////
+            Approx& epsilon
+            (
+                double newEpsilon
+            )
+            {
+                m_epsilon = newEpsilon;
+                return *this;
+            }
+            
+            ///////////////////////////////////////////////////////////////////////////
+            Approx& scale
+            (
+                double newScale
+            )
+            {
+                m_scale = newScale;
+                return *this;
+            }
+            
+            ///////////////////////////////////////////////////////////////////////////
+            std::string toString() const
+            {
+                std::ostringstream oss;
+                oss << "Approx( " << m_d << ")";
+                return oss.str();
+            }
             
+        private:
             double m_epsilon;
             double m_scale;
             double m_d;
@@ -70,9 +101,7 @@ namespace Catch
         const Detail::Approx& value
     )
     {
-        std::ostringstream oss;
-        oss << "Approx( " << value.m_d << ")";
-        return oss.str();
+        return value.toString();
     }
     
 } // end namespace Catch