From cae44d8ace757609f31af1083e0c792f1c0a8e81 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Fri, 3 Jun 2011 18:56:47 +0100 Subject: [PATCH] Made Approx a little more forgiving (to 100& epsilon of float) and added some more tests for it --- 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::epsilon() ), + : m_epsilon( std::numeric_limits::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 ) ); }