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

summaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorMartin Hořeňovský2022-05-17 17:57:15 +0200
committerMartin Hořeňovský2022-05-17 17:57:21 +0200
commit7a2a6c632feb7d6e438671b8520beb80efd60ad2 (patch)
treea2ed263dca51619468153ee267e81419496b41e8 /tests
parent359cd6187d7e8fe40dec82e77bafe5066115cb53 (diff)
downloadcatch3-7a2a6c632feb7d6e438671b8520beb80efd60ad2.tar.gz
Make Random*Generators be seedable
This is a necessary step to fix issue with combining multiple random generators in one test case, with different section nesting.
Diffstat (limited to 'tests')
-rw-r--r--tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp b/tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp
index 7793e970..3ad20453 100644
--- a/tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp
+++ b/tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp
@@ -511,3 +511,26 @@ TEST_CASE( "Generator element stringification is cached",
REQUIRE( generator.stringificationCalls() == 1 );
}
+
+TEST_CASE( "Random generators can be seeded", "[generators][approvals]" ) {
+ SECTION( "Integer generator" ) {
+ using Catch::Generators::RandomIntegerGenerator;
+ RandomIntegerGenerator<int> rng1( 0, 100, 0x1234 ),
+ rng2( 0, 100, 0x1234 );
+
+ for ( size_t i = 0; i < 10; ++i ) {
+ REQUIRE( rng1.get() == rng2.get() );
+ rng1.next(); rng2.next();
+ }
+ }
+ SECTION("Float generator") {
+ using Catch::Generators::RandomFloatingGenerator;
+ RandomFloatingGenerator<double> rng1( 0., 100., 0x1234 ),
+ rng2( 0., 100., 0x1234 );
+ for ( size_t i = 0; i < 10; ++i ) {
+ REQUIRE( rng1.get() == rng2.get() );
+ rng1.next();
+ rng2.next();
+ }
+ }
+}