Allow epsilon and scale to be specified

This commit is contained in:
Phil Nash 2011-04-28 08:20:47 +01:00
parent d7b8b01f3e
commit dfea75fc05

View File

@ -15,6 +15,7 @@
#include "catch_capture.hpp" #include "catch_capture.hpp"
#include <cmath> #include <cmath>
#include <limits>
namespace Catch namespace Catch
{ {
@ -28,7 +29,7 @@ namespace Catch
( (
double d double d
) )
: m_epsilon( 1e-10 ), : m_epsilon( std::numeric_limits<double>::epsilon() ),
m_scale( 1.0 ), m_scale( 1.0 ),
m_d( d ) m_d( d )
{ {
@ -57,6 +58,36 @@ namespace Catch
return !operator==( lhs, rhs ); return !operator==( lhs, rhs );
} }
///////////////////////////////////////////////////////////////////////////
Approx& epsilon
(
double newEpsilon
)
{
m_epsilon = newEpsilon;
return *this;
}
///////////////////////////////////////////////////////////////////////////
Approx& scale
(
double newScale
)
{
m_scale = newScale;
return *this;
}
///////////////////////////////////////////////////////////////////////////
std::string toString() const
{
std::ostringstream oss;
oss << "Approx( " << m_d << ")";
return oss.str();
}
private:
double m_epsilon; double m_epsilon;
double m_scale; double m_scale;
double m_d; double m_d;
@ -70,9 +101,7 @@ namespace Catch
const Detail::Approx& value const Detail::Approx& value
) )
{ {
std::ostringstream oss; return value.toString();
oss << "Approx( " << value.m_d << ")";
return oss.str();
} }
} // end namespace Catch } // end namespace Catch