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.next() for: true
GeneratorsImpl.tests.cpp:<line number>: passed: gen.get() == 3 for: 3 == 3 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: !(gen.next()) for: !false
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; }, 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.get() == 1 for: 1 == 1
GeneratorsImpl.tests.cpp:<line number>: passed: gen.next() for: true GeneratorsImpl.tests.cpp:<line number>: passed: gen.next() for: true
GeneratorsImpl.tests.cpp:<line number>: passed: gen.get() == 2 for: 2 == 2 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 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 Generators internals
Filter generator Filter generator
Simple filtering
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
GeneratorsImpl.tests.cpp:<line number> GeneratorsImpl.tests.cpp:<line number>
............................................................................... ...............................................................................
@ -5464,9 +5465,48 @@ GeneratorsImpl.tests.cpp:<line number>: PASSED:
with expansion: with expansion:
!false !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( 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: GeneratorsImpl.tests.cpp:<line number>: PASSED:
REQUIRE_THROWS_AS( filter([](int) { return false; }, value(1)), Catch::GeneratorException ) 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 Generators internals
Take generator Take generator
@ -17228,5 +17268,5 @@ Misc.tests.cpp:<line number>: PASSED:
=============================================================================== ===============================================================================
test cases: 376 | 283 passed | 86 failed | 7 failed as expected 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"?> <?xml version="1.0" encoding="UTF-8"?>
<testsuitesloose text artifact <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> <properties>
<property name="random-seed" value="1"/> <property name="random-seed" value="1"/>
<property name="filters" value="~[!nonportable]~[!benchmark]~[approvals] *"/> <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/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/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/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 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/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"/> <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/Preset values" duration="{duration}"/>
<testCase name="Generators internals/Generator combinator" duration="{duration}"/> <testCase name="Generators internals/Generator combinator" duration="{duration}"/>
<testCase name="Generators internals/Explicitly typed generator sequence" 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 less" duration="{duration}"/>
<testCase name="Generators internals/Take generator/Take more" duration="{duration}"/> <testCase name="Generators internals/Take generator/Take more" duration="{duration}"/>
<testCase name="Generators internals/Map with explicit return type" duration="{duration}"/> <testCase name="Generators internals/Map with explicit return type" duration="{duration}"/>

View File

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

View File

@ -6183,6 +6183,7 @@ Nor would this
<OverallResults successes="7" failures="0" expectedFailures="0"/> <OverallResults successes="7" failures="0" expectedFailures="0"/>
</Section> </Section>
<Section name="Filter generator" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" > <Section name="Filter generator" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<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" > <Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Original> <Original>
gen.get() == 1 gen.get() == 1
@ -6215,6 +6216,50 @@ Nor would this
!false !false
</Expanded> </Expanded>
</Expression> </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" > <Expression success="true" type="REQUIRE_THROWS_AS" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Original> <Original>
filter([](int) { return false; }, value(1)), Catch::GeneratorException filter([](int) { return false; }, value(1)), Catch::GeneratorException
@ -6223,7 +6268,17 @@ Nor would this
filter([](int) { return false; }, value(1)), Catch::GeneratorException filter([](int) { return false; }, value(1)), Catch::GeneratorException
</Expanded> </Expanded>
</Expression> </Expression>
<OverallResults successes="5" failures="0" expectedFailures="0"/> <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>
<Section name="Take generator" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" > <Section name="Take generator" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Section name="Take less" 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> </Section>
<OverallResult success="true"/> <OverallResult success="true"/>
</TestCase> </TestCase>
<OverallResults successes="1986" failures="146" expectedFailures="27"/> <OverallResults successes="1991" failures="146" expectedFailures="27"/>
<OverallResultsCases successes="283" failures="86" expectedFailures="7"/> <OverallResultsCases successes="283" failures="86" expectedFailures="7"/>
</Catch2TestRun> </Catch2TestRun>

View File

@ -50,14 +50,27 @@ TEST_CASE("Generators internals", "[generators][internals]") {
} }
SECTION("Filter generator") { SECTION("Filter generator") {
// Normal usage // Normal usage
SECTION("Simple filtering") {
auto gen = filter([](int i) { return i != 2; }, values({ 2, 1, 2, 3, 2, 2 })); auto gen = filter([](int i) { return i != 2; }, values({ 2, 1, 2, 3, 2, 2 }));
REQUIRE(gen.get() == 1); REQUIRE(gen.get() == 1);
REQUIRE(gen.next()); REQUIRE(gen.next());
REQUIRE(gen.get() == 3); REQUIRE(gen.get() == 3);
REQUIRE_FALSE(gen.next()); 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 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; }, value(1)), Catch::GeneratorException);
REQUIRE_THROWS_AS(
filter([](int) { return false; }, values({ 1, 2, 3 })),
Catch::GeneratorException);
}
} }
SECTION("Take generator") { SECTION("Take generator") {
SECTION("Take less") { SECTION("Take less") {