Add another test for FilterGenerator

This commit is contained in:
Martin Hořeňovský 2019-02-23 20:37:30 +01:00
parent 693647c43f
commit ef5fd8d42f
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
6 changed files with 78 additions and 33 deletions

View File

@ -402,6 +402,7 @@ Matchers.tests.cpp:<line number>: passed: WithinULP(1.f, -1), std::domain_error
Generators.tests.cpp:<line number>: passed: i % 2 == 0 for: 0 == 0 Generators.tests.cpp:<line number>: passed: i % 2 == 0 for: 0 == 0
Generators.tests.cpp:<line number>: passed: i % 2 == 0 for: 0 == 0 Generators.tests.cpp:<line number>: passed: i % 2 == 0 for: 0 == 0
Generators.tests.cpp:<line number>: passed: i % 2 == 0 for: 0 == 0 Generators.tests.cpp:<line number>: passed: i % 2 == 0 for: 0 == 0
Generators.tests.cpp:<line number>: passed: filter([] (int) {return false; }, value(1)), Catch::GeneratorException
Generators.tests.cpp:<line number>: passed: i < 4 for: 1 < 4 Generators.tests.cpp:<line number>: passed: i < 4 for: 1 < 4
Generators.tests.cpp:<line number>: passed: i < 4 for: 2 < 4 Generators.tests.cpp:<line number>: passed: i < 4 for: 2 < 4
Generators.tests.cpp:<line number>: passed: i < 4 for: 3 < 4 Generators.tests.cpp:<line number>: passed: i < 4 for: 3 < 4

View File

@ -1175,5 +1175,5 @@ due to unexpected exception with message:
=============================================================================== ===============================================================================
test cases: 245 | 185 passed | 56 failed | 4 failed as expected test cases: 245 | 185 passed | 56 failed | 4 failed as expected
assertions: 1378 | 1242 passed | 115 failed | 21 failed as expected assertions: 1379 | 1243 passed | 115 failed | 21 failed as expected

View File

@ -2861,6 +2861,7 @@ Matchers.tests.cpp:<line number>: PASSED:
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Generators -- adapters Generators -- adapters
Filtering by predicate Filtering by predicate
Basic usage
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Generators.tests.cpp:<line number> Generators.tests.cpp:<line number>
............................................................................... ...............................................................................
@ -2873,6 +2874,7 @@ with expansion:
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Generators -- adapters Generators -- adapters
Filtering by predicate Filtering by predicate
Basic usage
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Generators.tests.cpp:<line number> Generators.tests.cpp:<line number>
............................................................................... ...............................................................................
@ -2885,6 +2887,7 @@ with expansion:
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Generators -- adapters Generators -- adapters
Filtering by predicate Filtering by predicate
Basic usage
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Generators.tests.cpp:<line number> Generators.tests.cpp:<line number>
............................................................................... ...............................................................................
@ -2894,6 +2897,17 @@ Generators.tests.cpp:<line number>: PASSED:
with expansion: with expansion:
0 == 0 0 == 0
-------------------------------------------------------------------------------
Generators -- adapters
Filtering by predicate
Throws if there are no matching values
-------------------------------------------------------------------------------
Generators.tests.cpp:<line number>
...............................................................................
Generators.tests.cpp:<line number>: PASSED:
REQUIRE_THROWS_AS( filter([] (int) {return false; }, value(1)), Catch::GeneratorException )
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Generators -- adapters Generators -- adapters
Shortening a range Shortening a range
@ -10685,5 +10699,5 @@ Misc.tests.cpp:<line number>: PASSED:
=============================================================================== ===============================================================================
test cases: 245 | 172 passed | 69 failed | 4 failed as expected test cases: 245 | 172 passed | 69 failed | 4 failed as expected
assertions: 1392 | 1242 passed | 129 failed | 21 failed as expected assertions: 1393 | 1243 passed | 129 failed | 21 failed as expected

View File

@ -4,7 +4,7 @@
<property name="random-seed" value="1"/> <property name="random-seed" value="1"/>
</properties> </properties>
loose text artifact loose text artifact
<testsuite name="<exe-name>" errors="17" failures="113" tests="1393" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> <testsuite name="<exe-name>" errors="17" failures="113" tests="1394" 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}"/>
@ -342,7 +342,8 @@ Message.tests.cpp:<line number>
<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="Floating point matchers: float/Constructor validation" time="{duration}"/>
<testcase classname="<exe-name>.global" name="Generators -- adapters/Filtering by predicate" time="{duration}"/> <testcase classname="<exe-name>.global" name="Generators -- adapters/Filtering by predicate/Basic usage" time="{duration}"/>
<testcase classname="<exe-name>.global" name="Generators -- adapters/Filtering by predicate/Throws if there are no matching values" time="{duration}"/>
<testcase classname="<exe-name>.global" name="Generators -- adapters/Shortening a range" time="{duration}"/> <testcase classname="<exe-name>.global" name="Generators -- adapters/Shortening a range" time="{duration}"/>
<testcase classname="<exe-name>.global" name="Generators -- adapters/Transforming elements/Same type" time="{duration}"/> <testcase classname="<exe-name>.global" name="Generators -- adapters/Transforming elements/Same type" time="{duration}"/>
<testcase classname="<exe-name>.global" name="Generators -- adapters/Transforming elements/Different type" time="{duration}"/> <testcase classname="<exe-name>.global" name="Generators -- adapters/Transforming elements/Different type" time="{duration}"/>

View File

@ -3540,6 +3540,7 @@
</TestCase> </TestCase>
<TestCase name="Generators -- adapters" tags="[generators][generic]" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" > <TestCase name="Generators -- adapters" tags="[generators][generic]" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
<Section name="Filtering by predicate" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" > <Section name="Filtering by predicate" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
<Section name="Basic usage" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" > <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
<Original> <Original>
i % 2 == 0 i % 2 == 0
@ -3550,7 +3551,10 @@
</Expression> </Expression>
<OverallResults successes="1" failures="0" expectedFailures="0"/> <OverallResults successes="1" failures="0" expectedFailures="0"/>
</Section> </Section>
<OverallResults successes="1" failures="0" expectedFailures="0"/>
</Section>
<Section name="Filtering by predicate" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" > <Section name="Filtering by predicate" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
<Section name="Basic usage" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" > <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
<Original> <Original>
i % 2 == 0 i % 2 == 0
@ -3561,7 +3565,10 @@
</Expression> </Expression>
<OverallResults successes="1" failures="0" expectedFailures="0"/> <OverallResults successes="1" failures="0" expectedFailures="0"/>
</Section> </Section>
<OverallResults successes="1" failures="0" expectedFailures="0"/>
</Section>
<Section name="Filtering by predicate" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" > <Section name="Filtering by predicate" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
<Section name="Basic usage" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" > <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
<Original> <Original>
i % 2 == 0 i % 2 == 0
@ -3572,6 +3579,22 @@
</Expression> </Expression>
<OverallResults successes="1" failures="0" expectedFailures="0"/> <OverallResults successes="1" failures="0" expectedFailures="0"/>
</Section> </Section>
<OverallResults successes="1" failures="0" expectedFailures="0"/>
</Section>
<Section name="Filtering by predicate" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
<Section name="Throws if there are no matching values" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
<Expression success="true" type="REQUIRE_THROWS_AS" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
<Original>
filter([] (int) {return false; }, value(1)), Catch::GeneratorException
</Original>
<Expanded>
filter([] (int) {return false; }, value(1)), Catch::GeneratorException
</Expanded>
</Expression>
<OverallResults successes="1" failures="0" expectedFailures="0"/>
</Section>
<OverallResults successes="1" failures="0" expectedFailures="0"/>
</Section>
<Section name="Shortening a range" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" > <Section name="Shortening a range" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" > <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
<Original> <Original>
@ -12925,7 +12948,7 @@ loose text artifact
</Section> </Section>
<OverallResult success="true"/> <OverallResult success="true"/>
</TestCase> </TestCase>
<OverallResults successes="1242" failures="130" expectedFailures="21"/> <OverallResults successes="1243" failures="130" expectedFailures="21"/>
</Group> </Group>
<OverallResults successes="1242" failures="129" expectedFailures="21"/> <OverallResults successes="1243" failures="129" expectedFailures="21"/>
</Catch> </Catch>

View File

@ -118,10 +118,16 @@ TEST_CASE("Generators -- adapters", "[generators][generic]") {
// TODO: This won't work yet, introduce GENERATE_VAR? // TODO: This won't work yet, introduce GENERATE_VAR?
//auto numbers = Catch::Generators::values({ 1, 2, 3, 4, 5, 6 }); //auto numbers = Catch::Generators::values({ 1, 2, 3, 4, 5, 6 });
SECTION("Filtering by predicate") { SECTION("Filtering by predicate") {
SECTION("Basic usage") {
// This filters out all odd (false) numbers, giving [2, 4, 6] // This filters out all odd (false) numbers, giving [2, 4, 6]
auto i = GENERATE(filter([] (int val) { return val % 2 == 0; }, values({ 1, 2, 3, 4, 5, 6 }))); auto i = GENERATE(filter([] (int val) { return val % 2 == 0; }, values({ 1, 2, 3, 4, 5, 6 })));
REQUIRE(i % 2 == 0); REQUIRE(i % 2 == 0);
} }
SECTION("Throws if there are no matching values") {
using namespace Catch::Generators;
REQUIRE_THROWS_AS(filter([] (int) {return false; }, value(1)), Catch::GeneratorException);
}
}
SECTION("Shortening a range") { SECTION("Shortening a range") {
// This takes the first 3 elements from the values, giving back [1, 2, 3] // This takes the first 3 elements from the values, giving back [1, 2, 3]
auto i = GENERATE(take(3, values({ 1, 2, 3, 4, 5, 6 }))); auto i = GENERATE(take(3, values({ 1, 2, 3, 4, 5, 6 })));