mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 21:36:11 +01:00
Made Approx a little more forgiving (to 100& epsilon of float) and added some more tests for it
This commit is contained in:
parent
f5668fafd9
commit
cae44d8ace
@ -29,7 +29,7 @@ namespace Catch
|
||||
(
|
||||
double d
|
||||
)
|
||||
: m_epsilon( std::numeric_limits<double>::epsilon() ),
|
||||
: m_epsilon( std::numeric_limits<float>::epsilon()*100 ),
|
||||
m_scale( 1.0 ),
|
||||
m_d( d )
|
||||
{
|
||||
|
@ -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 ) );
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user