|
76 | 76 | @test nobs(rs) == 10 |
77 | 77 |
|
78 | 78 | weight2(el) = el <= 5 ? 1.0 : 2.0 |
79 | | - rng = StableRNG(41) |
80 | | - iters = (a:b, Iterators.filter(x -> x != b+1, a:b+1)) |
| 79 | + weight3(el) = el <= 5 ? 1.0 : 2.0 |
| 80 | + wfuncs = (weight2, weight3) |
| 81 | + rngs = (StableRNG(41), StableRNG(42)) |
| 82 | + iters = (a:b, Iterators.filter(x -> x != b+1, a:b+1), (a:floor(Int, b/2), (floor(Int, b/2)+1):b)) |
81 | 83 | sizes = (1, 2) |
82 | 84 | for it in iters |
83 | 85 | for size in sizes |
84 | 86 | reps = 10^(size+3) |
85 | 87 | dict_res = Dict{Vector, Int}() |
86 | 88 | for _ in 1:reps |
87 | | - s = shuffle!(rng, itsample(rng, it, weight2, size, method; ordered=ordered)) |
| 89 | + if typeof(it) <: Tuple |
| 90 | + if method == AlgWRSWRSKIP() && ordered == false |
| 91 | + s = shuffle!(rngs[1], itsample(rngs, it, wfuncs, size)) |
| 92 | + else |
| 93 | + break |
| 94 | + end |
| 95 | + else |
| 96 | + s = shuffle!(rngs[1], itsample(rngs[1], it, wfuncs[1], size, method; ordered=ordered)) |
| 97 | + end |
88 | 98 | if s in keys(dict_res) |
89 | 99 | dict_res[s] += 1 |
90 | 100 | else |
91 | 101 | dict_res[s] = 1 |
92 | 102 | end |
93 | 103 | end |
94 | | - cases = method == AlgWRSWRSKIP() ? 10^size : factorial(10)/factorial(10-size) |
95 | | - pairs_dict = collect(pairs(dict_res)) |
96 | | - if method == AlgWRSWRSKIP() |
97 | | - ps_exact = [prob_replace(k) for (k, v) in pairs_dict] |
98 | | - else |
99 | | - ps_exact = [prob_no_replace(k) for (k, v) in pairs_dict if length(unique(k)) == size] |
| 104 | + if !(typeof(it) <: Tuple) || (method == AlgWRSWRSKIP() && ordered == false) |
| 105 | + cases = method == AlgWRSWRSKIP() ? 10^size : factorial(10)/factorial(10-size) |
| 106 | + pairs_dict = collect(pairs(dict_res)) |
| 107 | + if method == AlgWRSWRSKIP() |
| 108 | + ps_exact = [prob_replace(k) for (k, v) in pairs_dict] |
| 109 | + else |
| 110 | + ps_exact = [prob_no_replace(k) for (k, v) in pairs_dict if length(unique(k)) == size] |
| 111 | + end |
| 112 | + count_est = [v for (k, v) in pairs_dict] |
| 113 | + chisq_test = ChisqTest(count_est, ps_exact) |
| 114 | + @test pvalue(chisq_test) > 0.05 |
100 | 115 | end |
101 | | - count_est = [v for (k, v) in pairs_dict] |
102 | | - chisq_test = ChisqTest(count_est, ps_exact) |
103 | | - @test pvalue(chisq_test) > 0.05 |
104 | 116 | end |
105 | 117 | end |
106 | 118 | end |
|
0 commit comments