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

summaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorMartin Hořeňovský2023-11-20 15:16:50 +0100
committerMartin Hořeňovský2023-12-10 18:44:12 +0100
commitab1b079e4deb159a6f56c9168031876a697a7d2c (patch)
treebfcac1219d4bc50f970e6f5a4efb0c10bec23684 /tests
parentd139b4ff7cd8823923e8616e8fef954e09e46322 (diff)
downloadcatch3-ab1b079e4deb159a6f56c9168031876a697a7d2c.tar.gz
Add uniform_floating_point_distribution
Diffstat (limited to 'tests')
-rw-r--r--tests/SelfTest/IntrospectiveTests/RandomNumberGeneration.tests.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/SelfTest/IntrospectiveTests/RandomNumberGeneration.tests.cpp b/tests/SelfTest/IntrospectiveTests/RandomNumberGeneration.tests.cpp
index 8018b7eb..ad44668d 100644
--- a/tests/SelfTest/IntrospectiveTests/RandomNumberGeneration.tests.cpp
+++ b/tests/SelfTest/IntrospectiveTests/RandomNumberGeneration.tests.cpp
@@ -7,8 +7,10 @@
// SPDX-License-Identifier: BSL-1.0
#include <catch2/catch_test_macros.hpp>
+#include <catch2/catch_template_test_macros.hpp>
#include <catch2/internal/catch_random_number_generator.hpp>
#include <catch2/internal/catch_random_seed_generation.hpp>
+#include <catch2/internal/catch_uniform_floating_point_distribution.hpp>
#include <catch2/generators/catch_generators.hpp>
TEST_CASE("Our PCG implementation provides expected results for known seeds", "[rng]") {
@@ -60,3 +62,18 @@ TEST_CASE("Random seed generation accepts known methods", "[rng][seed]") {
REQUIRE_NOTHROW(Catch::generateRandomSeed(method));
}
+
+TEMPLATE_TEST_CASE("uniform_floating_point_distribution never returns infs from finite range",
+ "[rng][distribution][floating-point][approvals]", float, double) {
+ std::random_device rd{};
+ Catch::SimplePcg32 pcg( rd() );
+ Catch::uniform_floating_point_distribution<TestType> dist(
+ -std::numeric_limits<TestType>::max(),
+ std::numeric_limits<TestType>::max() );
+
+ for (size_t i = 0; i < 10'000; ++i) {
+ auto ret = dist( pcg );
+ REQUIRE_FALSE( std::isinf( ret ) );
+ REQUIRE_FALSE( std::isnan( ret ) );
+ }
+}