From ef5fd8d42f1f61ee3bd5eb1595f517c34bb2b038 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Sat, 23 Feb 2019 20:37:30 +0100 Subject: [PATCH] Add another test for FilterGenerator --- .../Baselines/compact.sw.approved.txt | 1 + .../Baselines/console.std.approved.txt | 2 +- .../Baselines/console.sw.approved.txt | 16 +++- .../SelfTest/Baselines/junit.sw.approved.txt | 5 +- .../SelfTest/Baselines/xml.sw.approved.txt | 75 ++++++++++++------- .../SelfTest/UsageTests/Generators.tests.cpp | 12 ++- 6 files changed, 78 insertions(+), 33 deletions(-) diff --git a/projects/SelfTest/Baselines/compact.sw.approved.txt b/projects/SelfTest/Baselines/compact.sw.approved.txt index a25cf485..824c4a6b 100644 --- a/projects/SelfTest/Baselines/compact.sw.approved.txt +++ b/projects/SelfTest/Baselines/compact.sw.approved.txt @@ -402,6 +402,7 @@ Matchers.tests.cpp:: passed: WithinULP(1.f, -1), std::domain_error Generators.tests.cpp:: passed: i % 2 == 0 for: 0 == 0 Generators.tests.cpp:: passed: i % 2 == 0 for: 0 == 0 Generators.tests.cpp:: passed: i % 2 == 0 for: 0 == 0 +Generators.tests.cpp:: passed: filter([] (int) {return false; }, value(1)), Catch::GeneratorException Generators.tests.cpp:: passed: i < 4 for: 1 < 4 Generators.tests.cpp:: passed: i < 4 for: 2 < 4 Generators.tests.cpp:: passed: i < 4 for: 3 < 4 diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt index 72baaa26..d936ba03 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: 1378 | 1242 passed | 115 failed | 21 failed as expected +assertions: 1379 | 1243 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 f0edbd6a..6205211a 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -2861,6 +2861,7 @@ Matchers.tests.cpp:: PASSED: ------------------------------------------------------------------------------- Generators -- adapters Filtering by predicate + Basic usage ------------------------------------------------------------------------------- Generators.tests.cpp: ............................................................................... @@ -2873,6 +2874,7 @@ with expansion: ------------------------------------------------------------------------------- Generators -- adapters Filtering by predicate + Basic usage ------------------------------------------------------------------------------- Generators.tests.cpp: ............................................................................... @@ -2885,6 +2887,7 @@ with expansion: ------------------------------------------------------------------------------- Generators -- adapters Filtering by predicate + Basic usage ------------------------------------------------------------------------------- Generators.tests.cpp: ............................................................................... @@ -2894,6 +2897,17 @@ Generators.tests.cpp:: PASSED: with expansion: 0 == 0 +------------------------------------------------------------------------------- +Generators -- adapters + Filtering by predicate + Throws if there are no matching values +------------------------------------------------------------------------------- +Generators.tests.cpp: +............................................................................... + +Generators.tests.cpp:: PASSED: + REQUIRE_THROWS_AS( filter([] (int) {return false; }, value(1)), Catch::GeneratorException ) + ------------------------------------------------------------------------------- Generators -- adapters Shortening a range @@ -10685,5 +10699,5 @@ Misc.tests.cpp:: PASSED: =============================================================================== test cases: 245 | 172 passed | 69 failed | 4 failed as expected -assertions: 1392 | 1242 passed | 129 failed | 21 failed as expected +assertions: 1393 | 1243 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 08a64c33..e477c29c 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -4,7 +4,7 @@ loose text artifact - + @@ -342,7 +342,8 @@ Message.tests.cpp: - + + diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index 989c17f3..31ba5800 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -3540,36 +3540,59 @@
- - - i % 2 == 0 - - - 0 == 0 - - +
+ + + i % 2 == 0 + + + 0 == 0 + + + +
- - - i % 2 == 0 - - - 0 == 0 - - +
+ + + i % 2 == 0 + + + 0 == 0 + + + +
- - - i % 2 == 0 - - - 0 == 0 - - +
+ + + i % 2 == 0 + + + 0 == 0 + + + +
+ +
+
+
+ + + filter([] (int) {return false; }, value(1)), Catch::GeneratorException + + + filter([] (int) {return false; }, value(1)), Catch::GeneratorException + + + +
@@ -12925,7 +12948,7 @@ loose text artifact
- + - + diff --git a/projects/SelfTest/UsageTests/Generators.tests.cpp b/projects/SelfTest/UsageTests/Generators.tests.cpp index 8171e864..0cf1ce6e 100644 --- a/projects/SelfTest/UsageTests/Generators.tests.cpp +++ b/projects/SelfTest/UsageTests/Generators.tests.cpp @@ -118,9 +118,15 @@ TEST_CASE("Generators -- adapters", "[generators][generic]") { // TODO: This won't work yet, introduce GENERATE_VAR? //auto numbers = Catch::Generators::values({ 1, 2, 3, 4, 5, 6 }); SECTION("Filtering by predicate") { - // This filters out all odd (false) numbers, giving [2, 4, 6] - auto i = GENERATE(filter([] (int val) { return val % 2 == 0; }, values({ 1, 2, 3, 4, 5, 6 }))); - REQUIRE(i % 2 == 0); + SECTION("Basic usage") { + // This filters out all odd (false) numbers, giving [2, 4, 6] + auto i = GENERATE(filter([] (int val) { return val % 2 == 0; }, values({ 1, 2, 3, 4, 5, 6 }))); + REQUIRE(i % 2 == 0); + } + SECTION("Throws if there are no matching values") { + using namespace Catch::Generators; + REQUIRE_THROWS_AS(filter([] (int) {return false; }, value(1)), Catch::GeneratorException); + } } SECTION("Shortening a range") { // This takes the first 3 elements from the values, giving back [1, 2, 3]