Skip to content

Commit f53b738

Browse files
Use aggregation test
Simple KS test use a fixed seed. There is then a new aggregation test. Signed-off-by: Alessandro Pellegrini <a.pellegrini@ing.uniroma2.it>
1 parent 988e948 commit f53b738

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

‎test/numerical.c‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,37 @@ static int random_range_test(_unused void *_)
120120

121121
return passed;
122122
}
123+
static int ks_aggregation_test(_unused void *_)
124+
{
125+
int runs = 10000;
126+
int failures = 0;
127+
for(int i = 0; i < runs; i++) {
128+
if(kolmogorov(1000, Random) != 0) {
129+
failures++;
130+
}
131+
}
132+
133+
/*
134+
* The KS threshold in kolmogorov() corresponds to alpha = 0.02.
135+
* Over 10,000 independent runs, the expected number of failures is 10000 * 0.02 = 200.
136+
* The standard deviation is sqrt(10000 * 0.02 * 0.98) = 14.
137+
* We accept failures within +/- 4 standard deviations: [144, 256].
138+
* Probability of false positive is practically 0 (< 0.00006).
139+
*/
140+
test_assert(failures >= 144 && failures <= 256);
141+
142+
return 0;
143+
}
123144

145+
extern uint64_t master_seed;
124146

125147
int main(void)
126148
{
149+
master_seed = 42;
127150
initialize_stream(0, &ctx);
128151

129152
test("Kolmogorov-Smirnov test on Random(&ctx)", aux_ks_test, NULL);
153+
test("Kolmogorov-Smirnov aggregated rejection rate test", ks_aggregation_test, NULL);
130154
test("Functional test on RandomRange()", random_range_test, NULL);
131155
test("Functional test on RandomRangeNonUniform()", random_range_non_uniform_test, NULL);
132156
}

0 commit comments

Comments
 (0)