Skip to content

Commit 44e7366

Browse files
authored
Create sequential_sampling_tests.jl
1 parent af2c86b commit 44e7366

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

test/sequential_sampling_tests.jl

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
2+
@testset "SequentialSampler tests" begin
3+
rng = StableRNG(42)
4+
N = 10
5+
n = 2
6+
reps = 10000
7+
8+
for alg in (AlgD(), AlgHiddenShuffle())
9+
s = SequentialSampler(rng, n, N, alg)
10+
out = collect(s)
11+
@test length(out) == n
12+
@test issorted(out)
13+
@test allunique(out)
14+
@test all(1 .<= out .<= N)
15+
16+
dict_res = Dict{Vector{Int}, Int}()
17+
for _ in 1:reps
18+
s = SequentialSampler(rng, n, N, alg)
19+
out = collect(s)
20+
dict_res[out] = get(dict_res, out, 0) + 1
21+
end
22+
23+
valid_couples = 0
24+
for i in 1:N, j in i+1:N
25+
valid_couples += 1
26+
end
27+
28+
count_est = Int[]
29+
for i in 1:N, j in i+1:N
30+
push!(count_est, get(dict_res, [i, j], 0))
31+
end
32+
33+
chisq_test = ChisqTest(count_est, fill(1/valid_couples, valid_couples))
34+
@test pvalue(chisq_test) > 0.05
35+
end
36+
37+
s = SequentialSampler(rng, n, N, AlgORDSWR())
38+
out = collect(s)
39+
@test length(out) == n
40+
@test issorted(out)
41+
@test all(1 .<= out .<= N)
42+
43+
dict_res = Dict{Vector{Int}, Int}()
44+
for _ in 1:reps
45+
s = SequentialSampler(rng, n, N, AlgORDSWR())
46+
out = collect(s)
47+
dict_res[out] = get(dict_res, out, 0) + 1
48+
end
49+
50+
count_est = Int[]
51+
ps_exact = Float64[]
52+
53+
for i in 1:N, j in i:N
54+
push!(count_est, get(dict_res, [i, j], 0))
55+
if i == j
56+
push!(ps_exact, 1/(N^2))
57+
else
58+
push!(ps_exact, 2/(N^2))
59+
end
60+
end
61+
62+
chisq_test = ChisqTest(count_est, ps_exact)
63+
@test pvalue(chisq_test) > 0.05
64+
end

0 commit comments

Comments
 (0)