Special case Approx(inf) to better follow user expectations

This commit is contained in:
Martin Hořeňovský 2019-10-04 13:23:14 +02:00
parent 815f99541d
commit 02ee130bd0
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
7 changed files with 12 additions and 77 deletions

View File

@ -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) {

View File

@ -243,9 +243,6 @@ Tricky.tests.cpp:<line number>: passed: true
Tricky.tests.cpp:<line number>: passed: true
Tricky.tests.cpp:<line number>: passed: true
Tricky.tests.cpp:<line number>: passed: true
Approx.tests.cpp:<line number>: passed: INFINITY == Approx(INFINITY) for: inff == Approx( inf )
Approx.tests.cpp:<line number>: passed: NAN != Approx(NAN) for: nanf != Approx( nan )
Approx.tests.cpp:<line number>: passed: !(NAN == Approx(NAN)) for: !(nanf == Approx( nan ))
Message.tests.cpp:<line number>: 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:<line number>: passed: with 7 messages: 'std::vector<int>{1, 2, 3}[0, 1, 2] := 3' and 'std::vector<int>{1, 2, 3}[(0, 1)] := 2' and 'std::vector<int>{1, 2, 3}[0] := 1' and '(helper_1436<int, int>{12, -12}) := { 12, -12 }' and '(helper_1436<int, int>(-12, 12)) := { -12, 12 }' and '(1, 2) := 2' and '(2, 3) := 3'
Message.tests.cpp:<line number>: 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:<line number>: passed: d != 1.22_a for: 1.23 != Approx( 1.22 )
Approx.tests.cpp:<line number>: passed: Approx( d ) == 1.23 for: Approx( 1.23 ) == 1.23
Approx.tests.cpp:<line number>: passed: Approx( d ) != 1.22 for: Approx( 1.23 ) != 1.22
Approx.tests.cpp:<line number>: passed: Approx( d ) != 1.24 for: Approx( 1.23 ) != 1.24
Approx.tests.cpp:<line number>: passed: INFINITY == Approx(INFINITY) for: inff == Approx( inf )
Message from section one
Message from section two
Matchers.tests.cpp:<line number>: failed: testStringForMatching(), StartsWith("This String") for: "this string contains 'abc' as a substring" starts with: "This String"

View File

@ -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

View File

@ -1939,27 +1939,6 @@ Tricky.tests.cpp:<line number>
Tricky.tests.cpp:<line number>: PASSED:
REQUIRE( true )
-------------------------------------------------------------------------------
Assorted miscellaneous tests
-------------------------------------------------------------------------------
Approx.tests.cpp:<line number>
...............................................................................
Approx.tests.cpp:<line number>: PASSED:
REQUIRE( INFINITY == Approx(INFINITY) )
with expansion:
inff == Approx( inf )
Approx.tests.cpp:<line number>: PASSED:
REQUIRE( NAN != Approx(NAN) )
with expansion:
nanf != Approx( nan )
Approx.tests.cpp:<line number>: PASSED:
REQUIRE_FALSE( NAN == Approx(NAN) )
with expansion:
!(nanf == Approx( nan ))
-------------------------------------------------------------------------------
CAPTURE can deal with complex expressions
-------------------------------------------------------------------------------
@ -7418,11 +7397,6 @@ Approx.tests.cpp:<line number>: PASSED:
with expansion:
Approx( 1.23 ) != 1.24
Approx.tests.cpp:<line number>: 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:<line number>
Misc.tests.cpp:<line number>: 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

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuitesloose text artifact
>
<testsuite name="<exe-name>" errors="17" failures="132" tests="1587" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<testsuite name="<exe-name>" errors="17" failures="132" tests="1583" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<properties>
<property name="filters" value="~[!nonportable]~[!benchmark]~[approvals]"/>
<property name="random-seed" value="1"/>
@ -232,7 +232,6 @@ Exception.tests.cpp:<line number>
<testcase classname="<exe-name>.global" name="Assertions then sections/A section" time="{duration}"/>
<testcase classname="<exe-name>.global" name="Assertions then sections/A section/Another section" time="{duration}"/>
<testcase classname="<exe-name>.global" name="Assertions then sections/A section/Another other section" time="{duration}"/>
<testcase classname="<exe-name>.global" name="Assorted miscellaneous tests" time="{duration}"/>
<testcase classname="<exe-name>.global" name="CAPTURE can deal with complex expressions" time="{duration}"/>
<testcase classname="<exe-name>.global" name="CAPTURE can deal with complex expressions involving commas" time="{duration}"/>
<testcase classname="<exe-name>.global" name="CAPTURE parses string and character constants" time="{duration}"/>

View File

@ -2172,33 +2172,6 @@ Nor would this
</Section>
<OverallResult success="true"/>
</TestCase>
<TestCase name="Assorted miscellaneous tests" tags="[Approx]" filename="projects/<exe-name>/UsageTests/Approx.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Approx.tests.cpp" >
<Original>
INFINITY == Approx(INFINITY)
</Original>
<Expanded>
inff == Approx( inf )
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Approx.tests.cpp" >
<Original>
NAN != Approx(NAN)
</Original>
<Expanded>
nanf != Approx( nan )
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE_FALSE" filename="projects/<exe-name>/UsageTests/Approx.tests.cpp" >
<Original>
!(NAN == Approx(NAN))
</Original>
<Expanded>
!(nanf == Approx( nan ))
</Expanded>
</Expression>
<OverallResult success="true"/>
</TestCase>
<TestCase name="CAPTURE can deal with complex expressions" tags="[capture][messages]" filename="projects/<exe-name>/UsageTests/Message.tests.cpp" >
<Info>
a := 1
@ -9168,14 +9141,6 @@ A string sent to stderr via clog
Approx( 1.23 ) != 1.24
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Approx.tests.cpp" >
<Original>
INFINITY == Approx(INFINITY)
</Original>
<Expanded>
inff == Approx( inf )
</Expanded>
</Expression>
<OverallResult success="true"/>
</TestCase>
<TestCase name="Standard output from all sections is reported" tags="[.][messages]" filename="projects/<exe-name>/UsageTests/Message.tests.cpp" >
@ -14915,7 +14880,7 @@ loose text artifact
</Section>
<OverallResult success="true"/>
</TestCase>
<OverallResults successes="1417" failures="149" expectedFailures="21"/>
<OverallResults successes="1413" failures="149" expectedFailures="21"/>
</Group>
<OverallResults successes="1417" failures="148" expectedFailures="21"/>
<OverallResults successes="1413" failures="148" expectedFailures="21"/>
</Catch>

View File

@ -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));
}