Permalink
Browse files

Final set of fixes for floating matchers approvals

  • Loading branch information...
horenmar committed Nov 10, 2017
1 parent a0dbc62 commit 8dbaac61ff39c7b99a31d5548df17cdc16bca322
@@ -6,8 +6,9 @@
*/
#include "catch_matchers_floating.h"
#include "catch_tostring.h"
#include <cmath>
#include <cstdlib>
#include <cstdint>
#include <cstring>
#include <stdexcept>
@@ -87,7 +88,7 @@ namespace Floating {
}
std::string WithinAbsMatcher::describe() const {
return "is within " + std::to_string(m_margin) + " of " + std::to_string(m_target);
return "is within " + ::Catch::Detail::stringify(m_margin) + " of " + ::Catch::Detail::stringify(m_target);
}
@@ -110,7 +111,7 @@ namespace Floating {
}
std::string WithinUlpsMatcher::describe() const {
return "is within " + std::to_string(m_ulps) + " ULPs of " + std::to_string(m_target) + ((m_type == FloatingPointKind::Float)? "f" : "");
return "is within " + std::to_string(m_ulps) + " ULPs of " + ::Catch::Detail::stringify(m_target) + ((m_type == FloatingPointKind::Float)? "f" : "");
}
}// namespace Floating
@@ -17,6 +17,7 @@
#include "catch_interfaces_config.h"
#include "catch_context.h"
#include <cmath>
#include <iomanip>
namespace Catch {
@@ -63,6 +64,10 @@ namespace Detail {
template<typename T>
std::string fpToString( T value, int precision ) {
if (std::isnan(value)) {
return "nan";
}
ReusableStringStream rss;
rss << std::setprecision( precision )
<< std::fixed
@@ -1740,31 +1740,31 @@ MatchersTests.cpp:<line number>:
PASSED:
REQUIRE_THAT( 1., WithinAbs(1., 0) )
with expansion:
1.0 is within 0.000000 of 1.000000
1.0 is within 0.0 of 1.0
MatchersTests.cpp:<line number>:
PASSED:
REQUIRE_THAT( 0., WithinAbs(1., 1) )
with expansion:
0.0 is within 1.000000 of 1.000000
0.0 is within 1.0 of 1.0
MatchersTests.cpp:<line number>:
PASSED:
REQUIRE_THAT( 0., !WithinAbs(1., 0.99) )
with expansion:
0.0 not is within 0.990000 of 1.000000
0.0 not is within 0.99 of 1.0
MatchersTests.cpp:<line number>:
PASSED:
REQUIRE_THAT( 0., !WithinAbs(1., 0.99) )
with expansion:
0.0 not is within 0.990000 of 1.000000
0.0 not is within 0.99 of 1.0
MatchersTests.cpp:<line number>:
PASSED:
REQUIRE_THAT( NAN, !WithinAbs(NAN, 0) )
with expansion:
nanf not is within 0.000000 of nan
nanf not is within 0.0 of nan
-------------------------------------------------------------------------------
Floating point matchers: double
@@ -1777,37 +1777,37 @@ MatchersTests.cpp:<line number>:
PASSED:
REQUIRE_THAT( 1., WithinULP(1., 0) )
with expansion:
1.0 is within 0 ULPs of 1.000000
1.0 is within 0 ULPs of 1.0
MatchersTests.cpp:<line number>:
PASSED:
REQUIRE_THAT( std::nextafter(1., 2.), WithinULP(1., 1) )
with expansion:
1.0 is within 1 ULPs of 1.000000
1.0 is within 1 ULPs of 1.0
MatchersTests.cpp:<line number>:
PASSED:
REQUIRE_THAT( std::nextafter(1., 0.), WithinULP(1., 1) )
with expansion:
1.0 is within 1 ULPs of 1.000000
1.0 is within 1 ULPs of 1.0
MatchersTests.cpp:<line number>:
PASSED:
REQUIRE_THAT( std::nextafter(1., 2.), !WithinULP(1., 0) )
with expansion:
1.0 not is within 0 ULPs of 1.000000
1.0 not is within 0 ULPs of 1.0
MatchersTests.cpp:<line number>:
PASSED:
REQUIRE_THAT( 1., WithinULP(1., 0) )
with expansion:
1.0 is within 0 ULPs of 1.000000
1.0 is within 0 ULPs of 1.0
MatchersTests.cpp:<line number>:
PASSED:
REQUIRE_THAT( -0., WithinULP(0., 0) )
with expansion:
-0.0 is within 0 ULPs of 0.000000
-0.0 is within 0 ULPs of 0.0
MatchersTests.cpp:<line number>:
PASSED:
@@ -1826,19 +1826,19 @@ MatchersTests.cpp:<line number>:
PASSED:
REQUIRE_THAT( 1., WithinAbs(1., 0.5) || WithinULP(2., 1) )
with expansion:
1.0 ( is within 0.500000 of 1.000000 or is within 1 ULPs of 2.000000 )
1.0 ( is within 0.5 of 1.0 or is within 1 ULPs of 2.0 )
MatchersTests.cpp:<line number>:
PASSED:
REQUIRE_THAT( 1., WithinAbs(2., 0.5) || WithinULP(1., 0) )
with expansion:
1.0 ( is within 0.500000 of 2.000000 or is within 0 ULPs of 1.000000 )
1.0 ( is within 0.5 of 2.0 or is within 0 ULPs of 1.0 )
MatchersTests.cpp:<line number>:
PASSED:
REQUIRE_THAT( NAN, !(WithinAbs(NAN, 100) || WithinULP(NAN, 123)) )
with expansion:
nanf not ( is within 100.000000 of nan or is within 123 ULPs of nanf )
nanf not ( is within 100.0 of nan or is within 123 ULPs of nanf )
-------------------------------------------------------------------------------
Floating point matchers: float
@@ -1851,37 +1851,37 @@ MatchersTests.cpp:<line number>:
PASSED:
REQUIRE_THAT( 1.f, WithinAbs(1.f, 0) )
with expansion:
1.0f is within 0.000000 of 1.000000
1.0f is within 0.0 of 1.0
MatchersTests.cpp:<line number>:
PASSED:
REQUIRE_THAT( 0.f, WithinAbs(1.f, 1) )
with expansion:
0.0f is within 1.000000 of 1.000000
0.0f is within 1.0 of 1.0
MatchersTests.cpp:<line number>:
PASSED:
REQUIRE_THAT( 0.f, !WithinAbs(1.f, 0.99f) )
with expansion:
0.0f not is within 0.990000 of 1.000000
0.0f not is within 0.9900000095 of 1.0
MatchersTests.cpp:<line number>:
PASSED:
REQUIRE_THAT( 0.f, !WithinAbs(1.f, 0.99f) )
with expansion:
0.0f not is within 0.990000 of 1.000000
0.0f not is within 0.9900000095 of 1.0
MatchersTests.cpp:<line number>:
PASSED:
REQUIRE_THAT( 0.f, WithinAbs(-0.f, 0) )
with expansion:
0.0f is within 0.000000 of -0.000000
0.0f is within 0.0 of -0.0
MatchersTests.cpp:<line number>:
PASSED:
REQUIRE_THAT( NAN, !WithinAbs(NAN, 0) )
with expansion:
nanf not is within 0.000000 of nan
nanf not is within 0.0 of nan
-------------------------------------------------------------------------------
Floating point matchers: float
@@ -1894,37 +1894,37 @@ MatchersTests.cpp:<line number>:
PASSED:
REQUIRE_THAT( 1.f, WithinULP(1.f, 0) )
with expansion:
1.0f is within 0 ULPs of 1.000000f
1.0f is within 0 ULPs of 1.0f
MatchersTests.cpp:<line number>:
PASSED:
REQUIRE_THAT( std::nextafter(1.f, 2.f), WithinULP(1.f, 1) )
with expansion:
1.0f is within 1 ULPs of 1.000000f
1.0f is within 1 ULPs of 1.0f
MatchersTests.cpp:<line number>:
PASSED:
REQUIRE_THAT( std::nextafter(1.f, 0.f), WithinULP(1.f, 1) )
with expansion:
1.0f is within 1 ULPs of 1.000000f
1.0f is within 1 ULPs of 1.0f
MatchersTests.cpp:<line number>:
PASSED:
REQUIRE_THAT( std::nextafter(1.f, 2.f), !WithinULP(1.f, 0) )
with expansion:
1.0f not is within 0 ULPs of 1.000000f
1.0f not is within 0 ULPs of 1.0f
MatchersTests.cpp:<line number>:
PASSED:
REQUIRE_THAT( 1.f, WithinULP(1.f, 0) )
with expansion:
1.0f is within 0 ULPs of 1.000000f
1.0f is within 0 ULPs of 1.0f
MatchersTests.cpp:<line number>:
PASSED:
REQUIRE_THAT( -0.f, WithinULP(0.f, 0) )
with expansion:
-0.0f is within 0 ULPs of 0.000000f
-0.0f is within 0 ULPs of 0.0f
MatchersTests.cpp:<line number>:
PASSED:
@@ -1943,19 +1943,19 @@ MatchersTests.cpp:<line number>:
PASSED:
REQUIRE_THAT( 1.f, WithinAbs(1.f, 0.5) || WithinULP(1.f, 1) )
with expansion:
1.0f ( is within 0.500000 of 1.000000 or is within 1 ULPs of 1.000000f )
1.0f ( is within 0.5 of 1.0 or is within 1 ULPs of 1.0f )
MatchersTests.cpp:<line number>:
PASSED:
REQUIRE_THAT( 1.f, WithinAbs(2.f, 0.5) || WithinULP(1.f, 0) )
with expansion:
1.0f ( is within 0.500000 of 2.000000 or is within 0 ULPs of 1.000000f )
1.0f ( is within 0.5 of 2.0 or is within 0 ULPs of 1.0f )
MatchersTests.cpp:<line number>:
PASSED:
REQUIRE_THAT( NAN, !(WithinAbs(NAN, 100) || WithinULP(NAN, 123)) )
with expansion:
nanf not ( is within 100.000000 of nan or is within 123 ULPs of nanf )
nanf not ( is within 100.0 of nan or is within 123 ULPs of nanf )
-------------------------------------------------------------------------------
Greater-than inequalities with different epsilons
Oops, something went wrong.

0 comments on commit 8dbaac6

Please sign in to comment.