diff --git a/include/internal/catch_approx.cpp b/include/internal/catch_approx.cpp index da7e4020..32b5e043 100644 --- a/include/internal/catch_approx.cpp +++ b/include/internal/catch_approx.cpp @@ -52,7 +52,8 @@ namespace Detail { bool Approx::equalityComparisonImpl(const double other) const { // First try with fixed margin, then compute margin based on epsilon, scale and Approx's value // Thanks to Richard Harris for his help refining the scaled margin value - return marginComparison(m_value, other, m_margin) || marginComparison(m_value, other, m_epsilon * (m_scale + std::fabs(m_value))); + return marginComparison(m_value, other, m_margin) + || marginComparison(m_value, other, m_epsilon * (m_scale + std::fabs(std::isinf(m_value)? 0 : m_value))); } void Approx::setMargin(double newMargin) { diff --git a/projects/SelfTest/Baselines/compact.sw.approved.txt b/projects/SelfTest/Baselines/compact.sw.approved.txt index 03b49599..7c93c160 100644 --- a/projects/SelfTest/Baselines/compact.sw.approved.txt +++ b/projects/SelfTest/Baselines/compact.sw.approved.txt @@ -243,9 +243,6 @@ Tricky.tests.cpp:: passed: true Tricky.tests.cpp:: passed: true Tricky.tests.cpp:: passed: true Tricky.tests.cpp:: passed: true -Approx.tests.cpp:: passed: INFINITY == Approx(INFINITY) for: inff == Approx( inf ) -Approx.tests.cpp:: passed: NAN != Approx(NAN) for: nanf != Approx( nan ) -Approx.tests.cpp:: passed: !(NAN == Approx(NAN)) for: !(nanf == Approx( nan )) Message.tests.cpp:: passed: with 7 messages: 'a := 1' and 'b := 2' and 'c := 3' and 'a + b := 3' and 'a+b := 3' and 'c > b := true' and 'a == 1 := true' Message.tests.cpp:: passed: with 7 messages: 'std::vector{1, 2, 3}[0, 1, 2] := 3' and 'std::vector{1, 2, 3}[(0, 1)] := 2' and 'std::vector{1, 2, 3}[0] := 1' and '(helper_1436{12, -12}) := { 12, -12 }' and '(helper_1436(-12, 12)) := { -12, 12 }' and '(1, 2) := 2' and '(2, 3) := 3' Message.tests.cpp:: passed: with 11 messages: '("comma, in string", "escaped, \", ") := "escaped, ", "' and '"single quote in string,'," := "single quote in string,',"' and '"some escapes, \\,\\\\" := "some escapes, \,\\"' and '"some, ), unmatched, } prenheses {[<" := "some, ), unmatched, } prenheses {[<"' and ''"' := '"'' and ''\'' := '''' and '',' := ','' and ''}' := '}'' and '')' := ')'' and ''(' := '('' and ''{' := '{'' @@ -993,7 +990,6 @@ Approx.tests.cpp:: passed: d != 1.22_a for: 1.23 != Approx( 1.22 ) Approx.tests.cpp:: passed: Approx( d ) == 1.23 for: Approx( 1.23 ) == 1.23 Approx.tests.cpp:: passed: Approx( d ) != 1.22 for: Approx( 1.23 ) != 1.22 Approx.tests.cpp:: passed: Approx( d ) != 1.24 for: Approx( 1.23 ) != 1.24 -Approx.tests.cpp:: passed: INFINITY == Approx(INFINITY) for: inff == Approx( inf ) Message from section one Message from section two Matchers.tests.cpp:: failed: testStringForMatching(), StartsWith("This String") for: "this string contains 'abc' as a substring" starts with: "This String" diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt index 5798dcbe..a729420d 100644 --- a/projects/SelfTest/Baselines/console.std.approved.txt +++ b/projects/SelfTest/Baselines/console.std.approved.txt @@ -1380,6 +1380,6 @@ due to unexpected exception with message: Why would you throw a std::string? =============================================================================== -test cases: 301 | 227 passed | 70 failed | 4 failed as expected -assertions: 1569 | 1417 passed | 131 failed | 21 failed as expected +test cases: 300 | 226 passed | 70 failed | 4 failed as expected +assertions: 1565 | 1413 passed | 131 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index b4aba834..83ca294e 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -1939,27 +1939,6 @@ Tricky.tests.cpp: Tricky.tests.cpp:: PASSED: REQUIRE( true ) -------------------------------------------------------------------------------- -Assorted miscellaneous tests -------------------------------------------------------------------------------- -Approx.tests.cpp: -............................................................................... - -Approx.tests.cpp:: PASSED: - REQUIRE( INFINITY == Approx(INFINITY) ) -with expansion: - inff == Approx( inf ) - -Approx.tests.cpp:: PASSED: - REQUIRE( NAN != Approx(NAN) ) -with expansion: - nanf != Approx( nan ) - -Approx.tests.cpp:: PASSED: - REQUIRE_FALSE( NAN == Approx(NAN) ) -with expansion: - !(nanf == Approx( nan )) - ------------------------------------------------------------------------------- CAPTURE can deal with complex expressions ------------------------------------------------------------------------------- @@ -7418,11 +7397,6 @@ Approx.tests.cpp:: PASSED: with expansion: Approx( 1.23 ) != 1.24 -Approx.tests.cpp:: PASSED: - REQUIRE( INFINITY == Approx(INFINITY) ) -with expansion: - inff == Approx( inf ) - Message from section one ------------------------------------------------------------------------------- Standard output from all sections is reported @@ -12528,6 +12502,6 @@ Misc.tests.cpp: Misc.tests.cpp:: PASSED: =============================================================================== -test cases: 301 | 211 passed | 86 failed | 4 failed as expected -assertions: 1586 | 1417 passed | 148 failed | 21 failed as expected +test cases: 300 | 210 passed | 86 failed | 4 failed as expected +assertions: 1582 | 1413 passed | 148 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index a768f1e6..ae12fb07 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + @@ -232,7 +232,6 @@ Exception.tests.cpp: - diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index c4e5a75e..06d15a4e 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -2172,33 +2172,6 @@ Nor would this - - - - INFINITY == Approx(INFINITY) - - - inff == Approx( inf ) - - - - - NAN != Approx(NAN) - - - nanf != Approx( nan ) - - - - - !(NAN == Approx(NAN)) - - - !(nanf == Approx( nan )) - - - - a := 1 @@ -9168,14 +9141,6 @@ A string sent to stderr via clog Approx( 1.23 ) != 1.24 - - - INFINITY == Approx(INFINITY) - - - inff == Approx( inf ) - - @@ -14915,7 +14880,7 @@ loose text artifact - + - + diff --git a/projects/SelfTest/UsageTests/Approx.tests.cpp b/projects/SelfTest/UsageTests/Approx.tests.cpp index b95394a0..b51e3ccb 100644 --- a/projects/SelfTest/UsageTests/Approx.tests.cpp +++ b/projects/SelfTest/UsageTests/Approx.tests.cpp @@ -61,8 +61,6 @@ TEST_CASE( "Some simple comparisons between doubles", "[Approx]" ) { REQUIRE( Approx( d ) == 1.23 ); REQUIRE( Approx( d ) != 1.22 ); REQUIRE( Approx( d ) != 1.24 ); - - REQUIRE(INFINITY == Approx(INFINITY)); } /////////////////////////////////////////////////////////////////////////////// @@ -183,8 +181,10 @@ TEST_CASE("Epsilon only applies to Approx's value", "[Approx]") { REQUIRE(101.01 != Approx(100).epsilon(0.01)); } -TEST_CASE("Assorted miscellaneous tests", "[Approx]") { +TEST_CASE("Assorted miscellaneous tests", "[Approx][approvals]") { REQUIRE(INFINITY == Approx(INFINITY)); + REQUIRE(-INFINITY != Approx(INFINITY)); + REQUIRE(1 != Approx(INFINITY)); REQUIRE(NAN != Approx(NAN)); REQUIRE_FALSE(NAN == Approx(NAN)); }