Fix uniform_floating_point_distribution for unit ranges

This commit is contained in:
Martin Hořeňovský
2023-12-10 16:26:07 +01:00
parent ae4fe16b81
commit cb07ff9a7e
3 changed files with 23 additions and 3 deletions

View File

@@ -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 ) );
}
}