Skip to content

Commit

Permalink
More tests for single value sampling (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tortar authored Jan 14, 2024
1 parent 95293be commit 9a3a029
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion test/unweighted_sampling_single_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 9a3a029

Please sign in to comment.