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
Split out non-templated Approx methods into cpp file
- Commit
edbe12276143fb27a7f98c1af0e6f25c8787aae2- Author
- Martin Hořeňovský ·
- Parents
0a614ee5ba46
Changes
CMakeLists.txt | 1 + include/internal/catch_approx.cpp | 39 +++++++++++++++++++++++++++++++++++++++ include/internal/catch_approx.hpp | 24 ++++-------------------- 3 files changed, 44 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2936a114..ff300ca7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -193,6 +193,7 @@ set(INTERNAL_HEADERS ${HEADER_DIR}/internal/catch_xmlwriter.hpp ) set(IMPL_SOURCES + ${HEADER_DIR}/internal/catch_approx.cpp ${HEADER_DIR}/internal/catch_assertionresult.cpp ${HEADER_DIR}/internal/catch_commandline.cpp ${HEADER_DIR}/internal/catch_common.cpp diff --git a/include/internal/catch_approx.cpp b/include/internal/catch_approx.cpp new file mode 100644 index 00000000..98fc7bce --- /dev/null +++ b/include/internal/catch_approx.cpp @@ -0,0 +1,39 @@ +/* + * Created by Martin on 19/07/2017. + * Copyright 2017 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) + */ + +#include "catch_approx.hpp" + +#include <limits> + +namespace Catch { +namespace Detail { + + Approx::Approx ( double value ) + : m_epsilon( std::numeric_limits<float>::epsilon()*100 ), + m_margin( 0.0 ), + m_scale( 1.0 ), + m_value( value ) + {} + + Approx Approx::custom() { + return Approx( 0 ); + } + + std::string Approx::toString() const { + std::ostringstream oss; + oss << "Approx( " << ::Catch::Detail::stringify( m_value ) << " )"; + return oss.str(); + } + +} // end namespace Detail + +std::string StringMaker<Catch::Detail::Approx>::convert(Catch::Detail::Approx const& value) { + return value.toString(); +} + +} // end namespace Catch diff --git a/include/internal/catch_approx.hpp b/include/internal/catch_approx.hpp index 4235d0bc..bb930a4b 100644 --- a/include/internal/catch_approx.hpp +++ b/include/internal/catch_approx.hpp @@ -20,18 +20,9 @@ namespace Detail { class Approx { public: - explicit Approx ( double value ) - : m_epsilon( std::numeric_limits<float>::epsilon()*100 ), - m_margin( 0.0 ), - m_scale( 1.0 ), - m_value( value ) - {} - - Approx( Approx const& other ) = default; + explicit Approx ( double value ); - static Approx custom() { - return Approx( 0 ); - } + static Approx custom(); template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type> Approx operator()( T value ) { @@ -111,12 +102,7 @@ namespace Detail { return *this; } - - std::string toString() const { - std::ostringstream oss; - oss << "Approx( " << ::Catch::Detail::stringify( m_value ) << " )"; - return oss.str(); - } + std::string toString() const; private: double m_epsilon; @@ -128,9 +114,7 @@ namespace Detail { template<> struct StringMaker<Catch::Detail::Approx> { - static std::string convert(Catch::Detail::Approx const& value) { - return value.toString(); - } + static std::string convert(Catch::Detail::Approx const& value); }; } // end namespace Catch