From 9baffac1a93e55969c392922691a0f3a24ed647f Mon Sep 17 00:00:00 2001 From: Tortar <68152031+Tortar@users.noreply.github.com> Date: Sun, 14 Jan 2024 20:41:46 +0100 Subject: [PATCH] More tests for single value sampling --- test/unweighted_sampling_single_tests.jl | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/test/unweighted_sampling_single_tests.jl b/test/unweighted_sampling_single_tests.jl index f02a190..0ba400f 100644 --- a/test/unweighted_sampling_single_tests.jl +++ b/test/unweighted_sampling_single_tests.jl @@ -3,6 +3,26 @@ a, b = 1, 100 z = itsample(a:b) @test a <= z <= b - z = itsample(Iterators.filter(x -> x != 101, a:b+1)) + z = itsample(Iterators.filter(x -> x != b+1, a:b+1)) @test a <= z <= b + rng = StableRNG(43) + iters = (a:b, Iterators.filter(x -> x != b + 1, a:b+1)) + for it in iters + reps = 10000 + dict_res = Dict{Int, Int}() + for _ in 1:reps + s = itsample(rng, it) + if s in keys(dict_res) + dict_res[s] += 1 + else + dict_res[s] = 1 + end + end + cases = 100 + ps_exact = [1/cases for _ in 1:cases] + count_est = collect(values(dict_res)) + + chisq_test = ChisqTest(count_est, ps_exact) + @test pvalue(chisq_test) > 0.05 + end end