mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-10-31 20:27:11 +01:00 
			
		
		
		
	Special case Approx(inf) to better follow user expectations
This commit is contained in:
		| @@ -52,7 +52,8 @@ namespace Detail { | |||||||
|     bool Approx::equalityComparisonImpl(const double other) const { |     bool Approx::equalityComparisonImpl(const double other) const { | ||||||
|         // First try with fixed margin, then compute margin based on epsilon, scale and Approx's value |         // 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 |         // 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) { |     void Approx::setMargin(double newMargin) { | ||||||
|   | |||||||
| @@ -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 | 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: '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 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 ''{' := '{'' | 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.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.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: 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 one | ||||||
| Message from section two | 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" | Matchers.tests.cpp:<line number>: failed: testStringForMatching(), StartsWith("This String") for: "this string contains 'abc' as a substring" starts with: "This String" | ||||||
|   | |||||||
| @@ -1380,6 +1380,6 @@ due to unexpected exception with message: | |||||||
|   Why would you throw a std::string? |   Why would you throw a std::string? | ||||||
|  |  | ||||||
| =============================================================================== | =============================================================================== | ||||||
| test cases:  301 |  227 passed |  70 failed |  4 failed as expected | test cases:  300 |  226 passed |  70 failed |  4 failed as expected | ||||||
| assertions: 1569 | 1417 passed | 131 failed | 21 failed as expected | assertions: 1565 | 1413 passed | 131 failed | 21 failed as expected | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1939,27 +1939,6 @@ Tricky.tests.cpp:<line number> | |||||||
| Tricky.tests.cpp:<line number>: PASSED: | Tricky.tests.cpp:<line number>: PASSED: | ||||||
|   REQUIRE( true ) |   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 | CAPTURE can deal with complex expressions | ||||||
| ------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- | ||||||
| @@ -7418,11 +7397,6 @@ Approx.tests.cpp:<line number>: PASSED: | |||||||
| with expansion: | with expansion: | ||||||
|   Approx( 1.23 ) != 1.24 |   Approx( 1.23 ) != 1.24 | ||||||
|  |  | ||||||
| Approx.tests.cpp:<line number>: PASSED: |  | ||||||
|   REQUIRE( INFINITY == Approx(INFINITY) ) |  | ||||||
| with expansion: |  | ||||||
|   inff == Approx( inf ) |  | ||||||
|  |  | ||||||
| Message from section one | Message from section one | ||||||
| ------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- | ||||||
| Standard output from all sections is reported | Standard output from all sections is reported | ||||||
| @@ -12528,6 +12502,6 @@ Misc.tests.cpp:<line number> | |||||||
| Misc.tests.cpp:<line number>: PASSED: | Misc.tests.cpp:<line number>: PASSED: | ||||||
|  |  | ||||||
| =============================================================================== | =============================================================================== | ||||||
| test cases:  301 |  211 passed |  86 failed |  4 failed as expected | test cases:  300 |  210 passed |  86 failed |  4 failed as expected | ||||||
| assertions: 1586 | 1417 passed | 148 failed | 21 failed as expected | assertions: 1582 | 1413 passed | 148 failed | 21 failed as expected | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,7 +1,7 @@ | |||||||
| <?xml version="1.0" encoding="UTF-8"?> | <?xml version="1.0" encoding="UTF-8"?> | ||||||
| <testsuitesloose text artifact | <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> |     <properties> | ||||||
|       <property name="filters" value="~[!nonportable]~[!benchmark]~[approvals]"/> |       <property name="filters" value="~[!nonportable]~[!benchmark]~[approvals]"/> | ||||||
|       <property name="random-seed" value="1"/> |       <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" 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 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="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" 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 can deal with complex expressions involving commas" time="{duration}"/> | ||||||
|     <testcase classname="<exe-name>.global" name="CAPTURE parses string and character constants" time="{duration}"/> |     <testcase classname="<exe-name>.global" name="CAPTURE parses string and character constants" time="{duration}"/> | ||||||
|   | |||||||
| @@ -2172,33 +2172,6 @@ Nor would this | |||||||
|       </Section> |       </Section> | ||||||
|       <OverallResult success="true"/> |       <OverallResult success="true"/> | ||||||
|     </TestCase> |     </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" > |     <TestCase name="CAPTURE can deal with complex expressions" tags="[capture][messages]" filename="projects/<exe-name>/UsageTests/Message.tests.cpp" > | ||||||
|       <Info> |       <Info> | ||||||
|         a := 1 |         a := 1 | ||||||
| @@ -9168,14 +9141,6 @@ A string sent to stderr via clog | |||||||
|           Approx( 1.23 ) != 1.24 |           Approx( 1.23 ) != 1.24 | ||||||
|         </Expanded> |         </Expanded> | ||||||
|       </Expression> |       </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"/> |       <OverallResult success="true"/> | ||||||
|     </TestCase> |     </TestCase> | ||||||
|     <TestCase name="Standard output from all sections is reported" tags="[.][messages]" filename="projects/<exe-name>/UsageTests/Message.tests.cpp" > |     <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> |       </Section> | ||||||
|       <OverallResult success="true"/> |       <OverallResult success="true"/> | ||||||
|     </TestCase> |     </TestCase> | ||||||
|     <OverallResults successes="1417" failures="149" expectedFailures="21"/> |     <OverallResults successes="1413" failures="149" expectedFailures="21"/> | ||||||
|   </Group> |   </Group> | ||||||
|   <OverallResults successes="1417" failures="148" expectedFailures="21"/> |   <OverallResults successes="1413" failures="148" expectedFailures="21"/> | ||||||
| </Catch> | </Catch> | ||||||
|   | |||||||
| @@ -61,8 +61,6 @@ TEST_CASE( "Some simple comparisons between doubles", "[Approx]" ) { | |||||||
|     REQUIRE( Approx( d ) == 1.23 ); |     REQUIRE( Approx( d ) == 1.23 ); | ||||||
|     REQUIRE( Approx( d ) != 1.22 ); |     REQUIRE( Approx( d ) != 1.22 ); | ||||||
|     REQUIRE( Approx( d ) != 1.24 ); |     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)); |     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(-INFINITY != Approx(INFINITY)); | ||||||
|  |     REQUIRE(1 != Approx(INFINITY)); | ||||||
|     REQUIRE(NAN != Approx(NAN)); |     REQUIRE(NAN != Approx(NAN)); | ||||||
|     REQUIRE_FALSE(NAN == Approx(NAN)); |     REQUIRE_FALSE(NAN == Approx(NAN)); | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Martin Hořeňovský
					Martin Hořeňovský