diff --git a/src/catch2/generators/catch_generators.hpp b/src/catch2/generators/catch_generators.hpp index 0f35a996..e64f9b5f 100644 --- a/src/catch2/generators/catch_generators.hpp +++ b/src/catch2/generators/catch_generators.hpp @@ -93,6 +93,15 @@ namespace Detail { "specialization, use SingleValue Generator instead."); std::vector m_values; size_t m_idx = 0; + + void skipToNthElementImpl( std::size_t n ) override { + if ( n >= m_values.size() ) { + Detail::throw_generator_exception( + "Coud not jump to Nth element: not enough elements" ); + } + m_idx = n; + } + public: FixedValuesGenerator( std::initializer_list values ) : m_values( values ) {} diff --git a/src/catch2/generators/catch_generators_adapters.hpp b/src/catch2/generators/catch_generators_adapters.hpp index 01f7c622..35c103ce 100644 --- a/src/catch2/generators/catch_generators_adapters.hpp +++ b/src/catch2/generators/catch_generators_adapters.hpp @@ -22,6 +22,22 @@ namespace Generators { GeneratorWrapper m_generator; size_t m_returned = 0; size_t m_target; + + void skipToNthElementImpl( std::size_t n ) override { + if ( n >= m_target ) { + Detail::throw_generator_exception( + "Coud not jump to Nth element: not enough elements" ); + } + + for (; m_returned < n; ++m_returned) { + const auto success = m_generator.next(); + if ( !success ) { + Detail::throw_generator_exception( + "Coud not jump to Nth element: not enough elements" ); + } + } + } + public: TakeGenerator(size_t target, GeneratorWrapper&& generator): m_generator(CATCH_MOVE(generator)), @@ -158,6 +174,21 @@ namespace Generators { Func m_function; // To avoid returning dangling reference, we have to save the values T m_cache; + + void skipToNthElementImpl( std::size_t n ) override { + for ( size_t curr = GeneratorUntypedBase::currentElementIndex(); + curr < n; + ++curr ) { + const auto success = m_generator.next(); + if (!success) { + Detail::throw_generator_exception( + "Coud not jump to Nth element: not enough elements" ); + } + } + + m_cache = m_function( m_generator.get() ); + } + public: template MapGenerator(F2&& function, GeneratorWrapper&& generator) : diff --git a/tests/SelfTest/Baselines/automake.sw.approved.txt b/tests/SelfTest/Baselines/automake.sw.approved.txt index cf504a78..314feb2f 100644 --- a/tests/SelfTest/Baselines/automake.sw.approved.txt +++ b/tests/SelfTest/Baselines/automake.sw.approved.txt @@ -165,6 +165,7 @@ Nor would this :test-result: FAIL FAIL_CHECK does not abort the test :test-result: PASS Factorials are computed :test-result: PASS Filter generator throws exception for empty generator +:test-result: PASS FixedValuesGenerator can be skipped forward :test-result: PASS Floating point matchers: double :test-result: PASS Floating point matchers: float :test-result: PASS GENERATE can combine literals and generators @@ -190,6 +191,7 @@ Nor would this :test-result: PASS Lambdas in assertions :test-result: PASS Less-than inequalities with different epsilons :test-result: PASS ManuallyRegistered +:test-result: PASS MapGenerator can be skipped forward efficiently :test-result: PASS Matchers can be (AllOf) composed with the && operator :test-result: PASS Matchers can be (AnyOf) composed with the || operator :test-result: PASS Matchers can be composed with both && and || @@ -262,6 +264,7 @@ Message from section two :test-result: FAIL Tabs and newlines show in output :test-result: PASS Tag alias can be registered against tag patterns :test-result: PASS Tags with spaces and non-alphanumerical characters are accepted +:test-result: PASS TakeGenerator can be skipped forward :test-result: PASS Template test case method with test types specified inside std::tuple - MyTypes - 0 :test-result: PASS Template test case method with test types specified inside std::tuple - MyTypes - 1 :test-result: PASS Template test case method with test types specified inside std::tuple - MyTypes - 2 diff --git a/tests/SelfTest/Baselines/automake.sw.multi.approved.txt b/tests/SelfTest/Baselines/automake.sw.multi.approved.txt index 2b4b1ba7..e646593d 100644 --- a/tests/SelfTest/Baselines/automake.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/automake.sw.multi.approved.txt @@ -163,6 +163,7 @@ :test-result: FAIL FAIL_CHECK does not abort the test :test-result: PASS Factorials are computed :test-result: PASS Filter generator throws exception for empty generator +:test-result: PASS FixedValuesGenerator can be skipped forward :test-result: PASS Floating point matchers: double :test-result: PASS Floating point matchers: float :test-result: PASS GENERATE can combine literals and generators @@ -188,6 +189,7 @@ :test-result: PASS Lambdas in assertions :test-result: PASS Less-than inequalities with different epsilons :test-result: PASS ManuallyRegistered +:test-result: PASS MapGenerator can be skipped forward efficiently :test-result: PASS Matchers can be (AllOf) composed with the && operator :test-result: PASS Matchers can be (AnyOf) composed with the || operator :test-result: PASS Matchers can be composed with both && and || @@ -255,6 +257,7 @@ :test-result: FAIL Tabs and newlines show in output :test-result: PASS Tag alias can be registered against tag patterns :test-result: PASS Tags with spaces and non-alphanumerical characters are accepted +:test-result: PASS TakeGenerator can be skipped forward :test-result: PASS Template test case method with test types specified inside std::tuple - MyTypes - 0 :test-result: PASS Template test case method with test types specified inside std::tuple - MyTypes - 1 :test-result: PASS Template test case method with test types specified inside std::tuple - MyTypes - 2 diff --git a/tests/SelfTest/Baselines/compact.sw.approved.txt b/tests/SelfTest/Baselines/compact.sw.approved.txt index 8f7f2bf9..94123b41 100644 --- a/tests/SelfTest/Baselines/compact.sw.approved.txt +++ b/tests/SelfTest/Baselines/compact.sw.approved.txt @@ -678,6 +678,12 @@ Misc.tests.cpp:: passed: Factorial(2) == 2 for: 2 == 2 Misc.tests.cpp:: passed: Factorial(3) == 6 for: 6 == 6 Misc.tests.cpp:: passed: Factorial(10) == 3628800 for: 3628800 (0x) == 3628800 (0x) GeneratorsImpl.tests.cpp:: passed: filter( []( int ) { return false; }, value( 3 ) ), Catch::GeneratorException +GeneratorsImpl.tests.cpp:: passed: values.currentElementIndex() == 0 for: 0 == 0 +GeneratorsImpl.tests.cpp:: passed: values.currentElementIndex() == 3 for: 3 == 3 +GeneratorsImpl.tests.cpp:: passed: values.get() == 3 for: 3 == 3 +GeneratorsImpl.tests.cpp:: passed: values.currentElementIndex() == 4 for: 4 == 4 +GeneratorsImpl.tests.cpp:: passed: values.get() == 4 for: 4 == 4 +GeneratorsImpl.tests.cpp:: passed: values.skipToNthElement( 5 ) Matchers.tests.cpp:: passed: 10., WithinRel( 11.1, 0.1 ) for: 10.0 and 11.09999999999999964 are within 10% of each other Matchers.tests.cpp:: passed: 10., !WithinRel( 11.2, 0.1 ) for: 10.0 not and 11.19999999999999929 are within 10% of each other Matchers.tests.cpp:: passed: 1., !WithinRel( 0., 0.99 ) for: 1.0 not and 0.0 are within 99% of each other @@ -1243,6 +1249,14 @@ Approx.tests.cpp:: passed: d <= Approx( 1.22 ).epsilon(0.1) for: 1. <= Approx( 1.21999999999999997 ) Misc.tests.cpp:: passed: with 1 message: 'was called' +GeneratorsImpl.tests.cpp:: passed: map_generator.get() == 4 for: 4 == 4 +GeneratorsImpl.tests.cpp:: passed: map_calls == map_calls_1 + 1 for: 2 == 2 +GeneratorsImpl.tests.cpp:: passed: map_generator.get() == 4 for: 4 == 4 +GeneratorsImpl.tests.cpp:: passed: map_calls == map_calls_1 + 1 for: 2 == 2 +GeneratorsImpl.tests.cpp:: passed: map_generator.get() == 6 for: 6 == 6 +GeneratorsImpl.tests.cpp:: passed: map_calls == map_calls_2 + 1 for: 3 == 3 +GeneratorsImpl.tests.cpp:: passed: map_generator.skipToNthElement( 7 ) +GeneratorsImpl.tests.cpp:: passed: map_calls == map_calls_2 + 1 for: 3 == 3 Matchers.tests.cpp:: passed: testStringForMatching(), ContainsSubstring( "string" ) && ContainsSubstring( "abc" ) && ContainsSubstring( "substring" ) && ContainsSubstring( "contains" ) for: "this string contains 'abc' as a substring" ( contains: "string" and contains: "abc" and contains: "substring" and contains: "contains" ) Matchers.tests.cpp:: passed: testStringForMatching(), ContainsSubstring( "string" ) || ContainsSubstring( "different" ) || ContainsSubstring( "random" ) for: "this string contains 'abc' as a substring" ( contains: "string" or contains: "different" or contains: "random" ) Matchers.tests.cpp:: passed: testStringForMatching2(), ContainsSubstring( "string" ) || ContainsSubstring( "different" ) || ContainsSubstring( "random" ) for: "some completely different text that contains one common word" ( contains: "string" or contains: "different" or contains: "random" ) @@ -1930,6 +1944,14 @@ Tag.tests.cpp:: passed: registry.add( "@no square bracket at start] Tag.tests.cpp:: passed: registry.add( "[@no square bracket at end", "", Catch::SourceLineInfo( "file", 3 ) ) Tag.tests.cpp:: passed: testCase.tags.size() == 2 for: 2 == 2 Tag.tests.cpp:: passed: testCase.tags, VectorContains( Tag( "tag with spaces" ) ) && VectorContains( Tag( "I said \"good day\" sir!"_catch_sr ) ) for: { {?}, {?} } ( Contains: {?} and Contains: {?} ) +GeneratorsImpl.tests.cpp:: passed: take.get() == 0 for: 0 == 0 +GeneratorsImpl.tests.cpp:: passed: take.get() == 2 for: 2 == 2 +GeneratorsImpl.tests.cpp:: passed: take.get() == 5 for: 5 == 5 +GeneratorsImpl.tests.cpp:: passed: take.skipToNthElement( 6 ) +GeneratorsImpl.tests.cpp:: passed: take.get() == 0 for: 0 == 0 +GeneratorsImpl.tests.cpp:: passed: take.get() == 2 for: 2 == 2 +GeneratorsImpl.tests.cpp:: passed: take.get() == 5 for: 5 == 5 +GeneratorsImpl.tests.cpp:: passed: take.skipToNthElement( 6 ) Class.tests.cpp:: passed: Template_Fixture::m_a == 1 for: 1 == 1 Class.tests.cpp:: passed: Template_Fixture::m_a == 1 for: 1 == 1 Class.tests.cpp:: passed: Template_Fixture::m_a == 1 for: 1.0 == 1 @@ -2924,7 +2946,7 @@ InternalBenchmark.tests.cpp:: passed: med == 18. for: 18.0 == 18.0 InternalBenchmark.tests.cpp:: passed: q3 == 23. for: 23.0 == 23.0 Misc.tests.cpp:: passed: Misc.tests.cpp:: passed: -test cases: 440 | 320 passed | 96 failed | 6 skipped | 18 failed as expected -assertions: 2340 | 2139 passed | 158 failed | 43 failed as expected +test cases: 443 | 323 passed | 96 failed | 6 skipped | 18 failed as expected +assertions: 2362 | 2161 passed | 158 failed | 43 failed as expected diff --git a/tests/SelfTest/Baselines/compact.sw.multi.approved.txt b/tests/SelfTest/Baselines/compact.sw.multi.approved.txt index 17cf066a..e44e771d 100644 --- a/tests/SelfTest/Baselines/compact.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/compact.sw.multi.approved.txt @@ -676,6 +676,12 @@ Misc.tests.cpp:: passed: Factorial(2) == 2 for: 2 == 2 Misc.tests.cpp:: passed: Factorial(3) == 6 for: 6 == 6 Misc.tests.cpp:: passed: Factorial(10) == 3628800 for: 3628800 (0x) == 3628800 (0x) GeneratorsImpl.tests.cpp:: passed: filter( []( int ) { return false; }, value( 3 ) ), Catch::GeneratorException +GeneratorsImpl.tests.cpp:: passed: values.currentElementIndex() == 0 for: 0 == 0 +GeneratorsImpl.tests.cpp:: passed: values.currentElementIndex() == 3 for: 3 == 3 +GeneratorsImpl.tests.cpp:: passed: values.get() == 3 for: 3 == 3 +GeneratorsImpl.tests.cpp:: passed: values.currentElementIndex() == 4 for: 4 == 4 +GeneratorsImpl.tests.cpp:: passed: values.get() == 4 for: 4 == 4 +GeneratorsImpl.tests.cpp:: passed: values.skipToNthElement( 5 ) Matchers.tests.cpp:: passed: 10., WithinRel( 11.1, 0.1 ) for: 10.0 and 11.09999999999999964 are within 10% of each other Matchers.tests.cpp:: passed: 10., !WithinRel( 11.2, 0.1 ) for: 10.0 not and 11.19999999999999929 are within 10% of each other Matchers.tests.cpp:: passed: 1., !WithinRel( 0., 0.99 ) for: 1.0 not and 0.0 are within 99% of each other @@ -1241,6 +1247,14 @@ Approx.tests.cpp:: passed: d <= Approx( 1.22 ).epsilon(0.1) for: 1. <= Approx( 1.21999999999999997 ) Misc.tests.cpp:: passed: with 1 message: 'was called' +GeneratorsImpl.tests.cpp:: passed: map_generator.get() == 4 for: 4 == 4 +GeneratorsImpl.tests.cpp:: passed: map_calls == map_calls_1 + 1 for: 2 == 2 +GeneratorsImpl.tests.cpp:: passed: map_generator.get() == 4 for: 4 == 4 +GeneratorsImpl.tests.cpp:: passed: map_calls == map_calls_1 + 1 for: 2 == 2 +GeneratorsImpl.tests.cpp:: passed: map_generator.get() == 6 for: 6 == 6 +GeneratorsImpl.tests.cpp:: passed: map_calls == map_calls_2 + 1 for: 3 == 3 +GeneratorsImpl.tests.cpp:: passed: map_generator.skipToNthElement( 7 ) +GeneratorsImpl.tests.cpp:: passed: map_calls == map_calls_2 + 1 for: 3 == 3 Matchers.tests.cpp:: passed: testStringForMatching(), ContainsSubstring( "string" ) && ContainsSubstring( "abc" ) && ContainsSubstring( "substring" ) && ContainsSubstring( "contains" ) for: "this string contains 'abc' as a substring" ( contains: "string" and contains: "abc" and contains: "substring" and contains: "contains" ) Matchers.tests.cpp:: passed: testStringForMatching(), ContainsSubstring( "string" ) || ContainsSubstring( "different" ) || ContainsSubstring( "random" ) for: "this string contains 'abc' as a substring" ( contains: "string" or contains: "different" or contains: "random" ) Matchers.tests.cpp:: passed: testStringForMatching2(), ContainsSubstring( "string" ) || ContainsSubstring( "different" ) || ContainsSubstring( "random" ) for: "some completely different text that contains one common word" ( contains: "string" or contains: "different" or contains: "random" ) @@ -1923,6 +1937,14 @@ Tag.tests.cpp:: passed: registry.add( "@no square bracket at start] Tag.tests.cpp:: passed: registry.add( "[@no square bracket at end", "", Catch::SourceLineInfo( "file", 3 ) ) Tag.tests.cpp:: passed: testCase.tags.size() == 2 for: 2 == 2 Tag.tests.cpp:: passed: testCase.tags, VectorContains( Tag( "tag with spaces" ) ) && VectorContains( Tag( "I said \"good day\" sir!"_catch_sr ) ) for: { {?}, {?} } ( Contains: {?} and Contains: {?} ) +GeneratorsImpl.tests.cpp:: passed: take.get() == 0 for: 0 == 0 +GeneratorsImpl.tests.cpp:: passed: take.get() == 2 for: 2 == 2 +GeneratorsImpl.tests.cpp:: passed: take.get() == 5 for: 5 == 5 +GeneratorsImpl.tests.cpp:: passed: take.skipToNthElement( 6 ) +GeneratorsImpl.tests.cpp:: passed: take.get() == 0 for: 0 == 0 +GeneratorsImpl.tests.cpp:: passed: take.get() == 2 for: 2 == 2 +GeneratorsImpl.tests.cpp:: passed: take.get() == 5 for: 5 == 5 +GeneratorsImpl.tests.cpp:: passed: take.skipToNthElement( 6 ) Class.tests.cpp:: passed: Template_Fixture::m_a == 1 for: 1 == 1 Class.tests.cpp:: passed: Template_Fixture::m_a == 1 for: 1 == 1 Class.tests.cpp:: passed: Template_Fixture::m_a == 1 for: 1.0 == 1 @@ -2913,7 +2935,7 @@ InternalBenchmark.tests.cpp:: passed: med == 18. for: 18.0 == 18.0 InternalBenchmark.tests.cpp:: passed: q3 == 23. for: 23.0 == 23.0 Misc.tests.cpp:: passed: Misc.tests.cpp:: passed: -test cases: 440 | 320 passed | 96 failed | 6 skipped | 18 failed as expected -assertions: 2340 | 2139 passed | 158 failed | 43 failed as expected +test cases: 443 | 323 passed | 96 failed | 6 skipped | 18 failed as expected +assertions: 2362 | 2161 passed | 158 failed | 43 failed as expected diff --git a/tests/SelfTest/Baselines/console.std.approved.txt b/tests/SelfTest/Baselines/console.std.approved.txt index 02d7a3cb..4529fef8 100644 --- a/tests/SelfTest/Baselines/console.std.approved.txt +++ b/tests/SelfTest/Baselines/console.std.approved.txt @@ -1743,6 +1743,6 @@ due to unexpected exception with message: Why would you throw a std::string? =============================================================================== -test cases: 440 | 338 passed | 76 failed | 7 skipped | 19 failed as expected -assertions: 2318 | 2139 passed | 136 failed | 43 failed as expected +test cases: 443 | 341 passed | 76 failed | 7 skipped | 19 failed as expected +assertions: 2340 | 2161 passed | 136 failed | 43 failed as expected diff --git a/tests/SelfTest/Baselines/console.sw.approved.txt b/tests/SelfTest/Baselines/console.sw.approved.txt index 38578deb..48a4c85f 100644 --- a/tests/SelfTest/Baselines/console.sw.approved.txt +++ b/tests/SelfTest/Baselines/console.sw.approved.txt @@ -4832,6 +4832,40 @@ GeneratorsImpl.tests.cpp: GeneratorsImpl.tests.cpp:: PASSED: REQUIRE_THROWS_AS( filter( []( int ) { return false; }, value( 3 ) ), Catch::GeneratorException ) +------------------------------------------------------------------------------- +FixedValuesGenerator can be skipped forward +------------------------------------------------------------------------------- +GeneratorsImpl.tests.cpp: +............................................................................... + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( values.currentElementIndex() == 0 ) +with expansion: + 0 == 0 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( values.currentElementIndex() == 3 ) +with expansion: + 3 == 3 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( values.get() == 3 ) +with expansion: + 3 == 3 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( values.currentElementIndex() == 4 ) +with expansion: + 4 == 4 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( values.get() == 4 ) +with expansion: + 4 == 4 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE_THROWS( values.skipToNthElement( 5 ) ) + ------------------------------------------------------------------------------- Floating point matchers: double Relative @@ -8134,6 +8168,50 @@ Misc.tests.cpp:: PASSED: with message: was called +------------------------------------------------------------------------------- +MapGenerator can be skipped forward efficiently +------------------------------------------------------------------------------- +GeneratorsImpl.tests.cpp: +............................................................................... + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( map_generator.get() == 4 ) +with expansion: + 4 == 4 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( map_calls == map_calls_1 + 1 ) +with expansion: + 2 == 2 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( map_generator.get() == 4 ) +with expansion: + 4 == 4 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( map_calls == map_calls_1 + 1 ) +with expansion: + 2 == 2 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( map_generator.get() == 6 ) +with expansion: + 6 == 6 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( map_calls == map_calls_2 + 1 ) +with expansion: + 3 == 3 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE_THROWS( map_generator.skipToNthElement( 7 ) ) + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( map_calls == map_calls_2 + 1 ) +with expansion: + 3 == 3 + ------------------------------------------------------------------------------- Matchers can be (AllOf) composed with the && operator ------------------------------------------------------------------------------- @@ -12237,6 +12315,56 @@ Tag.tests.cpp:: PASSED: with expansion: { {?}, {?} } ( Contains: {?} and Contains: {?} ) +------------------------------------------------------------------------------- +TakeGenerator can be skipped forward + take is shorter than underlying +------------------------------------------------------------------------------- +GeneratorsImpl.tests.cpp: +............................................................................... + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( take.get() == 0 ) +with expansion: + 0 == 0 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( take.get() == 2 ) +with expansion: + 2 == 2 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( take.get() == 5 ) +with expansion: + 5 == 5 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE_THROWS( take.skipToNthElement( 6 ) ) + +------------------------------------------------------------------------------- +TakeGenerator can be skipped forward + take is longer than underlying +------------------------------------------------------------------------------- +GeneratorsImpl.tests.cpp: +............................................................................... + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( take.get() == 0 ) +with expansion: + 0 == 0 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( take.get() == 2 ) +with expansion: + 2 == 2 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( take.get() == 5 ) +with expansion: + 5 == 5 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE_THROWS( take.skipToNthElement( 6 ) ) + ------------------------------------------------------------------------------- Template test case method with test types specified inside std::tuple - MyTypes - 0 @@ -19589,6 +19717,6 @@ Misc.tests.cpp: Misc.tests.cpp:: PASSED: =============================================================================== -test cases: 440 | 320 passed | 96 failed | 6 skipped | 18 failed as expected -assertions: 2340 | 2139 passed | 158 failed | 43 failed as expected +test cases: 443 | 323 passed | 96 failed | 6 skipped | 18 failed as expected +assertions: 2362 | 2161 passed | 158 failed | 43 failed as expected diff --git a/tests/SelfTest/Baselines/console.sw.multi.approved.txt b/tests/SelfTest/Baselines/console.sw.multi.approved.txt index 207697cf..7845ed07 100644 --- a/tests/SelfTest/Baselines/console.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/console.sw.multi.approved.txt @@ -4830,6 +4830,40 @@ GeneratorsImpl.tests.cpp: GeneratorsImpl.tests.cpp:: PASSED: REQUIRE_THROWS_AS( filter( []( int ) { return false; }, value( 3 ) ), Catch::GeneratorException ) +------------------------------------------------------------------------------- +FixedValuesGenerator can be skipped forward +------------------------------------------------------------------------------- +GeneratorsImpl.tests.cpp: +............................................................................... + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( values.currentElementIndex() == 0 ) +with expansion: + 0 == 0 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( values.currentElementIndex() == 3 ) +with expansion: + 3 == 3 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( values.get() == 3 ) +with expansion: + 3 == 3 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( values.currentElementIndex() == 4 ) +with expansion: + 4 == 4 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( values.get() == 4 ) +with expansion: + 4 == 4 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE_THROWS( values.skipToNthElement( 5 ) ) + ------------------------------------------------------------------------------- Floating point matchers: double Relative @@ -8132,6 +8166,50 @@ Misc.tests.cpp:: PASSED: with message: was called +------------------------------------------------------------------------------- +MapGenerator can be skipped forward efficiently +------------------------------------------------------------------------------- +GeneratorsImpl.tests.cpp: +............................................................................... + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( map_generator.get() == 4 ) +with expansion: + 4 == 4 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( map_calls == map_calls_1 + 1 ) +with expansion: + 2 == 2 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( map_generator.get() == 4 ) +with expansion: + 4 == 4 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( map_calls == map_calls_1 + 1 ) +with expansion: + 2 == 2 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( map_generator.get() == 6 ) +with expansion: + 6 == 6 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( map_calls == map_calls_2 + 1 ) +with expansion: + 3 == 3 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE_THROWS( map_generator.skipToNthElement( 7 ) ) + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( map_calls == map_calls_2 + 1 ) +with expansion: + 3 == 3 + ------------------------------------------------------------------------------- Matchers can be (AllOf) composed with the && operator ------------------------------------------------------------------------------- @@ -12230,6 +12308,56 @@ Tag.tests.cpp:: PASSED: with expansion: { {?}, {?} } ( Contains: {?} and Contains: {?} ) +------------------------------------------------------------------------------- +TakeGenerator can be skipped forward + take is shorter than underlying +------------------------------------------------------------------------------- +GeneratorsImpl.tests.cpp: +............................................................................... + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( take.get() == 0 ) +with expansion: + 0 == 0 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( take.get() == 2 ) +with expansion: + 2 == 2 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( take.get() == 5 ) +with expansion: + 5 == 5 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE_THROWS( take.skipToNthElement( 6 ) ) + +------------------------------------------------------------------------------- +TakeGenerator can be skipped forward + take is longer than underlying +------------------------------------------------------------------------------- +GeneratorsImpl.tests.cpp: +............................................................................... + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( take.get() == 0 ) +with expansion: + 0 == 0 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( take.get() == 2 ) +with expansion: + 2 == 2 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( take.get() == 5 ) +with expansion: + 5 == 5 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE_THROWS( take.skipToNthElement( 6 ) ) + ------------------------------------------------------------------------------- Template test case method with test types specified inside std::tuple - MyTypes - 0 @@ -19578,6 +19706,6 @@ Misc.tests.cpp: Misc.tests.cpp:: PASSED: =============================================================================== -test cases: 440 | 320 passed | 96 failed | 6 skipped | 18 failed as expected -assertions: 2340 | 2139 passed | 158 failed | 43 failed as expected +test cases: 443 | 323 passed | 96 failed | 6 skipped | 18 failed as expected +assertions: 2362 | 2161 passed | 158 failed | 43 failed as expected diff --git a/tests/SelfTest/Baselines/junit.sw.approved.txt b/tests/SelfTest/Baselines/junit.sw.approved.txt index beaf9cf8..9f13c847 100644 --- a/tests/SelfTest/Baselines/junit.sw.approved.txt +++ b/tests/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + @@ -814,6 +814,7 @@ at Message.tests.cpp: + @@ -1023,6 +1024,7 @@ at Condition.tests.cpp: + @@ -1555,6 +1557,9 @@ at Misc.tests.cpp: + + + diff --git a/tests/SelfTest/Baselines/junit.sw.multi.approved.txt b/tests/SelfTest/Baselines/junit.sw.multi.approved.txt index a69a4979..ec33f1ba 100644 --- a/tests/SelfTest/Baselines/junit.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/junit.sw.multi.approved.txt @@ -1,6 +1,6 @@ - + @@ -813,6 +813,7 @@ at Message.tests.cpp: + @@ -1022,6 +1023,7 @@ at Condition.tests.cpp: + @@ -1554,6 +1556,9 @@ at Misc.tests.cpp: + + + diff --git a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt index 60ce76cd..1d36a1ff 100644 --- a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt +++ b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt @@ -149,6 +149,7 @@ at AssertionHandler.tests.cpp: + @@ -187,6 +188,10 @@ at AssertionHandler.tests.cpp: + + + + diff --git a/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt index 6811d003..9de7e03f 100644 --- a/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt @@ -148,6 +148,7 @@ at AssertionHandler.tests.cpp: + @@ -186,6 +187,10 @@ at AssertionHandler.tests.cpp: + + + + diff --git a/tests/SelfTest/Baselines/tap.sw.approved.txt b/tests/SelfTest/Baselines/tap.sw.approved.txt index 6d45b413..5261a4ac 100644 --- a/tests/SelfTest/Baselines/tap.sw.approved.txt +++ b/tests/SelfTest/Baselines/tap.sw.approved.txt @@ -1212,6 +1212,18 @@ ok {test-number} - Factorial(3) == 6 for: 6 == 6 ok {test-number} - Factorial(10) == 3628800 for: 3628800 (0x) == 3628800 (0x) # Filter generator throws exception for empty generator ok {test-number} - filter( []( int ) { return false; }, value( 3 ) ), Catch::GeneratorException +# FixedValuesGenerator can be skipped forward +ok {test-number} - values.currentElementIndex() == 0 for: 0 == 0 +# FixedValuesGenerator can be skipped forward +ok {test-number} - values.currentElementIndex() == 3 for: 3 == 3 +# FixedValuesGenerator can be skipped forward +ok {test-number} - values.get() == 3 for: 3 == 3 +# FixedValuesGenerator can be skipped forward +ok {test-number} - values.currentElementIndex() == 4 for: 4 == 4 +# FixedValuesGenerator can be skipped forward +ok {test-number} - values.get() == 4 for: 4 == 4 +# FixedValuesGenerator can be skipped forward +ok {test-number} - values.skipToNthElement( 5 ) # Floating point matchers: double ok {test-number} - 10., WithinRel( 11.1, 0.1 ) for: 10.0 and 11.09999999999999964 are within 10% of each other # Floating point matchers: double @@ -2028,6 +2040,22 @@ ok {test-number} - !(d <= Approx( 1.22 )) for: !(1.22999999999999998 <= Approx( ok {test-number} - d <= Approx( 1.22 ).epsilon(0.1) for: 1.22999999999999998 <= Approx( 1.21999999999999997 ) # ManuallyRegistered ok {test-number} - with 1 message: 'was called' +# MapGenerator can be skipped forward efficiently +ok {test-number} - map_generator.get() == 4 for: 4 == 4 +# MapGenerator can be skipped forward efficiently +ok {test-number} - map_calls == map_calls_1 + 1 for: 2 == 2 +# MapGenerator can be skipped forward efficiently +ok {test-number} - map_generator.get() == 4 for: 4 == 4 +# MapGenerator can be skipped forward efficiently +ok {test-number} - map_calls == map_calls_1 + 1 for: 2 == 2 +# MapGenerator can be skipped forward efficiently +ok {test-number} - map_generator.get() == 6 for: 6 == 6 +# MapGenerator can be skipped forward efficiently +ok {test-number} - map_calls == map_calls_2 + 1 for: 3 == 3 +# MapGenerator can be skipped forward efficiently +ok {test-number} - map_generator.skipToNthElement( 7 ) +# MapGenerator can be skipped forward efficiently +ok {test-number} - map_calls == map_calls_2 + 1 for: 3 == 3 # Matchers can be (AllOf) composed with the && operator ok {test-number} - testStringForMatching(), ContainsSubstring( "string" ) && ContainsSubstring( "abc" ) && ContainsSubstring( "substring" ) && ContainsSubstring( "contains" ) for: "this string contains 'abc' as a substring" ( contains: "string" and contains: "abc" and contains: "substring" and contains: "contains" ) # Matchers can be (AnyOf) composed with the || operator @@ -2929,6 +2957,22 @@ ok {test-number} - registry.add( "[@no square bracket at end", "", Catch::Source ok {test-number} - testCase.tags.size() == 2 for: 2 == 2 # Tags with spaces and non-alphanumerical characters are accepted ok {test-number} - testCase.tags, VectorContains( Tag( "tag with spaces" ) ) && VectorContains( Tag( "I said \"good day\" sir!"_catch_sr ) ) for: { {?}, {?} } ( Contains: {?} and Contains: {?} ) +# TakeGenerator can be skipped forward +ok {test-number} - take.get() == 0 for: 0 == 0 +# TakeGenerator can be skipped forward +ok {test-number} - take.get() == 2 for: 2 == 2 +# TakeGenerator can be skipped forward +ok {test-number} - take.get() == 5 for: 5 == 5 +# TakeGenerator can be skipped forward +ok {test-number} - take.skipToNthElement( 6 ) +# TakeGenerator can be skipped forward +ok {test-number} - take.get() == 0 for: 0 == 0 +# TakeGenerator can be skipped forward +ok {test-number} - take.get() == 2 for: 2 == 2 +# TakeGenerator can be skipped forward +ok {test-number} - take.get() == 5 for: 5 == 5 +# TakeGenerator can be skipped forward +ok {test-number} - take.skipToNthElement( 6 ) # Template test case method with test types specified inside std::tuple - MyTypes - 0 ok {test-number} - Template_Fixture::m_a == 1 for: 1 == 1 # Template test case method with test types specified inside std::tuple - MyTypes - 1 @@ -4699,5 +4743,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0 ok {test-number} - # xmlentitycheck ok {test-number} - -1..2352 +1..2374 diff --git a/tests/SelfTest/Baselines/tap.sw.multi.approved.txt b/tests/SelfTest/Baselines/tap.sw.multi.approved.txt index 215243ac..eeafbc01 100644 --- a/tests/SelfTest/Baselines/tap.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/tap.sw.multi.approved.txt @@ -1210,6 +1210,18 @@ ok {test-number} - Factorial(3) == 6 for: 6 == 6 ok {test-number} - Factorial(10) == 3628800 for: 3628800 (0x) == 3628800 (0x) # Filter generator throws exception for empty generator ok {test-number} - filter( []( int ) { return false; }, value( 3 ) ), Catch::GeneratorException +# FixedValuesGenerator can be skipped forward +ok {test-number} - values.currentElementIndex() == 0 for: 0 == 0 +# FixedValuesGenerator can be skipped forward +ok {test-number} - values.currentElementIndex() == 3 for: 3 == 3 +# FixedValuesGenerator can be skipped forward +ok {test-number} - values.get() == 3 for: 3 == 3 +# FixedValuesGenerator can be skipped forward +ok {test-number} - values.currentElementIndex() == 4 for: 4 == 4 +# FixedValuesGenerator can be skipped forward +ok {test-number} - values.get() == 4 for: 4 == 4 +# FixedValuesGenerator can be skipped forward +ok {test-number} - values.skipToNthElement( 5 ) # Floating point matchers: double ok {test-number} - 10., WithinRel( 11.1, 0.1 ) for: 10.0 and 11.09999999999999964 are within 10% of each other # Floating point matchers: double @@ -2026,6 +2038,22 @@ ok {test-number} - !(d <= Approx( 1.22 )) for: !(1.22999999999999998 <= Approx( ok {test-number} - d <= Approx( 1.22 ).epsilon(0.1) for: 1.22999999999999998 <= Approx( 1.21999999999999997 ) # ManuallyRegistered ok {test-number} - with 1 message: 'was called' +# MapGenerator can be skipped forward efficiently +ok {test-number} - map_generator.get() == 4 for: 4 == 4 +# MapGenerator can be skipped forward efficiently +ok {test-number} - map_calls == map_calls_1 + 1 for: 2 == 2 +# MapGenerator can be skipped forward efficiently +ok {test-number} - map_generator.get() == 4 for: 4 == 4 +# MapGenerator can be skipped forward efficiently +ok {test-number} - map_calls == map_calls_1 + 1 for: 2 == 2 +# MapGenerator can be skipped forward efficiently +ok {test-number} - map_generator.get() == 6 for: 6 == 6 +# MapGenerator can be skipped forward efficiently +ok {test-number} - map_calls == map_calls_2 + 1 for: 3 == 3 +# MapGenerator can be skipped forward efficiently +ok {test-number} - map_generator.skipToNthElement( 7 ) +# MapGenerator can be skipped forward efficiently +ok {test-number} - map_calls == map_calls_2 + 1 for: 3 == 3 # Matchers can be (AllOf) composed with the && operator ok {test-number} - testStringForMatching(), ContainsSubstring( "string" ) && ContainsSubstring( "abc" ) && ContainsSubstring( "substring" ) && ContainsSubstring( "contains" ) for: "this string contains 'abc' as a substring" ( contains: "string" and contains: "abc" and contains: "substring" and contains: "contains" ) # Matchers can be (AnyOf) composed with the || operator @@ -2922,6 +2950,22 @@ ok {test-number} - registry.add( "[@no square bracket at end", "", Catch::Source ok {test-number} - testCase.tags.size() == 2 for: 2 == 2 # Tags with spaces and non-alphanumerical characters are accepted ok {test-number} - testCase.tags, VectorContains( Tag( "tag with spaces" ) ) && VectorContains( Tag( "I said \"good day\" sir!"_catch_sr ) ) for: { {?}, {?} } ( Contains: {?} and Contains: {?} ) +# TakeGenerator can be skipped forward +ok {test-number} - take.get() == 0 for: 0 == 0 +# TakeGenerator can be skipped forward +ok {test-number} - take.get() == 2 for: 2 == 2 +# TakeGenerator can be skipped forward +ok {test-number} - take.get() == 5 for: 5 == 5 +# TakeGenerator can be skipped forward +ok {test-number} - take.skipToNthElement( 6 ) +# TakeGenerator can be skipped forward +ok {test-number} - take.get() == 0 for: 0 == 0 +# TakeGenerator can be skipped forward +ok {test-number} - take.get() == 2 for: 2 == 2 +# TakeGenerator can be skipped forward +ok {test-number} - take.get() == 5 for: 5 == 5 +# TakeGenerator can be skipped forward +ok {test-number} - take.skipToNthElement( 6 ) # Template test case method with test types specified inside std::tuple - MyTypes - 0 ok {test-number} - Template_Fixture::m_a == 1 for: 1 == 1 # Template test case method with test types specified inside std::tuple - MyTypes - 1 @@ -4688,5 +4732,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0 ok {test-number} - # xmlentitycheck ok {test-number} - -1..2352 +1..2374 diff --git a/tests/SelfTest/Baselines/teamcity.sw.approved.txt b/tests/SelfTest/Baselines/teamcity.sw.approved.txt index d460f1ff..b7be8d11 100644 --- a/tests/SelfTest/Baselines/teamcity.sw.approved.txt +++ b/tests/SelfTest/Baselines/teamcity.sw.approved.txt @@ -409,6 +409,8 @@ ##teamcity[testFinished name='Factorials are computed' duration="{duration}"] ##teamcity[testStarted name='Filter generator throws exception for empty generator'] ##teamcity[testFinished name='Filter generator throws exception for empty generator' duration="{duration}"] +##teamcity[testStarted name='FixedValuesGenerator can be skipped forward'] +##teamcity[testFinished name='FixedValuesGenerator can be skipped forward' duration="{duration}"] ##teamcity[testStarted name='Floating point matchers: double'] ##teamcity[testFinished name='Floating point matchers: double' duration="{duration}"] ##teamcity[testStarted name='Floating point matchers: float'] @@ -470,6 +472,8 @@ ##teamcity[testFinished name='Less-than inequalities with different epsilons' duration="{duration}"] ##teamcity[testStarted name='ManuallyRegistered'] ##teamcity[testFinished name='ManuallyRegistered' duration="{duration}"] +##teamcity[testStarted name='MapGenerator can be skipped forward efficiently'] +##teamcity[testFinished name='MapGenerator can be skipped forward efficiently' duration="{duration}"] ##teamcity[testStarted name='Matchers can be (AllOf) composed with the && operator'] ##teamcity[testFinished name='Matchers can be (AllOf) composed with the && operator' duration="{duration}"] ##teamcity[testStarted name='Matchers can be (AnyOf) composed with the |||| operator'] @@ -647,6 +651,8 @@ ##teamcity[testFinished name='Tag alias can be registered against tag patterns' duration="{duration}"] ##teamcity[testStarted name='Tags with spaces and non-alphanumerical characters are accepted'] ##teamcity[testFinished name='Tags with spaces and non-alphanumerical characters are accepted' duration="{duration}"] +##teamcity[testStarted name='TakeGenerator can be skipped forward'] +##teamcity[testFinished name='TakeGenerator can be skipped forward' duration="{duration}"] ##teamcity[testStarted name='Template test case method with test types specified inside std::tuple - MyTypes - 0'] ##teamcity[testFinished name='Template test case method with test types specified inside std::tuple - MyTypes - 0' duration="{duration}"] ##teamcity[testStarted name='Template test case method with test types specified inside std::tuple - MyTypes - 1'] diff --git a/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt b/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt index 5eee54e5..feb5f1d9 100644 --- a/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt @@ -409,6 +409,8 @@ ##teamcity[testFinished name='Factorials are computed' duration="{duration}"] ##teamcity[testStarted name='Filter generator throws exception for empty generator'] ##teamcity[testFinished name='Filter generator throws exception for empty generator' duration="{duration}"] +##teamcity[testStarted name='FixedValuesGenerator can be skipped forward'] +##teamcity[testFinished name='FixedValuesGenerator can be skipped forward' duration="{duration}"] ##teamcity[testStarted name='Floating point matchers: double'] ##teamcity[testFinished name='Floating point matchers: double' duration="{duration}"] ##teamcity[testStarted name='Floating point matchers: float'] @@ -470,6 +472,8 @@ ##teamcity[testFinished name='Less-than inequalities with different epsilons' duration="{duration}"] ##teamcity[testStarted name='ManuallyRegistered'] ##teamcity[testFinished name='ManuallyRegistered' duration="{duration}"] +##teamcity[testStarted name='MapGenerator can be skipped forward efficiently'] +##teamcity[testFinished name='MapGenerator can be skipped forward efficiently' duration="{duration}"] ##teamcity[testStarted name='Matchers can be (AllOf) composed with the && operator'] ##teamcity[testFinished name='Matchers can be (AllOf) composed with the && operator' duration="{duration}"] ##teamcity[testStarted name='Matchers can be (AnyOf) composed with the |||| operator'] @@ -647,6 +651,8 @@ ##teamcity[testFinished name='Tag alias can be registered against tag patterns' duration="{duration}"] ##teamcity[testStarted name='Tags with spaces and non-alphanumerical characters are accepted'] ##teamcity[testFinished name='Tags with spaces and non-alphanumerical characters are accepted' duration="{duration}"] +##teamcity[testStarted name='TakeGenerator can be skipped forward'] +##teamcity[testFinished name='TakeGenerator can be skipped forward' duration="{duration}"] ##teamcity[testStarted name='Template test case method with test types specified inside std::tuple - MyTypes - 0'] ##teamcity[testFinished name='Template test case method with test types specified inside std::tuple - MyTypes - 0' duration="{duration}"] ##teamcity[testStarted name='Template test case method with test types specified inside std::tuple - MyTypes - 1'] diff --git a/tests/SelfTest/Baselines/xml.sw.approved.txt b/tests/SelfTest/Baselines/xml.sw.approved.txt index 08900bfa..77a45a54 100644 --- a/tests/SelfTest/Baselines/xml.sw.approved.txt +++ b/tests/SelfTest/Baselines/xml.sw.approved.txt @@ -5481,6 +5481,57 @@ Approx( 1.30000000000000004 ) + + + + values.currentElementIndex() == 0 + + + 0 == 0 + + + + + values.currentElementIndex() == 3 + + + 3 == 3 + + + + + values.get() == 3 + + + 3 == 3 + + + + + values.currentElementIndex() == 4 + + + 4 == 4 + + + + + values.get() == 4 + + + 4 == 4 + + + + + values.skipToNthElement( 5 ) + + + values.skipToNthElement( 5 ) + + + +
@@ -9775,6 +9826,73 @@ Approx( 1.21999999999999997 ) + + + + map_generator.get() == 4 + + + 4 == 4 + + + + + map_calls == map_calls_1 + 1 + + + 2 == 2 + + + + + map_generator.get() == 4 + + + 4 == 4 + + + + + map_calls == map_calls_1 + 1 + + + 2 == 2 + + + + + map_generator.get() == 6 + + + 6 == 6 + + + + + map_calls == map_calls_2 + 1 + + + 3 == 3 + + + + + map_generator.skipToNthElement( 7 ) + + + map_generator.skipToNthElement( 7 ) + + + + + map_calls == map_calls_2 + 1 + + + 3 == 3 + + + + @@ -14326,6 +14444,79 @@ Message from section two + +
+ + + take.get() == 0 + + + 0 == 0 + + + + + take.get() == 2 + + + 2 == 2 + + + + + take.get() == 5 + + + 5 == 5 + + + + + take.skipToNthElement( 6 ) + + + take.skipToNthElement( 6 ) + + + +
+
+ + + take.get() == 0 + + + 0 == 0 + + + + + take.get() == 2 + + + 2 == 2 + + + + + take.get() == 5 + + + 5 == 5 + + + + + take.skipToNthElement( 6 ) + + + take.skipToNthElement( 6 ) + + + +
+ +
@@ -22687,6 +22878,6 @@ Approx( -1.95996398454005449 )
- - + + diff --git a/tests/SelfTest/Baselines/xml.sw.multi.approved.txt b/tests/SelfTest/Baselines/xml.sw.multi.approved.txt index c51ae00a..dbb3996f 100644 --- a/tests/SelfTest/Baselines/xml.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/xml.sw.multi.approved.txt @@ -5481,6 +5481,57 @@ Approx( 1.30000000000000004 )
+ + + + values.currentElementIndex() == 0 + + + 0 == 0 + + + + + values.currentElementIndex() == 3 + + + 3 == 3 + + + + + values.get() == 3 + + + 3 == 3 + + + + + values.currentElementIndex() == 4 + + + 4 == 4 + + + + + values.get() == 4 + + + 4 == 4 + + + + + values.skipToNthElement( 5 ) + + + values.skipToNthElement( 5 ) + + + +
@@ -9775,6 +9826,73 @@ Approx( 1.21999999999999997 ) + + + + map_generator.get() == 4 + + + 4 == 4 + + + + + map_calls == map_calls_1 + 1 + + + 2 == 2 + + + + + map_generator.get() == 4 + + + 4 == 4 + + + + + map_calls == map_calls_1 + 1 + + + 2 == 2 + + + + + map_generator.get() == 6 + + + 6 == 6 + + + + + map_calls == map_calls_2 + 1 + + + 3 == 3 + + + + + map_generator.skipToNthElement( 7 ) + + + map_generator.skipToNthElement( 7 ) + + + + + map_calls == map_calls_2 + 1 + + + 3 == 3 + + + + @@ -14326,6 +14444,79 @@ Message from section two + +
+ + + take.get() == 0 + + + 0 == 0 + + + + + take.get() == 2 + + + 2 == 2 + + + + + take.get() == 5 + + + 5 == 5 + + + + + take.skipToNthElement( 6 ) + + + take.skipToNthElement( 6 ) + + + +
+
+ + + take.get() == 0 + + + 0 == 0 + + + + + take.get() == 2 + + + 2 == 2 + + + + + take.get() == 5 + + + 5 == 5 + + + + + take.skipToNthElement( 6 ) + + + take.skipToNthElement( 6 ) + + + +
+ +
@@ -22686,6 +22877,6 @@ Approx( -1.95996398454005449 )
- - + + diff --git a/tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp b/tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp index 0a2b17ea..6c81b160 100644 --- a/tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp +++ b/tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp @@ -643,3 +643,81 @@ TEST_CASE( "Generators can be skipped forward", "[generators]" ) { // Past the end REQUIRE_THROWS( generator.skipToNthElement( 6 ) ); } + +TEST_CASE( "FixedValuesGenerator can be skipped forward", + "[generators][values]" ) { + Catch::Generators::FixedValuesGenerator values( {0, 1, 2, 3, 4} ); + REQUIRE( values.currentElementIndex() == 0 ); + + values.skipToNthElement( 3 ); + REQUIRE( values.currentElementIndex() == 3 ); + REQUIRE( values.get() == 3 ); + + values.skipToNthElement( 4 ); + REQUIRE( values.currentElementIndex() == 4 ); + REQUIRE( values.get() == 4 ); + + // Past the end + REQUIRE_THROWS( values.skipToNthElement( 5 ) ); +} + +TEST_CASE( "TakeGenerator can be skipped forward", "[generators][take]" ) { + SECTION("take is shorter than underlying") { + Catch::Generators::TakeGenerator take( + 6, Catch::Generators::values( { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } ) ); + REQUIRE( take.get() == 0 ); + + take.skipToNthElement( 2 ); + REQUIRE( take.get() == 2 ); + + take.skipToNthElement( 5 ); + REQUIRE( take.get() == 5 ); + + // This is in the original values, but past the end of the take + REQUIRE_THROWS( take.skipToNthElement( 6 ) ); + } + SECTION( "take is longer than underlying" ) { + Catch::Generators::TakeGenerator take( + 8, Catch::Generators::values( { 0, 1, 2, 3, 4, 5 } ) ); + REQUIRE( take.get() == 0 ); + + take.skipToNthElement( 2 ); + REQUIRE( take.get() == 2 ); + + take.skipToNthElement( 5 ); + REQUIRE( take.get() == 5 ); + + // This is in the take, but outside of original values + REQUIRE_THROWS( take.skipToNthElement( 6 ) ); + } +} + +TEST_CASE("MapGenerator can be skipped forward efficiently", + "[generators][map]") { + using namespace Catch::Generators; + + int map_calls = 0; + auto map_func = [&map_calls]( int i ) { + ++map_calls; + return i; + }; + + MapGenerator map_generator( map_func, values( { 0, 1, 2, 3, 4, 5, 6 } ) ); + const int map_calls_1 = map_calls; + + map_generator.skipToNthElement( 4 ); + REQUIRE( map_generator.get() == 4 ); + REQUIRE( map_calls == map_calls_1 + 1 ); + + map_generator.skipToNthElement( 4 ); + REQUIRE( map_generator.get() == 4 ); + REQUIRE( map_calls == map_calls_1 + 1 ); + + const int map_calls_2 = map_calls; + map_generator.skipToNthElement( 6 ); + REQUIRE( map_generator.get() == 6 ); + REQUIRE( map_calls == map_calls_2 + 1 ); + + REQUIRE_THROWS( map_generator.skipToNthElement( 7 ) ); + REQUIRE( map_calls == map_calls_2 + 1 ); +}