Made Approx a little more forgiving (to 100& epsilon of float) and added some more tests for it

This commit is contained in:
Phil Nash 2011-06-03 18:56:47 +01:00
parent f5668fafd9
commit cae44d8ace
2 changed files with 41 additions and 2 deletions

View File

@ -29,7 +29,7 @@ namespace Catch
( (
double d double d
) )
: m_epsilon( std::numeric_limits<double>::epsilon() ), : m_epsilon( std::numeric_limits<float>::epsilon()*100 ),
m_scale( 1.0 ), m_scale( 1.0 ),
m_d( d ) m_d( d )
{ {

View File

@ -41,5 +41,44 @@ TEST_CASE
REQUIRE( d != Approx( 1.231 ) ); REQUIRE( d != Approx( 1.231 ) );
REQUIRE( d == Approx( 1.231 ).epsilon( 0.1 ) ); 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 ) );
} }