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

Factored Approx out into own file

Commit
d7c203c3e9c318fc50d64763fad25b75f72d3db1
Author
Phil Nash ·
Parents
95419e935cd5

Files · Download .tar.gz

Changes

 include/catch.hpp                                  |  1 +
 include/internal/catch_approx.hpp                  | 88 ++++++++++++++++++++++
 include/internal/catch_capture.hpp                 | 68 +----------------
 .../XCode/CatchSelfTest.xcodeproj/project.pbxproj  |  9 +++
 4 files changed, 100 insertions(+), 66 deletions(-)

diff --git a/include/catch.hpp b/include/catch.hpp
index 57fd82c0..c1b761df 100644
--- a/include/catch.hpp
+++ b/include/catch.hpp
@@ -29,6 +29,7 @@
 #include "internal/catch_section.hpp"
 #include "internal/catch_generators.hpp"
 #include "internal/catch_interfaces_exception.h"
+#include "internal/catch_approx.hpp"
 
 #ifdef __OBJC__
 #include "internal/catch_objc.hpp"
diff --git a/include/internal/catch_approx.hpp b/include/internal/catch_approx.hpp
new file mode 100644
index 00000000..538441a2
--- /dev/null
+++ b/include/internal/catch_approx.hpp
@@ -0,0 +1,88 @@
+/*
+ *  catch_approx.hpp
+ *  Catch
+ *
+ *  Created by Phil on 28/04/2011.
+ *  Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
+ *
+ *  Distributed under the Boost Software License, Version 1.0. (See accompanying
+ *  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ *
+ */
+#ifndef TWOBLUECUBES_CATCH_APPROX_HPP_INCLUDED
+#define TWOBLUECUBES_CATCH_APPROX_HPP_INCLUDED
+
+#include "catch_capture.hpp"
+
+#include <cmath>
+
+namespace Catch
+{
+    
+    // !TBD Need to clean this all up
+#define CATCH_absTol 1e-10
+#define CATCH_relTol 1e-10
+    
+    inline double catch_max( double x, double y )
+    {
+        return x > y ? x : y;
+    }
+    namespace Detail
+    {
+        class Approx
+        {
+        public:
+            ///////////////////////////////////////////////////////////////////////////
+            // !TBD more generic
+            explicit Approx
+            (
+             double d
+             )
+            : m_d( d )
+            {
+            }
+            
+            ///////////////////////////////////////////////////////////////////////////
+            template<typename T>
+            friend bool operator == 
+            (
+             const T& lhs, 
+             const Approx& rhs
+             )
+            {
+                // !TBD Use proper tolerance
+                // From: http://realtimecollisiondetection.net/blog/?p=89
+                // see also: http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm
+                return fabs( lhs - rhs.m_d ) <= catch_max( CATCH_absTol, CATCH_relTol * catch_max( fabs(lhs), fabs(rhs.m_d) ) );
+            }
+            
+            ///////////////////////////////////////////////////////////////////////////
+            template<typename T>
+            friend bool operator != 
+            (
+             const T& lhs, 
+             const Approx& rhs
+             )
+            {
+                return ! operator==( lhs, rhs );
+            }
+            
+            double m_d;
+        };
+    }
+  
+    ///////////////////////////////////////////////////////////////////////////////
+    template<>
+    inline std::string toString<Detail::Approx>
+    (
+        const Detail::Approx& value
+    )
+    {
+        std::ostringstream oss;
+        oss << "Approx( " << value.m_d << ")";
+        return oss.str();
+    }
+    
+} // end namespace Catch
+
+#endif // TWOBLUECUBES_CATCH_APPROX_HPP_INCLUDED
diff --git a/include/internal/catch_capture.hpp b/include/internal/catch_capture.hpp
index 6fcf496a..9db8503d 100644
--- a/include/internal/catch_capture.hpp
+++ b/include/internal/catch_capture.hpp
@@ -17,8 +17,9 @@
 #include "catch_interfaces_capture.h"
 #include "catch_debugger.hpp"
 #include "catch_evaluate.hpp"
+#include "catch_hub.h"
+#include "catch_common.h"
 #include <sstream>
-#include <cmath>
 
 namespace Catch
 {
@@ -642,72 +643,7 @@ public:
 private:
     std::ostringstream m_oss;
 };
-    
-    
-// !TBD Need to clean this all up
-#define CATCH_absTol 1e-10
-#define CATCH_relTol 1e-10
-
-inline double catch_max( double x, double y )
-{
-    return x > y ? x : y;
-}
-namespace Detail
-{
-    class Approx
-    {
-    public:
-        ///////////////////////////////////////////////////////////////////////////
-        // !TBD more generic
-        explicit Approx
-        (
-            double d
-        )
-        : m_d( d )
-        {
-        }
-
-        ///////////////////////////////////////////////////////////////////////////
-        template<typename T>
-        friend bool operator == 
-        (
-            const T& lhs, 
-            const Approx& rhs
-        )
-        {
-            // !TBD Use proper tolerance
-            // From: http://realtimecollisiondetection.net/blog/?p=89
-            // see also: http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm
-            return fabs( lhs - rhs.m_d ) <= catch_max( CATCH_absTol, CATCH_relTol * catch_max( fabs(lhs), fabs(rhs.m_d) ) );
-        }
         
-        ///////////////////////////////////////////////////////////////////////////
-        template<typename T>
-        friend bool operator != 
-        (
-            const T& lhs, 
-            const Approx& rhs
-        )
-        {
-            return ! operator==( lhs, rhs );
-        }
-        
-        double m_d;
-    };
-}
-    
-///////////////////////////////////////////////////////////////////////////////
-template<>
-    inline std::string toString<Detail::Approx>
-(
-    const Detail::Approx& value
-)
-{
-    std::ostringstream oss;
-    oss << "Approx( " << value.m_d << ")";
-    return oss.str();
-}
-
 ///////////////////////////////////////////////////////////////////////////////
 // This is just here to avoid compiler warnings with macro constants
 inline bool isTrue
diff --git a/projects/XCode/CatchSelfTest.xcodeproj/project.pbxproj b/projects/XCode/CatchSelfTest.xcodeproj/project.pbxproj
index 11ca60b2..bc32fec5 100644
--- a/projects/XCode/CatchSelfTest.xcodeproj/project.pbxproj
+++ b/projects/XCode/CatchSelfTest.xcodeproj/project.pbxproj
@@ -75,6 +75,7 @@
 		4A060D14136203B800BBA8F8 /* catch_reporter_registrars.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_reporter_registrars.hpp; path = ../../include/internal/catch_reporter_registrars.hpp; sourceTree = SOURCE_ROOT; };
 		4A060D15136203B800BBA8F8 /* catch_xmlwriter.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_xmlwriter.hpp; path = ../../include/internal/catch_xmlwriter.hpp; sourceTree = SOURCE_ROOT; };
 		4A060D16136203B800BBA8F8 /* catch_generators_impl.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_generators_impl.hpp; path = ../../include/internal/catch_generators_impl.hpp; sourceTree = SOURCE_ROOT; };
+		4A1A22AF136946E0002FDDE0 /* catch_approx.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_approx.hpp; path = ../../include/internal/catch_approx.hpp; sourceTree = SOURCE_ROOT; };
 		8DD76F6C0486A84900D96B5E /* Test */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = Test; sourceTree = BUILT_PRODUCTS_DIR; };
 		C6859E8B029090EE04C91782 /* Test.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = Test.1; sourceTree = "<group>"; };
 /* End PBXFileReference section */
@@ -149,6 +150,7 @@
 				4A060CFD136203B800BBA8F8 /* catch_runner_impl.hpp */,
 				4A060D0C136203B800BBA8F8 /* catch_interfaces_runner.h */,
 				4A060D0D136203B800BBA8F8 /* catch_generators.hpp */,
+				4A1A22AF136946E0002FDDE0 /* catch_approx.hpp */,
 			);
 			name = "Running & Results";
 			sourceTree = "<group>";
@@ -274,7 +276,14 @@
 			isa = PBXProject;
 			buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "CatchSelfTest" */;
 			compatibilityVersion = "Xcode 3.1";
+			developmentRegion = English;
 			hasScannedForEncodings = 1;
+			knownRegions = (
+				English,
+				Japanese,
+				French,
+				German,
+			);
 			mainGroup = 08FB7794FE84155DC02AAC07 /* Test */;
 			projectDirPath = "";
 			projectRoot = "";