Change the threshold param of near to be inclusive

I.e. it means the maximum allowed difference, similar to how other testing frameworks handle this and it allows a threshold of 0 to mean "equal"
This commit is contained in:
Alexander Grund 2022-01-06 15:38:29 +01:00
parent e26601672e
commit 98541eb5a7
No known key found for this signature in database
GPG key ID: AA48A0760367A42B
2 changed files with 4 additions and 3 deletions

View file

@ -87,7 +87,7 @@ struct near_constraint
template< typename Actual >
bool operator()( Actual actual ) const
{
return std::abs( actual - mock::unwrap_ref(expected_) ) < mock::unwrap_ref(threshold_) ;
return std::abs( actual - mock::unwrap_ref(expected_) ) <= mock::unwrap_ref(threshold_) ;
}
friend std::ostream& operator<<( std::ostream& s, const near_constraint& c )
@ -157,6 +157,7 @@ BOOST_AUTO_TEST_CASE( near_constraint_works_with_with_float_wrapper_and_cref )
MOCK_EXPECT( v.display ).once().with( near( std::cref( expected ), std::cref( threshold ) ) );
expected = 42;
threshold = 1;
c.add(0, 0);
c.add(41, 1);
}
}

View file

@ -106,7 +106,7 @@ namespace detail
# define MOCK_NEAR_DEFINED
#endif
MOCK_NARY_CONSTRAINT( near, 2, ( expected, tolerance ),
std::abs( actual - expected ) < tolerance )
std::abs( actual - expected ) <= tolerance )
#ifdef MOCK_NEAR_DEFINED
# pragma pop_macro( "near" )
#endif