Add float/int literal for Approx

This commit is contained in:
Henry Schreiner 2018-05-21 15:42:40 +02:00 committed by Martin Hořeňovský
parent d6c7392b24
commit 283e2e6d41
8 changed files with 177 additions and 8 deletions

View file

@ -33,8 +33,21 @@ namespace { namespace ApproxTests {
#endif
using namespace Catch::literals;
///////////////////////////////////////////////////////////////////////////////
TEST_CASE( "A comparison that uses literals instead of the normal constructor", "[Approx]" ) {
double d = 1.23;
REQUIRE( d == 1.23_a );
REQUIRE( d != 1.22_a );
REQUIRE( -d == -1.23_a );
REQUIRE( d == 1.2_a .epsilon(.1) );
REQUIRE( d != 1.2_a .epsilon(.001) );
REQUIRE( d == 1_a .epsilon(.3) );
}
TEST_CASE( "Some simple comparisons between doubles", "[Approx]" ) {
double d = 1.23;
@ -42,6 +55,9 @@ TEST_CASE( "Some simple comparisons between doubles", "[Approx]" ) {
REQUIRE( d != Approx( 1.22 ) );
REQUIRE( d != Approx( 1.24 ) );
REQUIRE( d == 1.23_a );
REQUIRE( d != 1.22_a );
REQUIRE( Approx( d ) == 1.23 );
REQUIRE( Approx( d ) != 1.22 );
REQUIRE( Approx( d ) != 1.24 );