2018-06-12 18:50:39 +02:00
|
|
|
#include "catch.hpp"
|
|
|
|
|
2019-01-27 19:46:28 +01:00
|
|
|
// Tests of generator implementation details
|
|
|
|
TEST_CASE("Generators internals", "[generators][internals]") {
|
2018-06-12 18:50:39 +02:00
|
|
|
using namespace Catch::Generators;
|
|
|
|
|
2019-01-27 19:46:28 +01:00
|
|
|
SECTION("Single value") {
|
|
|
|
auto gen = value(123);
|
|
|
|
REQUIRE(gen.get() == 123);
|
|
|
|
REQUIRE_FALSE(gen.next());
|
|
|
|
}
|
|
|
|
SECTION("Preset values") {
|
|
|
|
auto gen = values({ 1, 3, 5 });
|
|
|
|
REQUIRE(gen.get() == 1);
|
|
|
|
REQUIRE(gen.next());
|
|
|
|
REQUIRE(gen.get() == 3);
|
|
|
|
REQUIRE(gen.next());
|
|
|
|
REQUIRE(gen.get() == 5);
|
|
|
|
REQUIRE_FALSE(gen.next());
|
|
|
|
}
|
|
|
|
SECTION("Generator combinator") {
|
|
|
|
auto gen = makeGenerators(1, 5, values({ 2, 4 }), 0);
|
|
|
|
REQUIRE(gen.get() == 1);
|
|
|
|
REQUIRE(gen.next());
|
|
|
|
REQUIRE(gen.get() == 5);
|
|
|
|
REQUIRE(gen.next());
|
|
|
|
REQUIRE(gen.get() == 2);
|
|
|
|
REQUIRE(gen.next());
|
|
|
|
REQUIRE(gen.get() == 4);
|
|
|
|
REQUIRE(gen.next());
|
|
|
|
REQUIRE(gen.get() == 0);
|
|
|
|
REQUIRE_FALSE(gen.next());
|
|
|
|
}
|
|
|
|
SECTION("Explicitly typed generator sequence") {
|
|
|
|
auto gen = makeGenerators(as<std::string>{}, "aa", "bb", "cc");
|
|
|
|
// This just checks that the type is std::string:
|
|
|
|
REQUIRE(gen.get().size() == 2);
|
|
|
|
// Iterate over the generator
|
|
|
|
REQUIRE(gen.get() == "aa");
|
|
|
|
REQUIRE(gen.next());
|
|
|
|
REQUIRE(gen.get() == "bb");
|
|
|
|
REQUIRE(gen.next());
|
|
|
|
REQUIRE(gen.get() == "cc");
|
|
|
|
REQUIRE_FALSE(gen.next());
|
2018-06-12 18:50:39 +02:00
|
|
|
}
|
|
|
|
}
|