mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Added floating point comparison constraints
git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@659 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
parent
c8072405c8
commit
8a6edd531e
4 changed files with 56 additions and 11 deletions
|
|
@ -8,6 +8,7 @@ Not yet released
|
||||||
* Officially documented MOCK_UNARY_CONSTRAINT and MOCK_BINARY_CONSTRAINT
|
* Officially documented MOCK_UNARY_CONSTRAINT and MOCK_BINARY_CONSTRAINT
|
||||||
* Added support for several sequences in 'in'
|
* Added support for several sequences in 'in'
|
||||||
* Added support for nullptr as constraint
|
* Added support for nullptr as constraint
|
||||||
|
* Added mock::close, mock::close_fraction, mock::small and mock::near constraints
|
||||||
|
|
||||||
[endsect]
|
[endsect]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -323,6 +323,10 @@ Constraints :
|
||||||
[[mock::greater( ['expected] )] [['actual] > ['expected]] [compares ['actual] to ['expected] using operator >]]
|
[[mock::greater( ['expected] )] [['actual] > ['expected]] [compares ['actual] to ['expected] using operator >]]
|
||||||
[[mock::less_equal( ['expected] )] [['actual] <= ['expected]] [compares ['actual] to ['expected] using operator <=]]
|
[[mock::less_equal( ['expected] )] [['actual] <= ['expected]] [compares ['actual] to ['expected] using operator <=]]
|
||||||
[[mock::greater_equal( ['expected] )] [['actual] >= ['expected]] [compares ['actual] to ['expected] using operator >=]]
|
[[mock::greater_equal( ['expected] )] [['actual] >= ['expected]] [compares ['actual] to ['expected] using operator >=]]
|
||||||
|
[[mock::near] [std::abs( ['actual] - ['expected] ) < ['arg]] [checks whether ['actual] is near ['expected]]]
|
||||||
|
[[mock::close] [boost::test_tools::check_is_close( ['actual], ['expected], boost::test_tools::percent_tolerance( ['arg] ) )] [checks whether ['actual] is close to ['expected], see [@http://www.boost.org/libs/test/doc/html/utf/testing-tools/floating_point_comparison.html Floating-point comparison algorithms] ]]
|
||||||
|
[[mock::close_fraction] [boost::test_tools::check_is_close( ['actual], ['expected], boost::test_tools::fraction_tolerance( ['arg] ) )] [checks whether ['actual] is close to ['expected], see [@http://www.boost.org/libs/test/doc/html/utf/testing-tools/floating_point_comparison.html Floating-point comparison algorithms] ]]
|
||||||
|
[[mock::small] [boost::test_tools::check_is_small( ['actual], ['expected] ) )] [checks whether ['actual] is small with a tolerance of ['expected], see [@http://www.boost.org/libs/test/doc/html/utf/testing-tools/floating_point_comparison.html Floating-point comparison algorithms] ]]
|
||||||
[[mock::call( ['expected] )] [['expected]( ['actual] )] [calls ['expected] as a functor returning a ['bool] and accepting ['actual] as parameter]]
|
[[mock::call( ['expected] )] [['expected]( ['actual] )] [calls ['expected] as a functor returning a ['bool] and accepting ['actual] as parameter]]
|
||||||
[[mock::same( ['expected] )] [&['actual] == &['expected]] [compares ['actual] to ['expected] by comparing their pointers]]
|
[[mock::same( ['expected] )] [&['actual] == &['expected]] [compares ['actual] to ['expected] by comparing their pointers]]
|
||||||
[[mock::assign( ['expected] )] [['actual] = ['expected], true
|
[[mock::assign( ['expected] )] [['actual] = ['expected], true
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ BOOST_AUTO_TEST_CASE( constraints_can_be_combined_using_the_and_operator )
|
||||||
mock::less( 0 ) && mock::greater( 0 );
|
mock::less( 0 ) && mock::greater( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( equal )
|
BOOST_AUTO_TEST_CASE( equal_constraint )
|
||||||
{
|
{
|
||||||
BOOST_CHECK( mock::equal( std::string( "string" ) ).c_( "string" ) );
|
BOOST_CHECK( mock::equal( std::string( "string" ) ).c_( "string" ) );
|
||||||
BOOST_CHECK( ! mock::equal( std::string( "string" ) ).c_( "not string" ) );
|
BOOST_CHECK( ! mock::equal( std::string( "string" ) ).c_( "not string" ) );
|
||||||
|
|
@ -57,7 +57,7 @@ BOOST_AUTO_TEST_CASE( equal )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( same )
|
BOOST_AUTO_TEST_CASE( same_constraint )
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
@ -86,7 +86,7 @@ BOOST_AUTO_TEST_CASE( same )
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( assign )
|
BOOST_AUTO_TEST_CASE( assign_constraint )
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
@ -149,7 +149,7 @@ BOOST_AUTO_TEST_CASE( assign )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( retrieve )
|
BOOST_AUTO_TEST_CASE( retrieve_constraint )
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
@ -235,14 +235,14 @@ namespace
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( retrieve_uses_assignment_operator )
|
BOOST_AUTO_TEST_CASE( retrieve_constraint_uses_assignment_operator )
|
||||||
{
|
{
|
||||||
B b;
|
B b;
|
||||||
const A a = A();
|
const A a = A();
|
||||||
mock::retrieve( b ).c_( a );
|
mock::retrieve( b ).c_( a );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( affirm )
|
BOOST_AUTO_TEST_CASE( affirm_constraint )
|
||||||
{
|
{
|
||||||
int* i = 0;
|
int* i = 0;
|
||||||
int j;
|
int j;
|
||||||
|
|
@ -250,7 +250,7 @@ BOOST_AUTO_TEST_CASE( affirm )
|
||||||
BOOST_CHECK( mock::affirm.c_( &j ) );
|
BOOST_CHECK( mock::affirm.c_( &j ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( negate )
|
BOOST_AUTO_TEST_CASE( negate_constraint )
|
||||||
{
|
{
|
||||||
int* i = 0;
|
int* i = 0;
|
||||||
int j;
|
int j;
|
||||||
|
|
@ -270,19 +270,19 @@ namespace
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( call )
|
BOOST_AUTO_TEST_CASE( call_constraint )
|
||||||
{
|
{
|
||||||
BOOST_CHECK( mock::call( &return_true ).c_() );
|
BOOST_CHECK( mock::call( &return_true ).c_() );
|
||||||
BOOST_CHECK( ! mock::call( &return_false ).c_() );
|
BOOST_CHECK( ! mock::call( &return_false ).c_() );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( evaluate )
|
BOOST_AUTO_TEST_CASE( evaluate_constraint )
|
||||||
{
|
{
|
||||||
BOOST_CHECK( mock::evaluate.c_( &return_true ) );
|
BOOST_CHECK( mock::evaluate.c_( &return_true ) );
|
||||||
BOOST_CHECK( ! mock::evaluate.c_( &return_false ) );
|
BOOST_CHECK( ! mock::evaluate.c_( &return_false ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( contain_with_const_char_ptr )
|
BOOST_AUTO_TEST_CASE( contain_constraint_with_const_char_ptr )
|
||||||
{
|
{
|
||||||
BOOST_CHECK( mock::contain( "string" ).c_( "this is a string" ) );
|
BOOST_CHECK( mock::contain( "string" ).c_( "this is a string" ) );
|
||||||
BOOST_CHECK( mock::contain( "string" ).c_( std::string( "this is a string" ) ) );
|
BOOST_CHECK( mock::contain( "string" ).c_( std::string( "this is a string" ) ) );
|
||||||
|
|
@ -304,7 +304,7 @@ BOOST_AUTO_TEST_CASE( contain_with_const_char_ptr )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( contain_with_strings )
|
BOOST_AUTO_TEST_CASE( contain_constraint_with_strings )
|
||||||
{
|
{
|
||||||
BOOST_CHECK( mock::contain( std::string( "string" ) ).c_( "this is a string" ) );
|
BOOST_CHECK( mock::contain( std::string( "string" ) ).c_( "this is a string" ) );
|
||||||
BOOST_CHECK( mock::contain( std::string( "string" ) ).c_( std::string( "this is a string" ) ) );
|
BOOST_CHECK( mock::contain( std::string( "string" ) ).c_( std::string( "this is a string" ) ) );
|
||||||
|
|
@ -343,3 +343,27 @@ BOOST_AUTO_TEST_CASE( type_with_overloaded_address_operator_can_be_used_in_const
|
||||||
type_with_overloaded_address_operator* pt;
|
type_with_overloaded_address_operator* pt;
|
||||||
mock::retrieve( pt ).c_( t );
|
mock::retrieve( pt ).c_( t );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE( close_constraint )
|
||||||
|
{
|
||||||
|
BOOST_CHECK( mock::close( 12.0, 0.0001 ).c_( 12 ) );
|
||||||
|
BOOST_CHECK( ! mock::close( 12.0, 0.0001 ).c_( 13 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE( close_fraction_constraint )
|
||||||
|
{
|
||||||
|
BOOST_CHECK( mock::close_fraction( 12.0, 0.0001 ).c_( 12 ) );
|
||||||
|
BOOST_CHECK( ! mock::close_fraction( 12.0, 0.0001 ).c_( 13 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE( small_constraint )
|
||||||
|
{
|
||||||
|
BOOST_CHECK( mock::small( 0.0001 ).c_( 0. ) );
|
||||||
|
BOOST_CHECK( ! mock::small( 0.0001 ).c_( 12. ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE( near_constraint )
|
||||||
|
{
|
||||||
|
BOOST_CHECK( mock::near( 12.0, 0.0001 ).c_( 12 ) );
|
||||||
|
BOOST_CHECK( ! mock::near( 12.0, 0.0001 ).c_( 13 ) );
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
#include <boost/utility/enable_if.hpp>
|
#include <boost/utility/enable_if.hpp>
|
||||||
#include <boost/utility/addressof.hpp>
|
#include <boost/utility/addressof.hpp>
|
||||||
#include <boost/type_traits/is_convertible.hpp>
|
#include <boost/type_traits/is_convertible.hpp>
|
||||||
|
#include <boost/test/floating_point_comparison.hpp>
|
||||||
|
|
||||||
namespace mock
|
namespace mock
|
||||||
{
|
{
|
||||||
|
|
@ -30,6 +31,21 @@ namespace mock
|
||||||
MOCK_BINARY_CONSTRAINT( less_equal, actual <= expected )
|
MOCK_BINARY_CONSTRAINT( less_equal, actual <= expected )
|
||||||
MOCK_BINARY_CONSTRAINT( greater_equal, actual >= expected )
|
MOCK_BINARY_CONSTRAINT( greater_equal, actual >= expected )
|
||||||
|
|
||||||
|
MOCK_BINARY_CONSTRAINT( small, \
|
||||||
|
( boost::test_tools::check_is_small( actual, expected ) ) );
|
||||||
|
|
||||||
|
MOCK_TERNARY_CONSTRAINT( close, \
|
||||||
|
( boost::test_tools::check_is_close( \
|
||||||
|
actual, expected, \
|
||||||
|
boost::test_tools::percent_tolerance( arg ) ) ) );
|
||||||
|
|
||||||
|
MOCK_TERNARY_CONSTRAINT( close_fraction, \
|
||||||
|
( boost::test_tools::check_is_close( \
|
||||||
|
actual, expected, \
|
||||||
|
boost::test_tools::fraction_tolerance( arg ) ) ) );
|
||||||
|
|
||||||
|
MOCK_TERNARY_CONSTRAINT( near, std::abs( actual - expected ) < arg );
|
||||||
|
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
template< typename Expected >
|
template< typename Expected >
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue