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

Make Approx::operator() const

Closes #2273
Commit
ff0a5227caf84d466e3c9c8d6b58469d651e5268
Author
Martin Hořeňovský ·
Parents
54edab53bf38

Files · Download .tar.gz

Changes

 src/catch2/catch_approx.hpp                | 2 +-
 tests/SelfTest/UsageTests/Approx.tests.cpp | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/catch2/catch_approx.hpp b/src/catch2/catch_approx.hpp
index 8f0e6327..7c3a17c0 100644
--- a/src/catch2/catch_approx.hpp
+++ b/src/catch2/catch_approx.hpp
@@ -30,7 +30,7 @@ namespace Catch {
         Approx operator-() const;
 
         template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
-        Approx operator()( T const& value ) {
+        Approx operator()( T const& value ) const {
             Approx approx( static_cast<double>(value) );
             approx.m_epsilon = m_epsilon;
             approx.m_margin = m_margin;
diff --git a/tests/SelfTest/UsageTests/Approx.tests.cpp b/tests/SelfTest/UsageTests/Approx.tests.cpp
index 96f9706d..1ae5fe04 100644
--- a/tests/SelfTest/UsageTests/Approx.tests.cpp
+++ b/tests/SelfTest/UsageTests/Approx.tests.cpp
@@ -209,3 +209,10 @@ TEST_CASE( "Comparison with explicitly convertible types", "[Approx]" )
   REQUIRE(Approx(11.0) >= td);
 
 }
+
+TEST_CASE("Approx::operator() is const correct", "[Approx][.approvals]") {
+    const Approx ap = Approx(0.0).margin(0.01);
+
+    // As long as this compiles, the test should be considered passing
+    REQUIRE(1.0 == ap(1.0));
+}