Skip to content

Commit ba3ddad

Browse files
committed
rand_dist test: add degenerate tests
1 parent fa30cc1 commit ba3ddad

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

test/t-rand_dist-17.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,3 +256,45 @@ TEST_CASE("std compat") {
256256
test_deterministic_ints_neg50_100(rng, {80, 57, 74, 95, 22, -24, 5, 44, 92, -30});
257257
}
258258
}
259+
260+
#define uauto [[maybe_unused]] auto
261+
262+
TEST_CASE("degenerate") {
263+
SUBCASE("int") {
264+
q_test_rng<uint32_t> rng; // empty rng, should not be used
265+
SUBCASE("0 range") {
266+
itlib::uniform_uint_max_distribution<uint32_t> dist(0);
267+
for (uauto _ : rng.values) {
268+
CHECK(dist(rng) == 0);
269+
}
270+
}
271+
SUBCASE("fixed range") {
272+
itlib::uniform_int_distribution<int32_t> dist(42, 42);
273+
for (uauto _ : rng.values) {
274+
CHECK(dist(rng) == 42);
275+
}
276+
}
277+
}
278+
SUBCASE("real") {
279+
q_test_rng<uint32_t> rng{
280+
0u,
281+
1u << 10,
282+
1u << 23,
283+
1u << 24,
284+
(1u << 24) - 1, // almost 1
285+
1u << 23,
286+
};
287+
SUBCASE("0 range") {
288+
itlib::fast_uniform_real_distribution<float> dist(0, 0);
289+
for (uauto _ : rng.values) {
290+
CHECK(dist(rng) == 0);
291+
}
292+
}
293+
SUBCASE("fixed range") {
294+
itlib::fast_uniform_real_distribution<float> dist(3.14f, 3.14f);
295+
for (uauto _ : rng.values) {
296+
CHECK(dist(rng) == 3.14f);
297+
}
298+
}
299+
}
300+
}

0 commit comments

Comments
 (0)