Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/projects/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp
diff options
context:
space:
mode:
authorManuel Drews2019-10-16 16:03:42 +0200
committerMartin Hořeňovský2019-10-26 20:52:09 +0200
commit4327baba400f6f8158c4d686135ba7fb6ba10d54 (patch)
tree64eb5d02d6236d2babcf3e3a5312e10c66a85737 /projects/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp
parent50cc14c94c972fc743afca92b22ad7bdc63c429a (diff)
downloadcatch3-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.cpp52
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") {