diff options
| author | Manuel Drews | 2019-10-16 16:03:42 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2019-10-26 20:52:09 +0200 |
| commit | 4327baba400f6f8158c4d686135ba7fb6ba10d54 (patch) | |
| tree | 64eb5d02d6236d2babcf3e3a5312e10c66a85737 /projects/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp | |
| parent | 50cc14c94c972fc743afca92b22ad7bdc63c429a (diff) | |
| download | catch3-4327baba400f6f8158c4d686135ba7fb6ba10d54.tar.gz | |
Enable `range` generator for floating point types
Diffstat (limited to 'projects/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp')
| -rw-r--r-- | projects/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
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") { |