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

summaryrefslogtreecommitdiffhomepage
path: root/tests/SelfTest/IntrospectiveTests/RandomNumberGeneration.tests.cpp
diff options
context:
space:
mode:
authorMartin Hořeňovský2023-12-10 16:26:07 +0100
committerMartin Hořeňovský2023-12-10 19:53:46 +0100
commitcb07ff9a7eaf586bfcd74337373192733090675d (patch)
tree0efba7868815dbd11fd9f62f3dd529b3028eda6c /tests/SelfTest/IntrospectiveTests/RandomNumberGeneration.tests.cpp
parentae4fe16b81d819bbef8920eddf8d38a3538fe826 (diff)
downloadcatch3-cb07ff9a7eaf586bfcd74337373192733090675d.tar.gz
Fix uniform_floating_point_distribution for unit ranges
Diffstat (limited to 'tests/SelfTest/IntrospectiveTests/RandomNumberGeneration.tests.cpp')
-rw-r--r--tests/SelfTest/IntrospectiveTests/RandomNumberGeneration.tests.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/SelfTest/IntrospectiveTests/RandomNumberGeneration.tests.cpp b/tests/SelfTest/IntrospectiveTests/RandomNumberGeneration.tests.cpp
index 379f8b23..03be6c9c 100644
--- a/tests/SelfTest/IntrospectiveTests/RandomNumberGeneration.tests.cpp
+++ b/tests/SelfTest/IntrospectiveTests/RandomNumberGeneration.tests.cpp
@@ -8,6 +8,7 @@
#include <catch2/catch_test_macros.hpp>
#include <catch2/catch_template_test_macros.hpp>
+#include <catch2/internal/catch_floating_point_helpers.hpp>
#include <catch2/internal/catch_random_integer_helpers.hpp>
#include <catch2/internal/catch_random_number_generator.hpp>
#include <catch2/internal/catch_random_seed_generation.hpp>
@@ -568,3 +569,22 @@ TEMPLATE_TEST_CASE( "uniform_floating_point_distribution is reproducible",
REQUIRE_THAT( generated, Catch::Matchers::RangeEquals( uniform_fp_test_params<TestType>::expected ) );
}
+
+TEMPLATE_TEST_CASE( "uniform_floating_point_distribution can handle unitary ranges",
+ "[rng][distribution][floating-point][approvals]",
+ float,
+ double ) {
+ std::random_device rd;
+ auto seed = rd();
+ CAPTURE( seed );
+ Catch::SimplePcg32 pcg( seed );
+
+ const auto highest = uniform_fp_test_params<TestType>::highest;
+ Catch::uniform_floating_point_distribution<TestType> dist( highest,
+ highest );
+
+ constexpr auto iters = 20;
+ for (int i = 0; i < iters; ++i) {
+ REQUIRE( Catch::Detail::directCompare( dist( pcg ), highest ) );
+ }
+}