From 165de9b072ac40d3fea3d7f1ad7fa3aeaa0f5983 Mon Sep 17 00:00:00 2001 From: Rick de Water Date: Sun, 3 Feb 2019 16:42:24 +0100 Subject: [PATCH] Add RangeGenerator --- docs/generators.md | 5 +- include/internal/catch_generators.hpp | 45 ++ .../Baselines/compact.sw.approved.txt | 68 ++ .../Baselines/console.std.approved.txt | 2 +- .../Baselines/console.sw.approved.txt | 420 +++++++++++- .../SelfTest/Baselines/junit.sw.approved.txt | 10 +- .../SelfTest/Baselines/xml.sw.approved.txt | 638 +++++++++++++++++- .../GeneratorsImpl.tests.cpp | 106 +++ 8 files changed, 1288 insertions(+), 6 deletions(-) diff --git a/docs/generators.md b/docs/generators.md index 997feab7..19c31a67 100644 --- a/docs/generators.md +++ b/docs/generators.md @@ -33,9 +33,10 @@ Catch2's provided generator functionality consists of three parts, * `GENERATE` macro, that serves to integrate generator expression with a test case, -* 2 fundamental generators +* 3 fundamental generators * `ValueGenerator` -- contains only single element * `ValuesGenerator` -- contains multiple elements + * `RangeGenerator` -- generates all values between `start` and `end` * 4 generic generators that modify other generators * `FilterGenerator` -- filters out elements from a generator for which the predicate returns "false" @@ -52,6 +53,8 @@ type, making their usage much nicer. These are * `value(T&&)` for `ValueGenerator` * `values(std::initializer_list)` for `ValuesGenerator` +* `range(start, end)` for `RangeGenerator` with a step size of `1` +* `range(start, end, step)` for `RangeGenerator` with a custom step size * `filter(predicate, GeneratorWrapper&&)` for `FilterGenerator` * `take(count, GeneratorWrapper&&)` for `TakeGenerator` * `repeat(repeats, GeneratorWrapper&&)` for `RepeatGenerator` diff --git a/include/internal/catch_generators.hpp b/include/internal/catch_generators.hpp index 3deffc3d..281dc4bc 100644 --- a/include/internal/catch_generators.hpp +++ b/include/internal/catch_generators.hpp @@ -349,6 +349,51 @@ namespace Generators { ); } + template + class RangeGenerator final : public IGenerator { + T m_current; + T m_end; + T m_step; + bool m_positive; + + public: + RangeGenerator(T const& start, T const& end, T const& step): + m_current(start), + m_end(end), + m_step(step), + m_positive(m_step > T(0)) + { + assert(m_current != m_end && "Range start and end cannot be equal"); + assert(m_step != T(0) && "Step size cannot be zero"); + assert(((m_positive && m_current <= m_end) || (!m_positive && m_current >= m_end)) && "Step moves away from end"); + } + + RangeGenerator(T const& start, T const& end): + RangeGenerator(start, end, (start < end) ? T(1) : T(-1)) + {} + + T const& get() const override { + return m_current; + } + + bool next() override { + m_current += m_step; + return (m_positive) ? (m_current < m_end) : (m_current > m_end); + } + }; + + template + GeneratorWrapper range(T const& start, T const& end, T const& step) { + static_assert(std::is_integral::value && !std::is_same::value, "Type must be an integer"); + return GeneratorWrapper(pf::make_unique>(start, end, step)); + } + + template + GeneratorWrapper range(T const& start, T const& end) { + static_assert(std::is_integral::value && !std::is_same::value, "Type must be an integer"); + return GeneratorWrapper(pf::make_unique>(start, end)); + } + auto acquireGeneratorTracker( SourceLineInfo const& lineInfo ) -> IGeneratorTracker&; template diff --git a/projects/SelfTest/Baselines/compact.sw.approved.txt b/projects/SelfTest/Baselines/compact.sw.approved.txt index 0c706c79..69d74ecf 100644 --- a/projects/SelfTest/Baselines/compact.sw.approved.txt +++ b/projects/SelfTest/Baselines/compact.sw.approved.txt @@ -491,6 +491,74 @@ GeneratorsImpl.tests.cpp:: passed: gen.get() == 2 for: 2 == 2 GeneratorsImpl.tests.cpp:: passed: gen.next() for: true GeneratorsImpl.tests.cpp:: passed: gen.get() == 3 for: 3 == 3 GeneratorsImpl.tests.cpp:: passed: !(gen.next()) for: !false +GeneratorsImpl.tests.cpp:: passed: gen.get() == -2 for: -2 == -2 +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true +GeneratorsImpl.tests.cpp:: passed: gen.get() == -1 for: -1 == -1 +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true +GeneratorsImpl.tests.cpp:: passed: gen.get() == 0 for: 0 == 0 +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true +GeneratorsImpl.tests.cpp:: passed: gen.get() == 1 for: 1 == 1 +GeneratorsImpl.tests.cpp:: passed: !(gen.next()) for: !false +GeneratorsImpl.tests.cpp:: passed: gen.get() == 2 for: 2 == 2 +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true +GeneratorsImpl.tests.cpp:: passed: gen.get() == 1 for: 1 == 1 +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true +GeneratorsImpl.tests.cpp:: passed: gen.get() == 0 for: 0 == 0 +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true +GeneratorsImpl.tests.cpp:: passed: gen.get() == -1 for: -1 == -1 +GeneratorsImpl.tests.cpp:: passed: !(gen.next()) for: !false +GeneratorsImpl.tests.cpp:: passed: gen.get() == -7 for: -7 == -7 +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true +GeneratorsImpl.tests.cpp:: passed: gen.get() == -4 for: -4 == -4 +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true +GeneratorsImpl.tests.cpp:: passed: gen.get() == -1 for: -1 == -1 +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true +GeneratorsImpl.tests.cpp:: passed: gen.get() == 2 for: 2 == 2 +GeneratorsImpl.tests.cpp:: passed: !(gen.next()) for: !false +GeneratorsImpl.tests.cpp:: passed: gen.get() == -7 for: -7 == -7 +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true +GeneratorsImpl.tests.cpp:: passed: gen.get() == -4 for: -4 == -4 +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true +GeneratorsImpl.tests.cpp:: passed: gen.get() == -1 for: -1 == -1 +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true +GeneratorsImpl.tests.cpp:: passed: gen.get() == 2 for: 2 == 2 +GeneratorsImpl.tests.cpp:: passed: !(gen.next()) for: !false +GeneratorsImpl.tests.cpp:: passed: gen.get() == -7 for: -7 == -7 +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true +GeneratorsImpl.tests.cpp:: passed: gen.get() == -4 for: -4 == -4 +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true +GeneratorsImpl.tests.cpp:: passed: gen.get() == -1 for: -1 == -1 +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true +GeneratorsImpl.tests.cpp:: passed: gen.get() == 2 for: 2 == 2 +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true +GeneratorsImpl.tests.cpp:: passed: gen.get() == 5 for: 5 == 5 +GeneratorsImpl.tests.cpp:: passed: !(gen.next()) for: !false +GeneratorsImpl.tests.cpp:: passed: gen.get() == 5 for: 5 == 5 +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true +GeneratorsImpl.tests.cpp:: passed: gen.get() == 2 for: 2 == 2 +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true +GeneratorsImpl.tests.cpp:: passed: gen.get() == -1 for: -1 == -1 +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true +GeneratorsImpl.tests.cpp:: passed: gen.get() == -4 for: -4 == -4 +GeneratorsImpl.tests.cpp:: passed: !(gen.next()) for: !false +GeneratorsImpl.tests.cpp:: passed: gen.get() == 5 for: 5 == 5 +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true +GeneratorsImpl.tests.cpp:: passed: gen.get() == 2 for: 2 == 2 +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true +GeneratorsImpl.tests.cpp:: passed: gen.get() == -1 for: -1 == -1 +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true +GeneratorsImpl.tests.cpp:: passed: gen.get() == -4 for: -4 == -4 +GeneratorsImpl.tests.cpp:: passed: !(gen.next()) for: !false +GeneratorsImpl.tests.cpp:: passed: gen.get() == 5 for: 5 == 5 +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true +GeneratorsImpl.tests.cpp:: passed: gen.get() == 2 for: 2 == 2 +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true +GeneratorsImpl.tests.cpp:: passed: gen.get() == -1 for: -1 == -1 +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true +GeneratorsImpl.tests.cpp:: passed: gen.get() == -4 for: -4 == -4 +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true +GeneratorsImpl.tests.cpp:: passed: gen.get() == -7 for: -7 == -7 +GeneratorsImpl.tests.cpp:: passed: !(gen.next()) for: !false Approx.tests.cpp:: passed: d >= Approx( 1.22 ) for: 1.23 >= Approx( 1.22 ) Approx.tests.cpp:: passed: d >= Approx( 1.23 ) for: 1.23 >= Approx( 1.23 ) Approx.tests.cpp:: passed: !(d >= Approx( 1.24 )) for: !(1.23 >= Approx( 1.24 )) diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt index 8e2d5718..b2ff3aa5 100644 --- a/projects/SelfTest/Baselines/console.std.approved.txt +++ b/projects/SelfTest/Baselines/console.std.approved.txt @@ -1175,5 +1175,5 @@ due to unexpected exception with message: =============================================================================== test cases: 245 | 185 passed | 56 failed | 4 failed as expected -assertions: 1297 | 1161 passed | 115 failed | 21 failed as expected +assertions: 1365 | 1229 passed | 115 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index bcaa5ff8..6ff22c77 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -3648,6 +3648,424 @@ GeneratorsImpl.tests.cpp:: PASSED: with expansion: !false +------------------------------------------------------------------------------- +Generators internals + Range + Positive auto step + Integer +------------------------------------------------------------------------------- +GeneratorsImpl.tests.cpp: +............................................................................... + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == -2 ) +with expansion: + -2 == -2 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == -1 ) +with expansion: + -1 == -1 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == 0 ) +with expansion: + 0 == 0 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == 1 ) +with expansion: + 1 == 1 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE_FALSE( gen.next() ) +with expansion: + !false + +------------------------------------------------------------------------------- +Generators internals + Range + Negative auto step + Integer +------------------------------------------------------------------------------- +GeneratorsImpl.tests.cpp: +............................................................................... + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == 2 ) +with expansion: + 2 == 2 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == 1 ) +with expansion: + 1 == 1 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == 0 ) +with expansion: + 0 == 0 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == -1 ) +with expansion: + -1 == -1 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE_FALSE( gen.next() ) +with expansion: + !false + +------------------------------------------------------------------------------- +Generators internals + Range + Positive manual step + Integer + Exact +------------------------------------------------------------------------------- +GeneratorsImpl.tests.cpp: +............................................................................... + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == -7 ) +with expansion: + -7 == -7 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == -4 ) +with expansion: + -4 == -4 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == -1 ) +with expansion: + -1 == -1 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == 2 ) +with expansion: + 2 == 2 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE_FALSE( gen.next() ) +with expansion: + !false + +------------------------------------------------------------------------------- +Generators internals + Range + Positive manual step + Integer + Slightly over end +------------------------------------------------------------------------------- +GeneratorsImpl.tests.cpp: +............................................................................... + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == -7 ) +with expansion: + -7 == -7 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == -4 ) +with expansion: + -4 == -4 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == -1 ) +with expansion: + -1 == -1 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == 2 ) +with expansion: + 2 == 2 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE_FALSE( gen.next() ) +with expansion: + !false + +------------------------------------------------------------------------------- +Generators internals + Range + Positive manual step + Integer + Slightly under end +------------------------------------------------------------------------------- +GeneratorsImpl.tests.cpp: +............................................................................... + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == -7 ) +with expansion: + -7 == -7 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == -4 ) +with expansion: + -4 == -4 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == -1 ) +with expansion: + -1 == -1 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == 2 ) +with expansion: + 2 == 2 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == 5 ) +with expansion: + 5 == 5 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE_FALSE( gen.next() ) +with expansion: + !false + +------------------------------------------------------------------------------- +Generators internals + Range + Negative manual step + Integer + Exact +------------------------------------------------------------------------------- +GeneratorsImpl.tests.cpp: +............................................................................... + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == 5 ) +with expansion: + 5 == 5 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == 2 ) +with expansion: + 2 == 2 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == -1 ) +with expansion: + -1 == -1 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == -4 ) +with expansion: + -4 == -4 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE_FALSE( gen.next() ) +with expansion: + !false + +------------------------------------------------------------------------------- +Generators internals + Range + Negative manual step + Integer + Slightly over end +------------------------------------------------------------------------------- +GeneratorsImpl.tests.cpp: +............................................................................... + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == 5 ) +with expansion: + 5 == 5 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == 2 ) +with expansion: + 2 == 2 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == -1 ) +with expansion: + -1 == -1 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == -4 ) +with expansion: + -4 == -4 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE_FALSE( gen.next() ) +with expansion: + !false + +------------------------------------------------------------------------------- +Generators internals + Range + Negative manual step + Integer + Slightly under end +------------------------------------------------------------------------------- +GeneratorsImpl.tests.cpp: +............................................................................... + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == 5 ) +with expansion: + 5 == 5 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == 2 ) +with expansion: + 2 == 2 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == -1 ) +with expansion: + -1 == -1 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == -4 ) +with expansion: + -4 == -4 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == -7 ) +with expansion: + -7 == -7 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE_FALSE( gen.next() ) +with expansion: + !false + ------------------------------------------------------------------------------- Greater-than inequalities with different epsilons ------------------------------------------------------------------------------- @@ -10156,5 +10574,5 @@ Misc.tests.cpp:: PASSED: =============================================================================== test cases: 245 | 172 passed | 69 failed | 4 failed as expected -assertions: 1311 | 1161 passed | 129 failed | 21 failed as expected +assertions: 1379 | 1229 passed | 129 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index 6f315396..17981c7e 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -4,7 +4,7 @@ loose text artifact - + @@ -359,6 +359,14 @@ Message.tests.cpp: + + + + + + + + diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index e54f8426..bd0d971d 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -4449,6 +4449,640 @@ +
+
+
+ + + gen.get() == -2 + + + -2 == -2 + + + + + gen.next() + + + true + + + + + gen.get() == -1 + + + -1 == -1 + + + + + gen.next() + + + true + + + + + gen.get() == 0 + + + 0 == 0 + + + + + gen.next() + + + true + + + + + gen.get() == 1 + + + 1 == 1 + + + + + !(gen.next()) + + + !false + + + +
+ +
+ +
+
+
+
+ + + gen.get() == 2 + + + 2 == 2 + + + + + gen.next() + + + true + + + + + gen.get() == 1 + + + 1 == 1 + + + + + gen.next() + + + true + + + + + gen.get() == 0 + + + 0 == 0 + + + + + gen.next() + + + true + + + + + gen.get() == -1 + + + -1 == -1 + + + + + !(gen.next()) + + + !false + + + +
+ +
+ +
+
+
+
+
+ + + gen.get() == -7 + + + -7 == -7 + + + + + gen.next() + + + true + + + + + gen.get() == -4 + + + -4 == -4 + + + + + gen.next() + + + true + + + + + gen.get() == -1 + + + -1 == -1 + + + + + gen.next() + + + true + + + + + gen.get() == 2 + + + 2 == 2 + + + + + !(gen.next()) + + + !false + + + +
+ +
+ +
+ +
+
+
+
+
+ + + gen.get() == -7 + + + -7 == -7 + + + + + gen.next() + + + true + + + + + gen.get() == -4 + + + -4 == -4 + + + + + gen.next() + + + true + + + + + gen.get() == -1 + + + -1 == -1 + + + + + gen.next() + + + true + + + + + gen.get() == 2 + + + 2 == 2 + + + + + !(gen.next()) + + + !false + + + +
+ +
+ +
+ +
+
+
+
+
+ + + gen.get() == -7 + + + -7 == -7 + + + + + gen.next() + + + true + + + + + gen.get() == -4 + + + -4 == -4 + + + + + gen.next() + + + true + + + + + gen.get() == -1 + + + -1 == -1 + + + + + gen.next() + + + true + + + + + gen.get() == 2 + + + 2 == 2 + + + + + gen.next() + + + true + + + + + gen.get() == 5 + + + 5 == 5 + + + + + !(gen.next()) + + + !false + + + +
+ +
+ +
+ +
+
+
+
+
+ + + gen.get() == 5 + + + 5 == 5 + + + + + gen.next() + + + true + + + + + gen.get() == 2 + + + 2 == 2 + + + + + gen.next() + + + true + + + + + gen.get() == -1 + + + -1 == -1 + + + + + gen.next() + + + true + + + + + gen.get() == -4 + + + -4 == -4 + + + + + !(gen.next()) + + + !false + + + +
+ +
+ +
+ +
+
+
+
+
+ + + gen.get() == 5 + + + 5 == 5 + + + + + gen.next() + + + true + + + + + gen.get() == 2 + + + 2 == 2 + + + + + gen.next() + + + true + + + + + gen.get() == -1 + + + -1 == -1 + + + + + gen.next() + + + true + + + + + gen.get() == -4 + + + -4 == -4 + + + + + !(gen.next()) + + + !false + + + +
+ +
+ +
+ +
+
+
+
+
+ + + gen.get() == 5 + + + 5 == 5 + + + + + gen.next() + + + true + + + + + gen.get() == 2 + + + 2 == 2 + + + + + gen.next() + + + true + + + + + gen.get() == -1 + + + -1 == -1 + + + + + gen.next() + + + true + + + + + gen.get() == -4 + + + -4 == -4 + + + + + gen.next() + + + true + + + + + gen.get() == -7 + + + -7 == -7 + + + + + !(gen.next()) + + + !false + + + +
+ +
+ +
+ +
@@ -12151,7 +12785,7 @@ loose text artifact - + - + diff --git a/projects/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp b/projects/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp index 0f581947..de8b0ffc 100644 --- a/projects/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp +++ b/projects/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp @@ -99,5 +99,111 @@ TEST_CASE("Generators internals", "[generators][internals]") { REQUIRE_FALSE(gen.next()); } } + SECTION("Range") { + SECTION("Positive auto step") { + SECTION("Integer") { + auto gen = range(-2, 2); + REQUIRE(gen.get() == -2); + REQUIRE(gen.next()); + REQUIRE(gen.get() == -1); + REQUIRE(gen.next()); + REQUIRE(gen.get() == 0); + REQUIRE(gen.next()); + REQUIRE(gen.get() == 1); + REQUIRE_FALSE(gen.next()); + } + } + SECTION("Negative auto step") { + SECTION("Integer") { + auto gen = range(2, -2); + REQUIRE(gen.get() == 2); + REQUIRE(gen.next()); + REQUIRE(gen.get() == 1); + REQUIRE(gen.next()); + REQUIRE(gen.get() == 0); + REQUIRE(gen.next()); + REQUIRE(gen.get() == -1); + REQUIRE_FALSE(gen.next()); + } + } + SECTION("Positive manual step") { + SECTION("Integer") { + SECTION("Exact") { + auto gen = range(-7, 5, 3); + REQUIRE(gen.get() == -7); + REQUIRE(gen.next()); + REQUIRE(gen.get() == -4); + REQUIRE(gen.next()); + REQUIRE(gen.get() == -1); + REQUIRE(gen.next()); + REQUIRE(gen.get() == 2); + REQUIRE_FALSE(gen.next()); + } + SECTION("Slightly over end") { + auto gen = range(-7, 4, 3); + REQUIRE(gen.get() == -7); + REQUIRE(gen.next()); + REQUIRE(gen.get() == -4); + REQUIRE(gen.next()); + REQUIRE(gen.get() == -1); + REQUIRE(gen.next()); + REQUIRE(gen.get() == 2); + REQUIRE_FALSE(gen.next()); + } + SECTION("Slightly under end") { + auto gen = range(-7, 6, 3); + REQUIRE(gen.get() == -7); + REQUIRE(gen.next()); + REQUIRE(gen.get() == -4); + REQUIRE(gen.next()); + REQUIRE(gen.get() == -1); + REQUIRE(gen.next()); + REQUIRE(gen.get() == 2); + REQUIRE(gen.next()); + REQUIRE(gen.get() == 5); + REQUIRE_FALSE(gen.next()); + } + } + } + SECTION("Negative manual step") { + SECTION("Integer") { + SECTION("Exact") { + auto gen = range(5, -7, -3); + REQUIRE(gen.get() == 5); + REQUIRE(gen.next()); + REQUIRE(gen.get() == 2); + REQUIRE(gen.next()); + REQUIRE(gen.get() == -1); + REQUIRE(gen.next()); + REQUIRE(gen.get() == -4); + REQUIRE_FALSE(gen.next()); + } + SECTION("Slightly over end") { + auto gen = range(5, -6, -3); + REQUIRE(gen.get() == 5); + REQUIRE(gen.next()); + REQUIRE(gen.get() == 2); + REQUIRE(gen.next()); + REQUIRE(gen.get() == -1); + REQUIRE(gen.next()); + REQUIRE(gen.get() == -4); + REQUIRE_FALSE(gen.next()); + } + SECTION("Slightly under end") { + auto gen = range(5, -8, -3); + REQUIRE(gen.get() == 5); + REQUIRE(gen.next()); + REQUIRE(gen.get() == 2); + REQUIRE(gen.next()); + REQUIRE(gen.get() == -1); + REQUIRE(gen.next()); + REQUIRE(gen.get() == -4); + REQUIRE(gen.next()); + REQUIRE(gen.get() == -7); + REQUIRE_FALSE(gen.next()); + } + } + } + } }