Add generateRandomSeed utility to generate randomness seed

This commit is contained in:
Martin Hořeňovský
2021-10-08 20:02:24 +02:00
parent fce42b62ad
commit 200a487cf2
14 changed files with 184 additions and 8 deletions

View File

@@ -5,6 +5,8 @@
#include <catch2/catch_test_macros.hpp>
#include <catch2/internal/catch_random_number_generator.hpp>
#include <catch2/internal/catch_random_seed_generation.hpp>
#include <catch2/generators/catch_generators.hpp>
TEST_CASE("Our PCG implementation provides expected results for known seeds", "[rng]") {
Catch::SimplePcg32 rng;
@@ -40,3 +42,18 @@ TEST_CASE("Comparison ops", "[rng]") {
REQUIRE_FALSE(SimplePcg32{ 1 } == SimplePcg32{ 2 });
REQUIRE_FALSE(SimplePcg32{ 1 } != SimplePcg32{ 1 });
}
TEST_CASE("Random seed generation reports unknown methods", "[rng][seed]") {
REQUIRE_THROWS(Catch::generateRandomSeed(static_cast<Catch::GenerateFrom>(77)));
}
TEST_CASE("Random seed generation accepts known methods", "[rng][seed]") {
using Catch::GenerateFrom;
const auto method = GENERATE(
GenerateFrom::Time,
GenerateFrom::RandomDevice,
GenerateFrom::Default
);
REQUIRE_NOTHROW(Catch::generateRandomSeed(method));
}