diff --git a/include/lest/lest.hpp b/include/lest/lest.hpp index 3b1f569..0db8c18 100644 --- a/include/lest/lest.hpp +++ b/include/lest/lest.hpp @@ -392,6 +392,11 @@ class approx friend bool operator != ( double lhs, approx const & rhs ) { return !operator==( lhs, rhs ); } friend bool operator != ( approx const & lhs, double rhs ) { return !operator==( rhs, lhs ); } + friend bool operator <= ( double lhs, approx const & rhs ) { return lhs < rhs.magnitude_ || lhs == rhs; } + friend bool operator <= ( approx const & lhs, double rhs ) { return lhs.magnitude_ < rhs || lhs == rhs; } + friend bool operator >= ( double lhs, approx const & rhs ) { return lhs > rhs.magnitude_ || lhs == rhs; } + friend bool operator >= ( approx const & lhs, double rhs ) { return lhs.magnitude_ > rhs || lhs == rhs; } + private: double epsilon_; double scale_; diff --git a/include/lest/lest_cpp03.hpp b/include/lest/lest_cpp03.hpp index f79554f..77e9c19 100644 --- a/include/lest/lest_cpp03.hpp +++ b/include/lest/lest_cpp03.hpp @@ -452,6 +452,11 @@ class approx friend bool operator != ( double lhs, approx const & rhs ) { return !operator==( lhs, rhs ); } friend bool operator != ( approx const & lhs, double rhs ) { return !operator==( rhs, lhs ); } + friend bool operator <= ( double lhs, approx const & rhs ) { return lhs < rhs.magnitude_ || lhs == rhs; } + friend bool operator <= ( approx const & lhs, double rhs ) { return lhs.magnitude_ < rhs || lhs == rhs; } + friend bool operator >= ( double lhs, approx const & rhs ) { return lhs > rhs.magnitude_ || lhs == rhs; } + friend bool operator >= ( approx const & lhs, double rhs ) { return lhs.magnitude_ > rhs || lhs == rhs; } + private: double epsilon_; double scale_; diff --git a/test/test_lest.cpp b/test/test_lest.cpp index 5f40169..e91f589 100644 --- a/test/test_lest.cpp +++ b/test/test_lest.cpp @@ -501,13 +501,20 @@ const lest::test specification[] = CASE( "Approximate compares properly" ) { EXPECT( 1.23 == approx( 1.23 ) ); + EXPECT( 1.23 <= approx( 1.23 ) ); + EXPECT( 1.23 >= approx( 1.23 ) ); EXPECT( 1.23 != approx( 1.24 ) ); + + EXPECT_NOT( 1.24 <= approx( 1.23 ) ); + EXPECT_NOT( 1.23 >= approx( 1.24 ) ); }, CASE( "Approximate using epsilon compares properly" ) { - EXPECT( 1.23 != approx( 1.231 ) ); - EXPECT( 1.23 == approx( 1.231 ).epsilon( 0.1 ) ); + EXPECT( 1.23 != approx( 1.231 ) ); + EXPECT( 1.231 >= approx( 1.23 ) ); + EXPECT( 1.23 == approx( 1.231 ).epsilon( 0.1 ) ); + EXPECT( 1.23 <= approx( 1.231 ).epsilon( 0.1 ) ); }, CASE( "Approximate using custom epsilon compares properly" ) diff --git a/test/test_lest_cpp03.cpp b/test/test_lest_cpp03.cpp index d455ab2..f6915ec 100644 --- a/test/test_lest_cpp03.cpp +++ b/test/test_lest_cpp03.cpp @@ -524,13 +524,20 @@ CASE( "Has single expression evaluation" ) CASE( "Approximate compares properly [approx][basic]" ) { EXPECT( 1.23 == approx( 1.23 ) ); + EXPECT( 1.23 <= approx( 1.23 ) ); + EXPECT( 1.23 >= approx( 1.23 ) ); EXPECT( 1.23 != approx( 1.24 ) ); + + EXPECT_NOT( 1.24 <= approx( 1.23 ) ); + EXPECT_NOT( 1.23 >= approx( 1.24 ) ); } CASE( "Approximate using epsilon compares properly [approx][epsilon]" ) { - EXPECT( 1.23 != approx( 1.231 ) ); - EXPECT( 1.23 == approx( 1.231 ).epsilon( 0.1 ) ); + EXPECT( 1.23 != approx( 1.231 ) ); + EXPECT( 1.231 >= approx( 1.23 ) ); + EXPECT( 1.23 == approx( 1.231 ).epsilon( 0.1 ) ); + EXPECT( 1.23 <= approx( 1.231 ).epsilon( 0.1 ) ); } CASE( "Approximate using custom epsilon compares properly [approx][custom]" )