From 0ea29b7d28aac0ec38970481bac4b24a36b1f079 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Thu, 28 Apr 2011 08:28:03 +0100 Subject: [PATCH] Started adding tests for Approx --- include/internal/catch_approx.hpp | 24 +++++++++++++++++++++++- projects/SelfTest/ApproxTests.cpp | 31 +++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 projects/SelfTest/ApproxTests.cpp diff --git a/include/internal/catch_approx.hpp b/include/internal/catch_approx.hpp index a8d540f2..5630e3a2 100644 --- a/include/internal/catch_approx.hpp +++ b/include/internal/catch_approx.hpp @@ -47,6 +47,17 @@ namespace Catch return fabs( lhs - rhs.m_d ) < rhs.m_epsilon * (rhs.m_scale + (std::max)( fabs(lhs), fabs(rhs.m_d) ) ); } + /////////////////////////////////////////////////////////////////////////// + template + friend bool operator == + ( + const Approx& lhs, + const T& rhs + ) + { + return operator==( rhs, lhs ); + } + /////////////////////////////////////////////////////////////////////////// template friend bool operator != @@ -58,7 +69,18 @@ namespace Catch return !operator==( lhs, rhs ); } - + /////////////////////////////////////////////////////////////////////////// + template + friend bool operator != + ( + const Approx& lhs, + const T& rhs + ) + { + return !operator==( rhs, lhs ); + } + + /////////////////////////////////////////////////////////////////////////// Approx& epsilon ( diff --git a/projects/SelfTest/ApproxTests.cpp b/projects/SelfTest/ApproxTests.cpp new file mode 100644 index 00000000..be59ee8d --- /dev/null +++ b/projects/SelfTest/ApproxTests.cpp @@ -0,0 +1,31 @@ +/* + * ApproxTests.cpp + * Catch - Test + * + * Created by Phil on 28/04/2011. + * Copyright 2011 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.hpp" + +/////////////////////////////////////////////////////////////////////////////// +TEST_CASE +( + "./succeeding/Approx/simple", + "Some simple comparisons between doubles" + ) +{ + double d = 1.23; + + REQUIRE( d == Approx( 1.23 ) ); + REQUIRE( d != Approx( 1.22 ) ); + REQUIRE( d != Approx( 1.24 ) ); + + REQUIRE( Approx( d ) == 1.23 ); + REQUIRE( Approx( d ) != 1.22 ); + REQUIRE( Approx( d ) != 1.24 ); +}