mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-30 01:03:30 +01:00
Merge pull request #1672 from sommd/master
Fix ChunkGenerator with chunk-size 0
This commit is contained in:
commit
c0d3a2e08f
@ -205,12 +205,14 @@ namespace Generators {
|
|||||||
m_chunk_size(size), m_generator(std::move(generator))
|
m_chunk_size(size), m_generator(std::move(generator))
|
||||||
{
|
{
|
||||||
m_chunk.reserve(m_chunk_size);
|
m_chunk.reserve(m_chunk_size);
|
||||||
m_chunk.push_back(m_generator.get());
|
if (m_chunk_size != 0) {
|
||||||
for (size_t i = 1; i < m_chunk_size; ++i) {
|
|
||||||
if (!m_generator.next()) {
|
|
||||||
Catch::throw_exception(GeneratorException("Not enough values to initialize the first chunk"));
|
|
||||||
}
|
|
||||||
m_chunk.push_back(m_generator.get());
|
m_chunk.push_back(m_generator.get());
|
||||||
|
for (size_t i = 1; i < m_chunk_size; ++i) {
|
||||||
|
if (!m_generator.next()) {
|
||||||
|
Catch::throw_exception(GeneratorException("Not enough values to initialize the first chunk"));
|
||||||
|
}
|
||||||
|
m_chunk.push_back(m_generator.get());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::vector<T> const& get() const override {
|
std::vector<T> const& get() const override {
|
||||||
|
@ -467,6 +467,9 @@ Generators.tests.cpp:<line number>: passed: chunk2.front() < 3 for: 1 < 3
|
|||||||
Generators.tests.cpp:<line number>: passed: chunk2.size() == 2 for: 2 == 2
|
Generators.tests.cpp:<line number>: passed: chunk2.size() == 2 for: 2 == 2
|
||||||
Generators.tests.cpp:<line number>: passed: chunk2.front() == chunk2.back() for: 2 == 2
|
Generators.tests.cpp:<line number>: passed: chunk2.front() == chunk2.back() for: 2 == 2
|
||||||
Generators.tests.cpp:<line number>: passed: chunk2.front() < 3 for: 2 < 3
|
Generators.tests.cpp:<line number>: passed: chunk2.front() < 3 for: 2 < 3
|
||||||
|
Generators.tests.cpp:<line number>: passed: chunk2.size() == 0 for: 0 == 0
|
||||||
|
Generators.tests.cpp:<line number>: passed: chunk2.size() == 0 for: 0 == 0
|
||||||
|
Generators.tests.cpp:<line number>: passed: chunk2.size() == 0 for: 0 == 0
|
||||||
Generators.tests.cpp:<line number>: passed: chunk(2, value(1)), Catch::GeneratorException
|
Generators.tests.cpp:<line number>: passed: chunk(2, value(1)), Catch::GeneratorException
|
||||||
Generators.tests.cpp:<line number>: passed: j < i for: -3 < 1
|
Generators.tests.cpp:<line number>: passed: j < i for: -3 < 1
|
||||||
Generators.tests.cpp:<line number>: passed: j < i for: -2 < 1
|
Generators.tests.cpp:<line number>: passed: j < i for: -2 < 1
|
||||||
|
@ -1381,5 +1381,5 @@ due to unexpected exception with message:
|
|||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
test cases: 295 | 221 passed | 70 failed | 4 failed as expected
|
test cases: 295 | 221 passed | 70 failed | 4 failed as expected
|
||||||
assertions: 1547 | 1395 passed | 131 failed | 21 failed as expected
|
assertions: 1550 | 1398 passed | 131 failed | 21 failed as expected
|
||||||
|
|
||||||
|
@ -3547,6 +3547,45 @@ Generators.tests.cpp:<line number>: PASSED:
|
|||||||
with expansion:
|
with expansion:
|
||||||
2 < 3
|
2 < 3
|
||||||
|
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
Generators -- adapters
|
||||||
|
Chunking a generator into sized pieces
|
||||||
|
Chunk size of zero
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
Generators.tests.cpp:<line number>
|
||||||
|
...............................................................................
|
||||||
|
|
||||||
|
Generators.tests.cpp:<line number>: PASSED:
|
||||||
|
REQUIRE( chunk2.size() == 0 )
|
||||||
|
with expansion:
|
||||||
|
0 == 0
|
||||||
|
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
Generators -- adapters
|
||||||
|
Chunking a generator into sized pieces
|
||||||
|
Chunk size of zero
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
Generators.tests.cpp:<line number>
|
||||||
|
...............................................................................
|
||||||
|
|
||||||
|
Generators.tests.cpp:<line number>: PASSED:
|
||||||
|
REQUIRE( chunk2.size() == 0 )
|
||||||
|
with expansion:
|
||||||
|
0 == 0
|
||||||
|
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
Generators -- adapters
|
||||||
|
Chunking a generator into sized pieces
|
||||||
|
Chunk size of zero
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
Generators.tests.cpp:<line number>
|
||||||
|
...............................................................................
|
||||||
|
|
||||||
|
Generators.tests.cpp:<line number>: PASSED:
|
||||||
|
REQUIRE( chunk2.size() == 0 )
|
||||||
|
with expansion:
|
||||||
|
0 == 0
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Generators -- adapters
|
Generators -- adapters
|
||||||
Chunking a generator into sized pieces
|
Chunking a generator into sized pieces
|
||||||
@ -12335,5 +12374,5 @@ Misc.tests.cpp:<line number>: PASSED:
|
|||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
test cases: 295 | 205 passed | 86 failed | 4 failed as expected
|
test cases: 295 | 205 passed | 86 failed | 4 failed as expected
|
||||||
assertions: 1564 | 1395 passed | 148 failed | 21 failed as expected
|
assertions: 1567 | 1398 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="1565" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
|
<testsuite name="<exe-name>" errors="17" failures="132" tests="1568" 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"/>
|
||||||
@ -416,6 +416,7 @@ Message.tests.cpp:<line number>
|
|||||||
<testcase classname="<exe-name>.global" name="Generators -- adapters/Repeating a generator" time="{duration}"/>
|
<testcase classname="<exe-name>.global" name="Generators -- adapters/Repeating a generator" time="{duration}"/>
|
||||||
<testcase classname="<exe-name>.global" name="Generators -- adapters/Chunking a generator into sized pieces/Number of elements in source is divisible by chunk size" time="{duration}"/>
|
<testcase classname="<exe-name>.global" name="Generators -- adapters/Chunking a generator into sized pieces/Number of elements in source is divisible by chunk size" time="{duration}"/>
|
||||||
<testcase classname="<exe-name>.global" name="Generators -- adapters/Chunking a generator into sized pieces/Number of elements in source is not divisible by chunk size" time="{duration}"/>
|
<testcase classname="<exe-name>.global" name="Generators -- adapters/Chunking a generator into sized pieces/Number of elements in source is not divisible by chunk size" time="{duration}"/>
|
||||||
|
<testcase classname="<exe-name>.global" name="Generators -- adapters/Chunking a generator into sized pieces/Chunk size of zero" time="{duration}"/>
|
||||||
<testcase classname="<exe-name>.global" name="Generators -- adapters/Chunking a generator into sized pieces/Throws on too small generators" time="{duration}"/>
|
<testcase classname="<exe-name>.global" name="Generators -- adapters/Chunking a generator into sized pieces/Throws on too small generators" time="{duration}"/>
|
||||||
<testcase classname="<exe-name>.global" name="Generators -- simple/one" time="{duration}"/>
|
<testcase classname="<exe-name>.global" name="Generators -- simple/one" time="{duration}"/>
|
||||||
<testcase classname="<exe-name>.global" name="Generators -- simple/two" time="{duration}"/>
|
<testcase classname="<exe-name>.global" name="Generators -- simple/two" time="{duration}"/>
|
||||||
|
@ -4260,6 +4260,48 @@ Nor would this
|
|||||||
</Section>
|
</Section>
|
||||||
<OverallResults successes="3" failures="0" expectedFailures="0"/>
|
<OverallResults successes="3" failures="0" expectedFailures="0"/>
|
||||||
</Section>
|
</Section>
|
||||||
|
<Section name="Chunking a generator into sized pieces" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
|
||||||
|
<Section name="Chunk size of zero" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
|
||||||
|
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
|
||||||
|
<Original>
|
||||||
|
chunk2.size() == 0
|
||||||
|
</Original>
|
||||||
|
<Expanded>
|
||||||
|
0 == 0
|
||||||
|
</Expanded>
|
||||||
|
</Expression>
|
||||||
|
<OverallResults successes="1" failures="0" expectedFailures="0"/>
|
||||||
|
</Section>
|
||||||
|
<OverallResults successes="1" failures="0" expectedFailures="0"/>
|
||||||
|
</Section>
|
||||||
|
<Section name="Chunking a generator into sized pieces" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
|
||||||
|
<Section name="Chunk size of zero" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
|
||||||
|
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
|
||||||
|
<Original>
|
||||||
|
chunk2.size() == 0
|
||||||
|
</Original>
|
||||||
|
<Expanded>
|
||||||
|
0 == 0
|
||||||
|
</Expanded>
|
||||||
|
</Expression>
|
||||||
|
<OverallResults successes="1" failures="0" expectedFailures="0"/>
|
||||||
|
</Section>
|
||||||
|
<OverallResults successes="1" failures="0" expectedFailures="0"/>
|
||||||
|
</Section>
|
||||||
|
<Section name="Chunking a generator into sized pieces" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
|
||||||
|
<Section name="Chunk size of zero" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
|
||||||
|
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
|
||||||
|
<Original>
|
||||||
|
chunk2.size() == 0
|
||||||
|
</Original>
|
||||||
|
<Expanded>
|
||||||
|
0 == 0
|
||||||
|
</Expanded>
|
||||||
|
</Expression>
|
||||||
|
<OverallResults successes="1" failures="0" expectedFailures="0"/>
|
||||||
|
</Section>
|
||||||
|
<OverallResults successes="1" failures="0" expectedFailures="0"/>
|
||||||
|
</Section>
|
||||||
<Section name="Chunking a generator into sized pieces" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
|
<Section name="Chunking a generator into sized pieces" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
|
||||||
<Section name="Throws on too small generators" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
|
<Section name="Throws on too small generators" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
|
||||||
<Expression success="true" type="REQUIRE_THROWS_AS" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
|
<Expression success="true" type="REQUIRE_THROWS_AS" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
|
||||||
@ -14692,7 +14734,7 @@ loose text artifact
|
|||||||
</Section>
|
</Section>
|
||||||
<OverallResult success="true"/>
|
<OverallResult success="true"/>
|
||||||
</TestCase>
|
</TestCase>
|
||||||
<OverallResults successes="1395" failures="149" expectedFailures="21"/>
|
<OverallResults successes="1398" failures="149" expectedFailures="21"/>
|
||||||
</Group>
|
</Group>
|
||||||
<OverallResults successes="1395" failures="148" expectedFailures="21"/>
|
<OverallResults successes="1398" failures="148" expectedFailures="21"/>
|
||||||
</Catch>
|
</Catch>
|
||||||
|
@ -167,6 +167,10 @@ TEST_CASE("Generators -- adapters", "[generators][generic]") {
|
|||||||
REQUIRE(chunk2.front() == chunk2.back());
|
REQUIRE(chunk2.front() == chunk2.back());
|
||||||
REQUIRE(chunk2.front() < 3);
|
REQUIRE(chunk2.front() < 3);
|
||||||
}
|
}
|
||||||
|
SECTION("Chunk size of zero") {
|
||||||
|
auto chunk2 = GENERATE(take(3, chunk(0, value(1))));
|
||||||
|
REQUIRE(chunk2.size() == 0);
|
||||||
|
}
|
||||||
SECTION("Throws on too small generators") {
|
SECTION("Throws on too small generators") {
|
||||||
using namespace Catch::Generators;
|
using namespace Catch::Generators;
|
||||||
REQUIRE_THROWS_AS(chunk(2, value(1)), Catch::GeneratorException);
|
REQUIRE_THROWS_AS(chunk(2, value(1)), Catch::GeneratorException);
|
||||||
|
Loading…
Reference in New Issue
Block a user