From 4327baba400f6f8158c4d686135ba7fb6ba10d54 Mon Sep 17 00:00:00 2001 From: Manuel Drews Date: Wed, 16 Oct 2019 16:03:42 +0200 Subject: [PATCH 1/2] Enable `range` generator for floating point types --- .../internal/catch_generators_specific.hpp | 2 +- .../Baselines/compact.sw.approved.txt | 68 ++ .../Baselines/console.std.approved.txt | 2 +- .../Baselines/console.sw.approved.txt | 500 ++++++++++- .../SelfTest/Baselines/junit.sw.approved.txt | 5 +- .../SelfTest/Baselines/xml.sw.approved.txt | 776 +++++++++++++++++- .../GeneratorsImpl.tests.cpp | 52 ++ 7 files changed, 1399 insertions(+), 6 deletions(-) diff --git a/include/internal/catch_generators_specific.hpp b/include/internal/catch_generators_specific.hpp index f57d29b6..dee8e711 100644 --- a/include/internal/catch_generators_specific.hpp +++ b/include/internal/catch_generators_specific.hpp @@ -117,7 +117,7 @@ public: 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"); + static_assert(std::is_arithmetic::value && !std::is_same::value, "Type must be numeric"); return GeneratorWrapper(pf::make_unique>(start, end, step)); } diff --git a/projects/SelfTest/Baselines/compact.sw.approved.txt b/projects/SelfTest/Baselines/compact.sw.approved.txt index 4090d70c..a65f15ab 100644 --- a/projects/SelfTest/Baselines/compact.sw.approved.txt +++ b/projects/SelfTest/Baselines/compact.sw.approved.txt @@ -631,6 +631,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() == 5 for: 5 == 5 GeneratorsImpl.tests.cpp:: passed: !(gen.next()) for: !false +GeneratorsImpl.tests.cpp:: passed: gen.get() == Approx(expected) for: -1.0 == Approx( -1.0 ) with 1 message: 'Current expected value is -1' +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true with 1 message: 'Current expected value is -1' +GeneratorsImpl.tests.cpp:: passed: gen.get() == Approx(expected) for: -0.9 == Approx( -0.9 ) with 1 message: 'Current expected value is -0.9' +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true with 1 message: 'Current expected value is -0.9' +GeneratorsImpl.tests.cpp:: passed: gen.get() == Approx(expected) for: -0.8 == Approx( -0.8 ) with 1 message: 'Current expected value is -0.8' +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true with 1 message: 'Current expected value is -0.8' +GeneratorsImpl.tests.cpp:: passed: gen.get() == Approx(expected) for: -0.7 == Approx( -0.7 ) with 1 message: 'Current expected value is -0.7' +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true with 1 message: 'Current expected value is -0.7' +GeneratorsImpl.tests.cpp:: passed: gen.get() == Approx(expected) for: -0.6 == Approx( -0.6 ) with 1 message: 'Current expected value is -0.6' +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true with 1 message: 'Current expected value is -0.6' +GeneratorsImpl.tests.cpp:: passed: gen.get() == Approx(expected) for: -0.5 == Approx( -0.5 ) with 1 message: 'Current expected value is -0.5' +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true with 1 message: 'Current expected value is -0.5' +GeneratorsImpl.tests.cpp:: passed: gen.get() == Approx(expected) for: -0.4 == Approx( -0.4 ) with 1 message: 'Current expected value is -0.4' +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true with 1 message: 'Current expected value is -0.4' +GeneratorsImpl.tests.cpp:: passed: gen.get() == Approx(expected) for: -0.3 == Approx( -0.3 ) with 1 message: 'Current expected value is -0.3' +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true with 1 message: 'Current expected value is -0.3' +GeneratorsImpl.tests.cpp:: passed: gen.get() == Approx(expected) for: -0.2 == Approx( -0.2 ) with 1 message: 'Current expected value is -0.2' +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true with 1 message: 'Current expected value is -0.2' +GeneratorsImpl.tests.cpp:: passed: gen.get() == Approx(expected) for: -0.1 == Approx( -0.1 ) with 1 message: 'Current expected value is -0.1' +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true with 1 message: 'Current expected value is -0.1' +GeneratorsImpl.tests.cpp:: passed: gen.get() == Approx(expected) for: -0.0 == Approx( -0.0 ) with 1 message: 'Current expected value is -1.38778e-16' +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true with 1 message: 'Current expected value is -1.38778e-16' +GeneratorsImpl.tests.cpp:: passed: gen.get() == Approx(expected) for: 0.1 == Approx( 0.1 ) with 1 message: 'Current expected value is 0.1' +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true with 1 message: 'Current expected value is 0.1' +GeneratorsImpl.tests.cpp:: passed: gen.get() == Approx(expected) for: 0.2 == Approx( 0.2 ) with 1 message: 'Current expected value is 0.2' +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true with 1 message: 'Current expected value is 0.2' +GeneratorsImpl.tests.cpp:: passed: gen.get() == Approx(expected) for: 0.3 == Approx( 0.3 ) with 1 message: 'Current expected value is 0.3' +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true with 1 message: 'Current expected value is 0.3' +GeneratorsImpl.tests.cpp:: passed: gen.get() == Approx(expected) for: 0.4 == Approx( 0.4 ) with 1 message: 'Current expected value is 0.4' +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true with 1 message: 'Current expected value is 0.4' +GeneratorsImpl.tests.cpp:: passed: gen.get() == Approx(expected) for: 0.5 == Approx( 0.5 ) with 1 message: 'Current expected value is 0.5' +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true with 1 message: 'Current expected value is 0.5' +GeneratorsImpl.tests.cpp:: passed: gen.get() == Approx(expected) for: 0.6 == Approx( 0.6 ) with 1 message: 'Current expected value is 0.6' +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true with 1 message: 'Current expected value is 0.6' +GeneratorsImpl.tests.cpp:: passed: gen.get() == Approx(expected) for: 0.7 == Approx( 0.7 ) with 1 message: 'Current expected value is 0.7' +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true with 1 message: 'Current expected value is 0.7' +GeneratorsImpl.tests.cpp:: passed: gen.get() == Approx(expected) for: 0.8 == Approx( 0.8 ) with 1 message: 'Current expected value is 0.8' +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true with 1 message: 'Current expected value is 0.8' +GeneratorsImpl.tests.cpp:: passed: gen.get() == Approx(expected) for: 0.9 == Approx( 0.9 ) with 1 message: 'Current expected value is 0.9' +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true with 1 message: 'Current expected value is 0.9' +GeneratorsImpl.tests.cpp:: passed: gen.get() == Approx( rangeEnd ) for: 1.0 == Approx( 1.0 ) +GeneratorsImpl.tests.cpp:: passed: !(gen.next()) for: !false +GeneratorsImpl.tests.cpp:: passed: gen.get() == Approx(expected) for: -1.0 == Approx( -1.0 ) with 1 message: 'Current expected value is -1' +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true with 1 message: 'Current expected value is -1' +GeneratorsImpl.tests.cpp:: passed: gen.get() == Approx(expected) for: -0.7 == Approx( -0.7 ) with 1 message: 'Current expected value is -0.7' +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true with 1 message: 'Current expected value is -0.7' +GeneratorsImpl.tests.cpp:: passed: gen.get() == Approx(expected) for: -0.4 == Approx( -0.4 ) with 1 message: 'Current expected value is -0.4' +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true with 1 message: 'Current expected value is -0.4' +GeneratorsImpl.tests.cpp:: passed: gen.get() == Approx(expected) for: -0.1 == Approx( -0.1 ) with 1 message: 'Current expected value is -0.1' +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true with 1 message: 'Current expected value is -0.1' +GeneratorsImpl.tests.cpp:: passed: gen.get() == Approx(expected) for: 0.2 == Approx( 0.2 ) with 1 message: 'Current expected value is 0.2' +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true with 1 message: 'Current expected value is 0.2' +GeneratorsImpl.tests.cpp:: passed: gen.get() == Approx(expected) for: 0.5 == Approx( 0.5 ) with 1 message: 'Current expected value is 0.5' +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true with 1 message: 'Current expected value is 0.5' +GeneratorsImpl.tests.cpp:: passed: !(gen.next()) for: !false +GeneratorsImpl.tests.cpp:: passed: gen.get() == Approx(expected) for: -1.0 == Approx( -1.0 ) with 1 message: 'Current expected value is -1' +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true with 1 message: 'Current expected value is -1' +GeneratorsImpl.tests.cpp:: passed: gen.get() == Approx(expected) for: -0.7 == Approx( -0.7 ) with 1 message: 'Current expected value is -0.7' +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true with 1 message: 'Current expected value is -0.7' +GeneratorsImpl.tests.cpp:: passed: gen.get() == Approx(expected) for: -0.4 == Approx( -0.4 ) with 1 message: 'Current expected value is -0.4' +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true with 1 message: 'Current expected value is -0.4' +GeneratorsImpl.tests.cpp:: passed: gen.get() == Approx(expected) for: -0.1 == Approx( -0.1 ) with 1 message: 'Current expected value is -0.1' +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true with 1 message: 'Current expected value is -0.1' +GeneratorsImpl.tests.cpp:: passed: gen.get() == Approx(expected) for: 0.2 == Approx( 0.2 ) with 1 message: 'Current expected value is 0.2' +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true with 1 message: 'Current expected value is 0.2' +GeneratorsImpl.tests.cpp:: passed: gen.get() == Approx(expected) for: 0.5 == Approx( 0.5 ) with 1 message: 'Current expected value is 0.5' +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true with 1 message: 'Current expected value is 0.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 diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt index f6f43449..d43063fe 100644 --- a/projects/SelfTest/Baselines/console.std.approved.txt +++ b/projects/SelfTest/Baselines/console.std.approved.txt @@ -1381,5 +1381,5 @@ due to unexpected exception with message: =============================================================================== test cases: 305 | 231 passed | 70 failed | 4 failed as expected -assertions: 1627 | 1475 passed | 131 failed | 21 failed as expected +assertions: 1695 | 1543 passed | 131 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index 0e7f7162..d321bd91 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -4774,6 +4774,504 @@ GeneratorsImpl.tests.cpp:: PASSED: with expansion: !false +------------------------------------------------------------------------------- +Generators internals + Range + Positive manual step + Floating Point + Exact +------------------------------------------------------------------------------- +GeneratorsImpl.tests.cpp: +............................................................................... + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == Approx(expected) ) +with expansion: + -1.0 == Approx( -1.0 ) +with message: + Current expected value is -1 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true +with message: + Current expected value is -1 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == Approx(expected) ) +with expansion: + -0.9 == Approx( -0.9 ) +with message: + Current expected value is -0.9 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true +with message: + Current expected value is -0.9 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == Approx(expected) ) +with expansion: + -0.8 == Approx( -0.8 ) +with message: + Current expected value is -0.8 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true +with message: + Current expected value is -0.8 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == Approx(expected) ) +with expansion: + -0.7 == Approx( -0.7 ) +with message: + Current expected value is -0.7 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true +with message: + Current expected value is -0.7 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == Approx(expected) ) +with expansion: + -0.6 == Approx( -0.6 ) +with message: + Current expected value is -0.6 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true +with message: + Current expected value is -0.6 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == Approx(expected) ) +with expansion: + -0.5 == Approx( -0.5 ) +with message: + Current expected value is -0.5 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true +with message: + Current expected value is -0.5 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == Approx(expected) ) +with expansion: + -0.4 == Approx( -0.4 ) +with message: + Current expected value is -0.4 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true +with message: + Current expected value is -0.4 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == Approx(expected) ) +with expansion: + -0.3 == Approx( -0.3 ) +with message: + Current expected value is -0.3 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true +with message: + Current expected value is -0.3 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == Approx(expected) ) +with expansion: + -0.2 == Approx( -0.2 ) +with message: + Current expected value is -0.2 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true +with message: + Current expected value is -0.2 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == Approx(expected) ) +with expansion: + -0.1 == Approx( -0.1 ) +with message: + Current expected value is -0.1 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true +with message: + Current expected value is -0.1 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == Approx(expected) ) +with expansion: + -0.0 == Approx( -0.0 ) +with message: + Current expected value is -1.38778e-16 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true +with message: + Current expected value is -1.38778e-16 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == Approx(expected) ) +with expansion: + 0.1 == Approx( 0.1 ) +with message: + Current expected value is 0.1 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true +with message: + Current expected value is 0.1 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == Approx(expected) ) +with expansion: + 0.2 == Approx( 0.2 ) +with message: + Current expected value is 0.2 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true +with message: + Current expected value is 0.2 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == Approx(expected) ) +with expansion: + 0.3 == Approx( 0.3 ) +with message: + Current expected value is 0.3 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true +with message: + Current expected value is 0.3 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == Approx(expected) ) +with expansion: + 0.4 == Approx( 0.4 ) +with message: + Current expected value is 0.4 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true +with message: + Current expected value is 0.4 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == Approx(expected) ) +with expansion: + 0.5 == Approx( 0.5 ) +with message: + Current expected value is 0.5 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true +with message: + Current expected value is 0.5 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == Approx(expected) ) +with expansion: + 0.6 == Approx( 0.6 ) +with message: + Current expected value is 0.6 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true +with message: + Current expected value is 0.6 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == Approx(expected) ) +with expansion: + 0.7 == Approx( 0.7 ) +with message: + Current expected value is 0.7 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true +with message: + Current expected value is 0.7 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == Approx(expected) ) +with expansion: + 0.8 == Approx( 0.8 ) +with message: + Current expected value is 0.8 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true +with message: + Current expected value is 0.8 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == Approx(expected) ) +with expansion: + 0.9 == Approx( 0.9 ) +with message: + Current expected value is 0.9 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true +with message: + Current expected value is 0.9 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == Approx( rangeEnd ) ) +with expansion: + 1.0 == Approx( 1.0 ) + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE_FALSE( gen.next() ) +with expansion: + !false + +------------------------------------------------------------------------------- +Generators internals + Range + Positive manual step + Floating Point + Slightly over end +------------------------------------------------------------------------------- +GeneratorsImpl.tests.cpp: +............................................................................... + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == Approx(expected) ) +with expansion: + -1.0 == Approx( -1.0 ) +with message: + Current expected value is -1 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true +with message: + Current expected value is -1 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == Approx(expected) ) +with expansion: + -0.7 == Approx( -0.7 ) +with message: + Current expected value is -0.7 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true +with message: + Current expected value is -0.7 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == Approx(expected) ) +with expansion: + -0.4 == Approx( -0.4 ) +with message: + Current expected value is -0.4 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true +with message: + Current expected value is -0.4 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == Approx(expected) ) +with expansion: + -0.1 == Approx( -0.1 ) +with message: + Current expected value is -0.1 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true +with message: + Current expected value is -0.1 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == Approx(expected) ) +with expansion: + 0.2 == Approx( 0.2 ) +with message: + Current expected value is 0.2 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true +with message: + Current expected value is 0.2 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == Approx(expected) ) +with expansion: + 0.5 == Approx( 0.5 ) +with message: + Current expected value is 0.5 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true +with message: + Current expected value is 0.5 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE_FALSE( gen.next() ) +with expansion: + !false + +------------------------------------------------------------------------------- +Generators internals + Range + Positive manual step + Floating Point + Slightly under end +------------------------------------------------------------------------------- +GeneratorsImpl.tests.cpp: +............................................................................... + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == Approx(expected) ) +with expansion: + -1.0 == Approx( -1.0 ) +with message: + Current expected value is -1 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true +with message: + Current expected value is -1 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == Approx(expected) ) +with expansion: + -0.7 == Approx( -0.7 ) +with message: + Current expected value is -0.7 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true +with message: + Current expected value is -0.7 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == Approx(expected) ) +with expansion: + -0.4 == Approx( -0.4 ) +with message: + Current expected value is -0.4 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true +with message: + Current expected value is -0.4 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == Approx(expected) ) +with expansion: + -0.1 == Approx( -0.1 ) +with message: + Current expected value is -0.1 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true +with message: + Current expected value is -0.1 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == Approx(expected) ) +with expansion: + 0.2 == Approx( 0.2 ) +with message: + Current expected value is 0.2 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true +with message: + Current expected value is 0.2 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == Approx(expected) ) +with expansion: + 0.5 == Approx( 0.5 ) +with message: + Current expected value is 0.5 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true +with message: + Current expected value is 0.5 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE_FALSE( gen.next() ) +with expansion: + !false + ------------------------------------------------------------------------------- Generators internals Range @@ -12967,5 +13465,5 @@ Misc.tests.cpp:: PASSED: =============================================================================== test cases: 305 | 215 passed | 86 failed | 4 failed as expected -assertions: 1644 | 1475 passed | 148 failed | 21 failed as expected +assertions: 1712 | 1543 passed | 148 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index 61b364f3..82bf925f 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + @@ -444,6 +444,9 @@ Message.tests.cpp: + + + diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index 4b67b803..35640250 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -5812,6 +5812,778 @@ Nor would this +
+
+
+
+ + Current expected value is -1 + + + + gen.get() == Approx(expected) + + + -1.0 == Approx( -1.0 ) + + + + Current expected value is -1 + + + + gen.next() + + + true + + + + Current expected value is -0.9 + + + + gen.get() == Approx(expected) + + + -0.9 == Approx( -0.9 ) + + + + Current expected value is -0.9 + + + + gen.next() + + + true + + + + Current expected value is -0.8 + + + + gen.get() == Approx(expected) + + + -0.8 == Approx( -0.8 ) + + + + Current expected value is -0.8 + + + + gen.next() + + + true + + + + Current expected value is -0.7 + + + + gen.get() == Approx(expected) + + + -0.7 == Approx( -0.7 ) + + + + Current expected value is -0.7 + + + + gen.next() + + + true + + + + Current expected value is -0.6 + + + + gen.get() == Approx(expected) + + + -0.6 == Approx( -0.6 ) + + + + Current expected value is -0.6 + + + + gen.next() + + + true + + + + Current expected value is -0.5 + + + + gen.get() == Approx(expected) + + + -0.5 == Approx( -0.5 ) + + + + Current expected value is -0.5 + + + + gen.next() + + + true + + + + Current expected value is -0.4 + + + + gen.get() == Approx(expected) + + + -0.4 == Approx( -0.4 ) + + + + Current expected value is -0.4 + + + + gen.next() + + + true + + + + Current expected value is -0.3 + + + + gen.get() == Approx(expected) + + + -0.3 == Approx( -0.3 ) + + + + Current expected value is -0.3 + + + + gen.next() + + + true + + + + Current expected value is -0.2 + + + + gen.get() == Approx(expected) + + + -0.2 == Approx( -0.2 ) + + + + Current expected value is -0.2 + + + + gen.next() + + + true + + + + Current expected value is -0.1 + + + + gen.get() == Approx(expected) + + + -0.1 == Approx( -0.1 ) + + + + Current expected value is -0.1 + + + + gen.next() + + + true + + + + Current expected value is -1.38778e-16 + + + + gen.get() == Approx(expected) + + + -0.0 == Approx( -0.0 ) + + + + Current expected value is -1.38778e-16 + + + + gen.next() + + + true + + + + Current expected value is 0.1 + + + + gen.get() == Approx(expected) + + + 0.1 == Approx( 0.1 ) + + + + Current expected value is 0.1 + + + + gen.next() + + + true + + + + Current expected value is 0.2 + + + + gen.get() == Approx(expected) + + + 0.2 == Approx( 0.2 ) + + + + Current expected value is 0.2 + + + + gen.next() + + + true + + + + Current expected value is 0.3 + + + + gen.get() == Approx(expected) + + + 0.3 == Approx( 0.3 ) + + + + Current expected value is 0.3 + + + + gen.next() + + + true + + + + Current expected value is 0.4 + + + + gen.get() == Approx(expected) + + + 0.4 == Approx( 0.4 ) + + + + Current expected value is 0.4 + + + + gen.next() + + + true + + + + Current expected value is 0.5 + + + + gen.get() == Approx(expected) + + + 0.5 == Approx( 0.5 ) + + + + Current expected value is 0.5 + + + + gen.next() + + + true + + + + Current expected value is 0.6 + + + + gen.get() == Approx(expected) + + + 0.6 == Approx( 0.6 ) + + + + Current expected value is 0.6 + + + + gen.next() + + + true + + + + Current expected value is 0.7 + + + + gen.get() == Approx(expected) + + + 0.7 == Approx( 0.7 ) + + + + Current expected value is 0.7 + + + + gen.next() + + + true + + + + Current expected value is 0.8 + + + + gen.get() == Approx(expected) + + + 0.8 == Approx( 0.8 ) + + + + Current expected value is 0.8 + + + + gen.next() + + + true + + + + Current expected value is 0.9 + + + + gen.get() == Approx(expected) + + + 0.9 == Approx( 0.9 ) + + + + Current expected value is 0.9 + + + + gen.next() + + + true + + + + + gen.get() == Approx( rangeEnd ) + + + 1.0 == Approx( 1.0 ) + + + + + !(gen.next()) + + + !false + + + +
+ +
+ +
+ +
+
+
+
+
+ + Current expected value is -1 + + + + gen.get() == Approx(expected) + + + -1.0 == Approx( -1.0 ) + + + + Current expected value is -1 + + + + gen.next() + + + true + + + + Current expected value is -0.7 + + + + gen.get() == Approx(expected) + + + -0.7 == Approx( -0.7 ) + + + + Current expected value is -0.7 + + + + gen.next() + + + true + + + + Current expected value is -0.4 + + + + gen.get() == Approx(expected) + + + -0.4 == Approx( -0.4 ) + + + + Current expected value is -0.4 + + + + gen.next() + + + true + + + + Current expected value is -0.1 + + + + gen.get() == Approx(expected) + + + -0.1 == Approx( -0.1 ) + + + + Current expected value is -0.1 + + + + gen.next() + + + true + + + + Current expected value is 0.2 + + + + gen.get() == Approx(expected) + + + 0.2 == Approx( 0.2 ) + + + + Current expected value is 0.2 + + + + gen.next() + + + true + + + + Current expected value is 0.5 + + + + gen.get() == Approx(expected) + + + 0.5 == Approx( 0.5 ) + + + + Current expected value is 0.5 + + + + gen.next() + + + true + + + + + !(gen.next()) + + + !false + + + +
+ +
+ +
+ +
+
+
+
+
+ + Current expected value is -1 + + + + gen.get() == Approx(expected) + + + -1.0 == Approx( -1.0 ) + + + + Current expected value is -1 + + + + gen.next() + + + true + + + + Current expected value is -0.7 + + + + gen.get() == Approx(expected) + + + -0.7 == Approx( -0.7 ) + + + + Current expected value is -0.7 + + + + gen.next() + + + true + + + + Current expected value is -0.4 + + + + gen.get() == Approx(expected) + + + -0.4 == Approx( -0.4 ) + + + + Current expected value is -0.4 + + + + gen.next() + + + true + + + + Current expected value is -0.1 + + + + gen.get() == Approx(expected) + + + -0.1 == Approx( -0.1 ) + + + + Current expected value is -0.1 + + + + gen.next() + + + true + + + + Current expected value is 0.2 + + + + gen.get() == Approx(expected) + + + 0.2 == Approx( 0.2 ) + + + + Current expected value is 0.2 + + + + gen.next() + + + true + + + + Current expected value is 0.5 + + + + gen.get() == Approx(expected) + + + 0.5 == Approx( 0.5 ) + + + + Current expected value is 0.5 + + + + gen.next() + + + true + + + + + !(gen.next()) + + + !false + + + +
+ +
+ +
+ +
@@ -15390,7 +16162,7 @@ loose text artifact
- + - + diff --git a/projects/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp b/projects/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp index 076c91a9..9cbe8931 100644 --- a/projects/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp +++ b/projects/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp @@ -173,6 +173,58 @@ TEST_CASE("Generators internals", "[generators][internals]") { REQUIRE_FALSE(gen.next()); } } + + SECTION("Floating Point") { + SECTION("Exact") { + const auto rangeStart = -1.; + const auto rangeEnd = 1.; + const auto step = .1; + + auto gen = range(rangeStart, rangeEnd, step); + auto expected = rangeStart; + while( (rangeEnd - expected) > step ) { + INFO( "Current expected value is " << expected ) + REQUIRE(gen.get() == Approx(expected)); + REQUIRE(gen.next()); + + expected += step; + } + REQUIRE(gen.get() == Approx( rangeEnd ) ); + REQUIRE_FALSE(gen.next()); + } + SECTION("Slightly over end") { + const auto rangeStart = -1.; + const auto rangeEnd = 1.; + const auto step = .3; + + auto gen = range(rangeStart, rangeEnd, step); + auto expected = rangeStart; + while( (rangeEnd - expected) > step ) { + INFO( "Current expected value is " << expected ) + REQUIRE(gen.get() == Approx(expected)); + REQUIRE(gen.next()); + + expected += step; + } + REQUIRE_FALSE(gen.next()); + } + SECTION("Slightly under end") { + const auto rangeStart = -1.; + const auto rangeEnd = .9; + const auto step = .3; + + auto gen = range(rangeStart, rangeEnd, step); + auto expected = rangeStart; + while( (rangeEnd - expected) > step ) { + INFO( "Current expected value is " << expected ) + REQUIRE(gen.get() == Approx(expected)); + REQUIRE(gen.next()); + + expected += step; + } + REQUIRE_FALSE(gen.next()); + } + } } SECTION("Negative manual step") { SECTION("Integer") { From 6a0822586382fcfa4bae4378b12656036850f959 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Sat, 26 Oct 2019 20:49:56 +0200 Subject: [PATCH 2/2] Add documentation for floating point `range` generator --- docs/generators.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/generators.md b/docs/generators.md index 61276f3c..d0147d7f 100644 --- a/docs/generators.md +++ b/docs/generators.md @@ -49,7 +49,7 @@ a test case, * 4 specific purpose generators * `RandomIntegerGenerator` -- generates random Integrals from range * `RandomFloatGenerator` -- generates random Floats from range - * `RangeGenerator` -- generates all values inside a specific range + * `RangeGenerator` -- generates all values inside an arithmetic range * `IteratorGenerator` -- copies and returns values from an iterator range > `ChunkGenerator`, `RandomIntegerGenerator`, `RandomFloatGenerator` and `RangeGenerator` were introduced in Catch 2.7.0. @@ -69,8 +69,8 @@ type, making their usage much nicer. These are * `map(func, GeneratorWrapper&&)` for `MapGenerator` (map `U` to `T`) * `chunk(chunk-size, GeneratorWrapper&&)` for `ChunkGenerator` * `random(IntegerOrFloat a, IntegerOrFloat b)` for `RandomIntegerGenerator` or `RandomFloatGenerator` -* `range(start, end)` for `RangeGenerator` with a step size of `1` -* `range(start, end, step)` for `RangeGenerator` with a custom step size +* `range(Arithemtic start, Arithmetic end)` for `RangeGenerator` with a step size of `1` +* `range(Arithmetic start, Arithmetic end, Arithmetic step)` for `RangeGenerator` with a custom step size * `from_range(InputIterator from, InputIterator to)` for `IteratorGenerator` * `from_range(Container const&)` for `IteratorGenerator` @@ -78,6 +78,8 @@ type, making their usage much nicer. These are > `from_range` has been introduced in Catch 2.10.0 +> `range()` for floating point numbers has been introduced in Catch X.Y.Z + And can be used as shown in the example below to create a generator that returns 100 odd random number: