diff options
| author | Martin Hořeňovský | 2023-11-20 15:16:50 +0100 |
|---|---|---|
| committer | Martin Hořeňovský | 2023-12-10 18:44:12 +0100 |
| commit | ab1b079e4deb159a6f56c9168031876a697a7d2c (patch) | |
| tree | bfcac1219d4bc50f970e6f5a4efb0c10bec23684 /tests/SelfTest/IntrospectiveTests/RandomNumberGeneration.tests.cpp | |
| parent | d139b4ff7cd8823923e8616e8fef954e09e46322 (diff) | |
| download | catch3-ab1b079e4deb159a6f56c9168031876a697a7d2c.tar.gz | |
Add uniform_floating_point_distribution
Diffstat (limited to 'tests/SelfTest/IntrospectiveTests/RandomNumberGeneration.tests.cpp')
| -rw-r--r-- | tests/SelfTest/IntrospectiveTests/RandomNumberGeneration.tests.cpp | 17 |
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 ) ); + } +} |