diff options
| author | Andreas Stenmark <astenmark@users.noreply.github.com> | 2025-11-30 21:46:26 +0100 |
|---|---|---|
| committer | Andreas Stenmark <astenmark@users.noreply.github.com> | 2025-11-30 21:46:26 +0100 |
| commit | ad11d3bea03eeb74e43fc518321943db7341e7be (patch) | |
| tree | 73c6cd8f8b59e80f232329be5fdf1bc4b7f09bc7 /tests | |
| parent | 679d306d0ff0ff9ac451a23ee50d7e44807d5aa6 (diff) | |
Fix #5978: choice_bit_set respects bit_set domain
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/core/math/rand/test_core_math_rand.odin | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/core/math/rand/test_core_math_rand.odin b/tests/core/math/rand/test_core_math_rand.odin index 814a1b9f8..19f844086 100644 --- a/tests/core/math/rand/test_core_math_rand.odin +++ b/tests/core/math/rand/test_core_math_rand.odin @@ -78,6 +78,24 @@ rand_issue_5881 :: proc(t:^testing.T, rng: Generator) { expect_quaternion_sign_uniformity(t, rng, 200_000) } +@(test) +test_issue_5978 :: proc(t:^testing.T) { + // Tests issue #5978 https://github.com/odin-lang/Odin/issues/5978 + + s := bit_set[1 ..= 5]{1, 5} + + cases := []struct { + seed: u64, + expected: int, + }{ {13, 1}, {27, 5} }; + + for c in cases { + rand.reset(c.seed); + i, _ := rand.choice_bit_set(s); + testing.expectf(t, i == c.expected, "choice_bit_set returned %v with seed %v, expected %v", i, c.seed, c.expected) + } +} + // Helper: compute chi-square statistic for counts vs equal-expected across k bins @(private = "file") chi_square_equal :: proc(counts: []int) -> f64 { |