mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 13:26:10 +01:00
Add constructor arg checking to WithinAbsMatcher
Also tests :-)
This commit is contained in:
parent
d19b7292b3
commit
0c122c135d
@ -79,7 +79,11 @@ namespace Catch {
|
|||||||
namespace Matchers {
|
namespace Matchers {
|
||||||
namespace Floating {
|
namespace Floating {
|
||||||
WithinAbsMatcher::WithinAbsMatcher(double target, double margin)
|
WithinAbsMatcher::WithinAbsMatcher(double target, double margin)
|
||||||
:m_target{ target }, m_margin{ margin } {}
|
:m_target{ target }, m_margin{ margin } {
|
||||||
|
if (m_margin < 0) {
|
||||||
|
throw std::domain_error("Allowed margin difference has to be >= 0");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Performs equivalent check of std::fabs(lhs - rhs) <= margin
|
// Performs equivalent check of std::fabs(lhs - rhs) <= margin
|
||||||
// But without the subtraction to allow for INFINITY in comparison
|
// But without the subtraction to allow for INFINITY in comparison
|
||||||
@ -95,7 +99,7 @@ namespace Floating {
|
|||||||
WithinUlpsMatcher::WithinUlpsMatcher(double target, int ulps, FloatingPointKind baseType)
|
WithinUlpsMatcher::WithinUlpsMatcher(double target, int ulps, FloatingPointKind baseType)
|
||||||
:m_target{ target }, m_ulps{ ulps }, m_type{ baseType } {
|
:m_target{ target }, m_ulps{ ulps }, m_type{ baseType } {
|
||||||
if (m_ulps < 0) {
|
if (m_ulps < 0) {
|
||||||
throw std::domain_error("Expected ulp difference has to be >0");
|
throw std::domain_error("Allowed ulp difference has to be >= 0");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1054,5 +1054,5 @@ with expansion:
|
|||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
test cases: 191 | 139 passed | 48 failed | 4 failed as expected
|
test cases: 191 | 139 passed | 48 failed | 4 failed as expected
|
||||||
assertions: 955 | 831 passed | 103 failed | 21 failed as expected
|
assertions: 963 | 839 passed | 103 failed | 21 failed as expected
|
||||||
|
|
||||||
|
@ -1872,6 +1872,29 @@ PASSED:
|
|||||||
with expansion:
|
with expansion:
|
||||||
nanf not ( is within 100.0 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: double
|
||||||
|
Constructor validation
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
Matchers.tests.cpp:<line number>
|
||||||
|
...............................................................................
|
||||||
|
|
||||||
|
Matchers.tests.cpp:<line number>:
|
||||||
|
PASSED:
|
||||||
|
REQUIRE_NOTHROW( WithinAbs(1., 0.) )
|
||||||
|
|
||||||
|
Matchers.tests.cpp:<line number>:
|
||||||
|
PASSED:
|
||||||
|
REQUIRE_THROWS_AS( WithinAbs(1., -1.), std::domain_error )
|
||||||
|
|
||||||
|
Matchers.tests.cpp:<line number>:
|
||||||
|
PASSED:
|
||||||
|
REQUIRE_NOTHROW( WithinULP(1., 0) )
|
||||||
|
|
||||||
|
Matchers.tests.cpp:<line number>:
|
||||||
|
PASSED:
|
||||||
|
REQUIRE_THROWS_AS( WithinULP(1., -1), std::domain_error )
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Floating point matchers: float
|
Floating point matchers: float
|
||||||
Margin
|
Margin
|
||||||
@ -1989,6 +2012,29 @@ PASSED:
|
|||||||
with expansion:
|
with expansion:
|
||||||
nanf not ( is within 100.0 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
|
||||||
|
Constructor validation
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
Matchers.tests.cpp:<line number>
|
||||||
|
...............................................................................
|
||||||
|
|
||||||
|
Matchers.tests.cpp:<line number>:
|
||||||
|
PASSED:
|
||||||
|
REQUIRE_NOTHROW( WithinAbs(1.f, 0.f) )
|
||||||
|
|
||||||
|
Matchers.tests.cpp:<line number>:
|
||||||
|
PASSED:
|
||||||
|
REQUIRE_THROWS_AS( WithinAbs(1.f, -1.f), std::domain_error )
|
||||||
|
|
||||||
|
Matchers.tests.cpp:<line number>:
|
||||||
|
PASSED:
|
||||||
|
REQUIRE_NOTHROW( WithinULP(1.f, 0) )
|
||||||
|
|
||||||
|
Matchers.tests.cpp:<line number>:
|
||||||
|
PASSED:
|
||||||
|
REQUIRE_THROWS_AS( WithinULP(1.f, -1), std::domain_error )
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Greater-than inequalities with different epsilons
|
Greater-than inequalities with different epsilons
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
@ -8011,5 +8057,5 @@ PASSED:
|
|||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
test cases: 191 | 137 passed | 50 failed | 4 failed as expected
|
test cases: 191 | 137 passed | 50 failed | 4 failed as expected
|
||||||
assertions: 954 | 827 passed | 106 failed | 21 failed as expected
|
assertions: 962 | 835 passed | 106 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="15" failures="92" tests="955" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
|
<testsuite name="<exe-name>" errors="15" failures="92" tests="963" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
|
||||||
<testcase classname="<exe-name>.global" name="# A test name that starts with a #" time="{duration}"/>
|
<testcase classname="<exe-name>.global" name="# A test name that starts with a #" time="{duration}"/>
|
||||||
<testcase classname="<exe-name>.global" name="#1005: Comparing pointer to int and long (NULL can be either on various systems)" time="{duration}"/>
|
<testcase classname="<exe-name>.global" name="#1005: Comparing pointer to int and long (NULL can be either on various systems)" time="{duration}"/>
|
||||||
<testcase classname="<exe-name>.global" name="#1027" time="{duration}"/>
|
<testcase classname="<exe-name>.global" name="#1027" time="{duration}"/>
|
||||||
@ -276,9 +276,11 @@ Message.tests.cpp:<line number>
|
|||||||
<testcase classname="<exe-name>.global" name="Floating point matchers: double/Margin" time="{duration}"/>
|
<testcase classname="<exe-name>.global" name="Floating point matchers: double/Margin" time="{duration}"/>
|
||||||
<testcase classname="<exe-name>.global" name="Floating point matchers: double/ULPs" time="{duration}"/>
|
<testcase classname="<exe-name>.global" name="Floating point matchers: double/ULPs" time="{duration}"/>
|
||||||
<testcase classname="<exe-name>.global" name="Floating point matchers: double/Composed" time="{duration}"/>
|
<testcase classname="<exe-name>.global" name="Floating point matchers: double/Composed" time="{duration}"/>
|
||||||
|
<testcase classname="<exe-name>.global" name="Floating point matchers: double/Constructor validation" time="{duration}"/>
|
||||||
<testcase classname="<exe-name>.global" name="Floating point matchers: float/Margin" time="{duration}"/>
|
<testcase classname="<exe-name>.global" name="Floating point matchers: float/Margin" time="{duration}"/>
|
||||||
<testcase classname="<exe-name>.global" name="Floating point matchers: float/ULPs" time="{duration}"/>
|
<testcase classname="<exe-name>.global" name="Floating point matchers: float/ULPs" time="{duration}"/>
|
||||||
<testcase classname="<exe-name>.global" name="Floating point matchers: float/Composed" time="{duration}"/>
|
<testcase classname="<exe-name>.global" name="Floating point matchers: float/Composed" time="{duration}"/>
|
||||||
|
<testcase classname="<exe-name>.global" name="Floating point matchers: float/Constructor validation" time="{duration}"/>
|
||||||
<testcase classname="<exe-name>.global" name="Greater-than inequalities with different epsilons" time="{duration}"/>
|
<testcase classname="<exe-name>.global" name="Greater-than inequalities with different epsilons" time="{duration}"/>
|
||||||
<testcase classname="<exe-name>.global" name="INFO and WARN do not abort tests" time="{duration}"/>
|
<testcase classname="<exe-name>.global" name="INFO and WARN do not abort tests" time="{duration}"/>
|
||||||
<testcase classname="<exe-name>.global" name="INFO gets logged on failure" time="{duration}">
|
<testcase classname="<exe-name>.global" name="INFO gets logged on failure" time="{duration}">
|
||||||
|
@ -2142,6 +2142,41 @@
|
|||||||
</Expression>
|
</Expression>
|
||||||
<OverallResults successes="3" failures="0" expectedFailures="0"/>
|
<OverallResults successes="3" failures="0" expectedFailures="0"/>
|
||||||
</Section>
|
</Section>
|
||||||
|
<Section name="Constructor validation" filename="projects/<exe-name>/UsageTests/Matchers.tests.cpp" >
|
||||||
|
<Expression success="true" type="REQUIRE_NOTHROW" filename="projects/<exe-name>/UsageTests/Matchers.tests.cpp" >
|
||||||
|
<Original>
|
||||||
|
WithinAbs(1., 0.)
|
||||||
|
</Original>
|
||||||
|
<Expanded>
|
||||||
|
WithinAbs(1., 0.)
|
||||||
|
</Expanded>
|
||||||
|
</Expression>
|
||||||
|
<Expression success="true" type="REQUIRE_THROWS_AS" filename="projects/<exe-name>/UsageTests/Matchers.tests.cpp" >
|
||||||
|
<Original>
|
||||||
|
WithinAbs(1., -1.), std::domain_error
|
||||||
|
</Original>
|
||||||
|
<Expanded>
|
||||||
|
WithinAbs(1., -1.), std::domain_error
|
||||||
|
</Expanded>
|
||||||
|
</Expression>
|
||||||
|
<Expression success="true" type="REQUIRE_NOTHROW" filename="projects/<exe-name>/UsageTests/Matchers.tests.cpp" >
|
||||||
|
<Original>
|
||||||
|
WithinULP(1., 0)
|
||||||
|
</Original>
|
||||||
|
<Expanded>
|
||||||
|
WithinULP(1., 0)
|
||||||
|
</Expanded>
|
||||||
|
</Expression>
|
||||||
|
<Expression success="true" type="REQUIRE_THROWS_AS" filename="projects/<exe-name>/UsageTests/Matchers.tests.cpp" >
|
||||||
|
<Original>
|
||||||
|
WithinULP(1., -1), std::domain_error
|
||||||
|
</Original>
|
||||||
|
<Expanded>
|
||||||
|
WithinULP(1., -1), std::domain_error
|
||||||
|
</Expanded>
|
||||||
|
</Expression>
|
||||||
|
<OverallResults successes="4" failures="0" expectedFailures="0"/>
|
||||||
|
</Section>
|
||||||
<OverallResult success="true"/>
|
<OverallResult success="true"/>
|
||||||
</TestCase>
|
</TestCase>
|
||||||
<TestCase name="Floating point matchers: float" tags="[floating-point][matchers]" filename="projects/<exe-name>/UsageTests/Matchers.tests.cpp" >
|
<TestCase name="Floating point matchers: float" tags="[floating-point][matchers]" filename="projects/<exe-name>/UsageTests/Matchers.tests.cpp" >
|
||||||
@ -2282,6 +2317,41 @@
|
|||||||
</Expression>
|
</Expression>
|
||||||
<OverallResults successes="3" failures="0" expectedFailures="0"/>
|
<OverallResults successes="3" failures="0" expectedFailures="0"/>
|
||||||
</Section>
|
</Section>
|
||||||
|
<Section name="Constructor validation" filename="projects/<exe-name>/UsageTests/Matchers.tests.cpp" >
|
||||||
|
<Expression success="true" type="REQUIRE_NOTHROW" filename="projects/<exe-name>/UsageTests/Matchers.tests.cpp" >
|
||||||
|
<Original>
|
||||||
|
WithinAbs(1.f, 0.f)
|
||||||
|
</Original>
|
||||||
|
<Expanded>
|
||||||
|
WithinAbs(1.f, 0.f)
|
||||||
|
</Expanded>
|
||||||
|
</Expression>
|
||||||
|
<Expression success="true" type="REQUIRE_THROWS_AS" filename="projects/<exe-name>/UsageTests/Matchers.tests.cpp" >
|
||||||
|
<Original>
|
||||||
|
WithinAbs(1.f, -1.f), std::domain_error
|
||||||
|
</Original>
|
||||||
|
<Expanded>
|
||||||
|
WithinAbs(1.f, -1.f), std::domain_error
|
||||||
|
</Expanded>
|
||||||
|
</Expression>
|
||||||
|
<Expression success="true" type="REQUIRE_NOTHROW" filename="projects/<exe-name>/UsageTests/Matchers.tests.cpp" >
|
||||||
|
<Original>
|
||||||
|
WithinULP(1.f, 0)
|
||||||
|
</Original>
|
||||||
|
<Expanded>
|
||||||
|
WithinULP(1.f, 0)
|
||||||
|
</Expanded>
|
||||||
|
</Expression>
|
||||||
|
<Expression success="true" type="REQUIRE_THROWS_AS" filename="projects/<exe-name>/UsageTests/Matchers.tests.cpp" >
|
||||||
|
<Original>
|
||||||
|
WithinULP(1.f, -1), std::domain_error
|
||||||
|
</Original>
|
||||||
|
<Expanded>
|
||||||
|
WithinULP(1.f, -1), std::domain_error
|
||||||
|
</Expanded>
|
||||||
|
</Expression>
|
||||||
|
<OverallResults successes="4" failures="0" expectedFailures="0"/>
|
||||||
|
</Section>
|
||||||
<OverallResult success="true"/>
|
<OverallResult success="true"/>
|
||||||
</TestCase>
|
</TestCase>
|
||||||
<TestCase name="Greater-than inequalities with different epsilons" tags="[Approx]" filename="projects/<exe-name>/UsageTests/Approx.tests.cpp" >
|
<TestCase name="Greater-than inequalities with different epsilons" tags="[Approx]" filename="projects/<exe-name>/UsageTests/Approx.tests.cpp" >
|
||||||
@ -8898,7 +8968,7 @@ loose text artifact
|
|||||||
</Section>
|
</Section>
|
||||||
<OverallResult success="true"/>
|
<OverallResult success="true"/>
|
||||||
</TestCase>
|
</TestCase>
|
||||||
<OverallResults successes="827" failures="107" expectedFailures="21"/>
|
<OverallResults successes="835" failures="107" expectedFailures="21"/>
|
||||||
</Group>
|
</Group>
|
||||||
<OverallResults successes="827" failures="106" expectedFailures="21"/>
|
<OverallResults successes="835" failures="106" expectedFailures="21"/>
|
||||||
</Catch>
|
</Catch>
|
||||||
|
@ -298,6 +298,13 @@ namespace { namespace MatchersTests {
|
|||||||
|
|
||||||
REQUIRE_THAT(NAN, !(WithinAbs(NAN, 100) || WithinULP(NAN, 123)));
|
REQUIRE_THAT(NAN, !(WithinAbs(NAN, 100) || WithinULP(NAN, 123)));
|
||||||
}
|
}
|
||||||
|
SECTION("Constructor validation") {
|
||||||
|
REQUIRE_NOTHROW(WithinAbs(1.f, 0.f));
|
||||||
|
REQUIRE_THROWS_AS(WithinAbs(1.f, -1.f), std::domain_error);
|
||||||
|
|
||||||
|
REQUIRE_NOTHROW(WithinULP(1.f, 0));
|
||||||
|
REQUIRE_THROWS_AS(WithinULP(1.f, -1), std::domain_error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Floating point matchers: double", "[matchers][floating-point]") {
|
TEST_CASE("Floating point matchers: double", "[matchers][floating-point]") {
|
||||||
@ -328,6 +335,13 @@ namespace { namespace MatchersTests {
|
|||||||
|
|
||||||
REQUIRE_THAT(NAN, !(WithinAbs(NAN, 100) || WithinULP(NAN, 123)));
|
REQUIRE_THAT(NAN, !(WithinAbs(NAN, 100) || WithinULP(NAN, 123)));
|
||||||
}
|
}
|
||||||
|
SECTION("Constructor validation") {
|
||||||
|
REQUIRE_NOTHROW(WithinAbs(1., 0.));
|
||||||
|
REQUIRE_THROWS_AS(WithinAbs(1., -1.), std::domain_error);
|
||||||
|
|
||||||
|
REQUIRE_NOTHROW(WithinULP(1., 0));
|
||||||
|
REQUIRE_THROWS_AS(WithinULP(1., -1), std::domain_error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} } // namespace MatchersTests
|
} } // namespace MatchersTests
|
||||||
|
Loading…
Reference in New Issue
Block a user