mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 23:36:11 +01:00
Moved Approx into its own namespace to avoid ADL issues with operator ==
This commit is contained in:
parent
3c08431c92
commit
01db6c4471
@ -66,6 +66,6 @@
|
|||||||
// Still to be implemented
|
// Still to be implemented
|
||||||
#define CHECK_NOFAIL( expr ) // !TBD - reports violation, but doesn't fail Test
|
#define CHECK_NOFAIL( expr ) // !TBD - reports violation, but doesn't fail Test
|
||||||
|
|
||||||
using Catch::Approx;
|
using Catch::Detail::Approx;
|
||||||
|
|
||||||
#endif // TWOBLUECUBES_CATCH_HPP_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_HPP_INCLUDED
|
||||||
|
@ -591,53 +591,55 @@ inline double catch_max( double x, double y )
|
|||||||
{
|
{
|
||||||
return x > y ? x : y;
|
return x > y ? x : y;
|
||||||
}
|
}
|
||||||
|
namespace Detail
|
||||||
class Approx
|
|
||||||
{
|
{
|
||||||
public:
|
class Approx
|
||||||
///////////////////////////////////////////////////////////////////////////
|
|
||||||
// !TBD more generic
|
|
||||||
explicit Approx
|
|
||||||
(
|
|
||||||
double d
|
|
||||||
)
|
|
||||||
: m_d( d )
|
|
||||||
{
|
{
|
||||||
}
|
public:
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// !TBD more generic
|
||||||
|
explicit Approx
|
||||||
|
(
|
||||||
|
double d
|
||||||
|
)
|
||||||
|
: m_d( d )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
template<typename T>
|
template<typename T>
|
||||||
friend bool operator ==
|
friend bool operator ==
|
||||||
(
|
(
|
||||||
const T& lhs,
|
const T& lhs,
|
||||||
const Approx& rhs
|
const Approx& rhs
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
// !TBD Use proper tolerance
|
// !TBD Use proper tolerance
|
||||||
// From: http://realtimecollisiondetection.net/blog/?p=89
|
// From: http://realtimecollisiondetection.net/blog/?p=89
|
||||||
// see also: http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm
|
// see also: http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm
|
||||||
return fabs( lhs - rhs.m_d ) <= catch_max( CATCH_absTol, CATCH_relTol * catch_max( fabs(lhs), fabs(rhs.m_d) ) );
|
return fabs( lhs - rhs.m_d ) <= catch_max( CATCH_absTol, CATCH_relTol * catch_max( fabs(lhs), fabs(rhs.m_d) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
template<typename T>
|
template<typename T>
|
||||||
friend bool operator !=
|
friend bool operator !=
|
||||||
(
|
(
|
||||||
const T& lhs,
|
const T& lhs,
|
||||||
const Approx& rhs
|
const Approx& rhs
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return ! operator==( lhs, rhs );
|
return ! operator==( lhs, rhs );
|
||||||
}
|
}
|
||||||
|
|
||||||
double m_d;
|
double m_d;
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
template<>
|
template<>
|
||||||
inline std::string toString<Approx>
|
inline std::string toString<Detail::Approx>
|
||||||
(
|
(
|
||||||
const Approx& value
|
const Detail::Approx& value
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
|
Loading…
Reference in New Issue
Block a user