Add test for filtering out multiple initial values in filter gen

This commit is contained in:
Martin Hořeňovský 2021-10-28 11:26:34 +02:00
parent 514206df36
commit 3c5c86a4e4
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
8 changed files with 185 additions and 58 deletions

View File

@ -695,7 +695,12 @@ GeneratorsImpl.tests.cpp:<line number>: passed: gen.get() == 1 for: 1 == 1
GeneratorsImpl.tests.cpp:<line number>: passed: gen.next() for: true
GeneratorsImpl.tests.cpp:<line number>: passed: gen.get() == 3 for: 3 == 3
GeneratorsImpl.tests.cpp:<line number>: passed: !(gen.next()) for: !false
GeneratorsImpl.tests.cpp:<line number>: passed: filter([] (int) { return false; }, value(1)), Catch::GeneratorException
GeneratorsImpl.tests.cpp:<line number>: passed: gen.get() == 1 for: 1 == 1
GeneratorsImpl.tests.cpp:<line number>: passed: gen.next() for: true
GeneratorsImpl.tests.cpp:<line number>: passed: gen.get() == 3 for: 3 == 3
GeneratorsImpl.tests.cpp:<line number>: passed: !(gen.next()) for: !false
GeneratorsImpl.tests.cpp:<line number>: passed: filter([](int) { return false; }, value(1)), Catch::GeneratorException
GeneratorsImpl.tests.cpp:<line number>: passed: filter([](int) { return false; }, values({ 1, 2, 3 })), Catch::GeneratorException
GeneratorsImpl.tests.cpp:<line number>: passed: gen.get() == 1 for: 1 == 1
GeneratorsImpl.tests.cpp:<line number>: passed: gen.next() for: true
GeneratorsImpl.tests.cpp:<line number>: passed: gen.get() == 2 for: 2 == 2

View File

@ -1427,5 +1427,5 @@ due to unexpected exception with message:
===============================================================================
test cases: 376 | 299 passed | 70 failed | 7 failed as expected
assertions: 2142 | 1986 passed | 129 failed | 27 failed as expected
assertions: 2147 | 1991 passed | 129 failed | 27 failed as expected

View File

@ -5440,6 +5440,7 @@ with expansion:
-------------------------------------------------------------------------------
Generators internals
Filter generator
Simple filtering
-------------------------------------------------------------------------------
GeneratorsImpl.tests.cpp:<line number>
...............................................................................
@ -5464,8 +5465,47 @@ GeneratorsImpl.tests.cpp:<line number>: PASSED:
with expansion:
!false
-------------------------------------------------------------------------------
Generators internals
Filter generator
Filter out multiple elements at the start and end
-------------------------------------------------------------------------------
GeneratorsImpl.tests.cpp:<line number>
...............................................................................
GeneratorsImpl.tests.cpp:<line number>: PASSED:
REQUIRE_THROWS_AS( filter([] (int) { return false; }, value(1)), Catch::GeneratorException )
REQUIRE( gen.get() == 1 )
with expansion:
1 == 1
GeneratorsImpl.tests.cpp:<line number>: PASSED:
REQUIRE( gen.next() )
with expansion:
true
GeneratorsImpl.tests.cpp:<line number>: PASSED:
REQUIRE( gen.get() == 3 )
with expansion:
3 == 3
GeneratorsImpl.tests.cpp:<line number>: PASSED:
REQUIRE_FALSE( gen.next() )
with expansion:
!false
-------------------------------------------------------------------------------
Generators internals
Filter generator
Throws on construction if it can't get initial element
-------------------------------------------------------------------------------
GeneratorsImpl.tests.cpp:<line number>
...............................................................................
GeneratorsImpl.tests.cpp:<line number>: PASSED:
REQUIRE_THROWS_AS( filter([](int) { return false; }, value(1)), Catch::GeneratorException )
GeneratorsImpl.tests.cpp:<line number>: PASSED:
REQUIRE_THROWS_AS( filter([](int) { return false; }, values({ 1, 2, 3 })), Catch::GeneratorException )
-------------------------------------------------------------------------------
Generators internals
@ -17228,5 +17268,5 @@ Misc.tests.cpp:<line number>: PASSED:
===============================================================================
test cases: 376 | 283 passed | 86 failed | 7 failed as expected
assertions: 2159 | 1986 passed | 146 failed | 27 failed as expected
assertions: 2164 | 1991 passed | 146 failed | 27 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="129" tests="2159" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<testsuite name="<exe-name>" errors="17" failures="129" tests="2164" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<properties>
<property name="random-seed" value="1"/>
<property name="filters" value="~[!nonportable]~[!benchmark]~[approvals] *"/>
@ -698,7 +698,9 @@ Message.tests.cpp:<line number>
<testcase classname="<exe-name>.global" name="Generators internals/Preset values" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Generators internals/Generator combinator" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Generators internals/Explicitly typed generator sequence" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Generators internals/Filter generator" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Generators internals/Filter generator/Simple filtering" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Generators internals/Filter generator/Filter out multiple elements at the start and end" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Generators internals/Filter generator/Throws on construction if it can't get initial element" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Generators internals/Take generator/Take less" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Generators internals/Take generator/Take more" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Generators internals/Map with explicit return type" time="{duration}" status="run"/>

View File

@ -94,7 +94,9 @@
<testCase name="Generators internals/Preset values" duration="{duration}"/>
<testCase name="Generators internals/Generator combinator" duration="{duration}"/>
<testCase name="Generators internals/Explicitly typed generator sequence" duration="{duration}"/>
<testCase name="Generators internals/Filter generator" duration="{duration}"/>
<testCase name="Generators internals/Filter generator/Simple filtering" duration="{duration}"/>
<testCase name="Generators internals/Filter generator/Filter out multiple elements at the start and end" duration="{duration}"/>
<testCase name="Generators internals/Filter generator/Throws on construction if it can't get initial element" duration="{duration}"/>
<testCase name="Generators internals/Take generator/Take less" duration="{duration}"/>
<testCase name="Generators internals/Take generator/Take more" duration="{duration}"/>
<testCase name="Generators internals/Map with explicit return type" duration="{duration}"/>

View File

@ -1373,7 +1373,17 @@ ok {test-number} - gen.get() == 3 for: 3 == 3
# Generators internals
ok {test-number} - !(gen.next()) for: !false
# Generators internals
ok {test-number} - filter([] (int) { return false; }, value(1)), Catch::GeneratorException
ok {test-number} - gen.get() == 1 for: 1 == 1
# Generators internals
ok {test-number} - gen.next() for: true
# Generators internals
ok {test-number} - gen.get() == 3 for: 3 == 3
# Generators internals
ok {test-number} - !(gen.next()) for: !false
# Generators internals
ok {test-number} - filter([](int) { return false; }, value(1)), Catch::GeneratorException
# Generators internals
ok {test-number} - filter([](int) { return false; }, values({ 1, 2, 3 })), Catch::GeneratorException
# Generators internals
ok {test-number} - gen.get() == 1 for: 1 == 1
# Generators internals
@ -4320,5 +4330,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0
ok {test-number} -
# xmlentitycheck
ok {test-number} -
1..2159
1..2164

View File

@ -6183,47 +6183,102 @@ Nor would this
<OverallResults successes="7" failures="0" expectedFailures="0"/>
</Section>
<Section name="Filter generator" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Original>
gen.get() == 1
</Original>
<Expanded>
1 == 1
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Original>
gen.next()
</Original>
<Expanded>
true
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Original>
gen.get() == 3
</Original>
<Expanded>
3 == 3
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE_FALSE" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Original>
!(gen.next())
</Original>
<Expanded>
!false
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE_THROWS_AS" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.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="5" failures="0" expectedFailures="0"/>
<Section name="Simple filtering" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Original>
gen.get() == 1
</Original>
<Expanded>
1 == 1
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Original>
gen.next()
</Original>
<Expanded>
true
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Original>
gen.get() == 3
</Original>
<Expanded>
3 == 3
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE_FALSE" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Original>
!(gen.next())
</Original>
<Expanded>
!false
</Expanded>
</Expression>
<OverallResults successes="4" failures="0" expectedFailures="0"/>
</Section>
<OverallResults successes="4" failures="0" expectedFailures="0"/>
</Section>
<Section name="Filter generator" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Section name="Filter out multiple elements at the start and end" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Original>
gen.get() == 1
</Original>
<Expanded>
1 == 1
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Original>
gen.next()
</Original>
<Expanded>
true
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Original>
gen.get() == 3
</Original>
<Expanded>
3 == 3
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE_FALSE" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Original>
!(gen.next())
</Original>
<Expanded>
!false
</Expanded>
</Expression>
<OverallResults successes="4" failures="0" expectedFailures="0"/>
</Section>
<OverallResults successes="4" failures="0" expectedFailures="0"/>
</Section>
<Section name="Filter generator" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Section name="Throws on construction if it can't get initial element" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Expression success="true" type="REQUIRE_THROWS_AS" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Original>
filter([](int) { return false; }, value(1)), Catch::GeneratorException
</Original>
<Expanded>
filter([](int) { return false; }, value(1)), Catch::GeneratorException
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE_THROWS_AS" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Original>
filter([](int) { return false; }, values({ 1, 2, 3 })), Catch::GeneratorException
</Original>
<Expanded>
filter([](int) { return false; }, values({ 1, 2, 3 })), Catch::GeneratorException
</Expanded>
</Expression>
<OverallResults successes="2" failures="0" expectedFailures="0"/>
</Section>
<OverallResults successes="2" failures="0" expectedFailures="0"/>
</Section>
<Section name="Take generator" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Section name="Take less" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
@ -20183,6 +20238,6 @@ loose text artifact
</Section>
<OverallResult success="true"/>
</TestCase>
<OverallResults successes="1986" failures="146" expectedFailures="27"/>
<OverallResults successes="1991" failures="146" expectedFailures="27"/>
<OverallResultsCases successes="283" failures="86" expectedFailures="7"/>
</Catch2TestRun>

View File

@ -50,14 +50,27 @@ TEST_CASE("Generators internals", "[generators][internals]") {
}
SECTION("Filter generator") {
// Normal usage
auto gen = filter([] (int i) { return i != 2; }, values({ 2, 1, 2, 3, 2, 2 }));
REQUIRE(gen.get() == 1);
REQUIRE(gen.next());
REQUIRE(gen.get() == 3);
REQUIRE_FALSE(gen.next());
SECTION("Simple filtering") {
auto gen = filter([](int i) { return i != 2; }, values({ 2, 1, 2, 3, 2, 2 }));
REQUIRE(gen.get() == 1);
REQUIRE(gen.next());
REQUIRE(gen.get() == 3);
REQUIRE_FALSE(gen.next());
}
SECTION("Filter out multiple elements at the start and end") {
auto gen = filter([](int i) { return i != 2; }, values({ 2, 2, 1, 3, 2, 2 }));
REQUIRE(gen.get() == 1);
REQUIRE(gen.next());
REQUIRE(gen.get() == 3);
REQUIRE_FALSE(gen.next());
}
// Completely filtered-out generator should throw on construction
REQUIRE_THROWS_AS(filter([] (int) { return false; }, value(1)), Catch::GeneratorException);
SECTION("Throws on construction if it can't get initial element") {
REQUIRE_THROWS_AS(filter([](int) { return false; }, value(1)), Catch::GeneratorException);
REQUIRE_THROWS_AS(
filter([](int) { return false; }, values({ 1, 2, 3 })),
Catch::GeneratorException);
}
}
SECTION("Take generator") {
SECTION("Take less") {