Skip to content

Commit

Permalink
Update merge_tests.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
Tortar authored Apr 20, 2024
1 parent 9844987 commit ab35e3f
Showing 1 changed file with 34 additions and 34 deletions.
68 changes: 34 additions & 34 deletions test/merge_tests.jl
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@

@testset "merge tests" begin
rng = StableRNG(43)
iters = (1:2, 3:10)
reps = 10^5
size = 2
for (m1, m2) in [(algRSWRSKIP, algRSWRSKIP)]
res = zeros(Int, 10, 10)
for _ in 1:reps
s1 = ReservoirSample(rng, Int, size, m1)
s2 = ReservoirSample(rng, Int, size, m2)
s_all = (s1, s2)
for (s, it) in zip(s_all, iters)
for x in it
update!(s, x)
end
end
s_merged = merge(s1, s2)
res[value(s_merged)...] += 1
end
cases = m1 == algRSWRSKIP ? 10^size : factorial(10)/factorial(10-size)
rng = StableRNG(43)
iters = (1:2, 3:10)
reps = 10^5
size = 2
for (m1, m2) in [(algRSWRSKIP, algRSWRSKIP)]
res = zeros(Int, 10, 10)
for _ in 1:reps
s1 = ReservoirSample(rng, Int, size, m1)
s2 = ReservoirSample(rng, Int, size, m2)
s_all = (s1, s2)
for (s, it) in zip(s_all, iters)
for x in it
update!(s, x)
end
end
s_merged = merge(s1, s2)
res[value(s_merged)...] += 1
end
cases = m1 == algRSWRSKIP ? 10^size : factorial(10)/factorial(10-size)
ps_exact = [1/cases for _ in 1:cases]
count_est = vec(res)
chisq_test = ChisqTest(count_est, ps_exact)
@test pvalue(chisq_test) > 0.05
end
s1 = ReservoirSample(rng, Int, 2, algRSWRSKIP)
s2 = ReservoirSample(rng, Int, 2, algRSWRSKIP)
s_all = (s1, s2)
for (s, it) in zip(s_all, iters)
for x in it
update!(s, x)
end
end
@test length(merge!(s1, s2).value) == 2
s1 = ReservoirSample(rng, Int, algR)
s2 = ReservoirSample(rng, Int, algR)
update!(s1, 1)
update!(s2, 2)
@test merge!(s1, s2).value in (1, 2)
end
s1 = ReservoirSample(rng, Int, 2, algRSWRSKIP)
s2 = ReservoirSample(rng, Int, 2, algRSWRSKIP)
s_all = (s1, s2)
for (s, it) in zip(s_all, iters)
for x in it
update!(s, x)
end
end
@test length(merge!(s1, s2).value) == 2
s1 = ReservoirSample(rng, Int, algR)
s2 = ReservoirSample(rng, Int, algR)
update!(s1, 1)
update!(s2, 2)
@test merge!(s1, s2).value in (1, 2)
end

0 comments on commit ab35e3f

Please sign in to comment.