Started adding tests for Approx

This commit is contained in:
Phil Nash 2011-04-28 08:28:03 +01:00
parent dfea75fc05
commit 0ea29b7d28
2 changed files with 54 additions and 1 deletions

View File

@ -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) ) ); return fabs( lhs - rhs.m_d ) < rhs.m_epsilon * (rhs.m_scale + (std::max)( fabs(lhs), fabs(rhs.m_d) ) );
} }
///////////////////////////////////////////////////////////////////////////
template<typename T>
friend bool operator ==
(
const Approx& lhs,
const T& rhs
)
{
return operator==( rhs, lhs );
}
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
template<typename T> template<typename T>
friend bool operator != friend bool operator !=
@ -58,6 +69,17 @@ namespace Catch
return !operator==( lhs, rhs ); return !operator==( lhs, rhs );
} }
///////////////////////////////////////////////////////////////////////////
template<typename T>
friend bool operator !=
(
const Approx& lhs,
const T& rhs
)
{
return !operator==( rhs, lhs );
}
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
Approx& epsilon Approx& epsilon

View File

@ -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 );
}