Skip to content
Permalink
Browse files
Compute p-value for the chi square test once.
Use String.format for the assertion message.
  • Loading branch information
aherbert committed Mar 1, 2022
1 parent bd30c3b commit 52a5b802ca01d1b5924da3939e1392413939cd96
Showing 1 changed file with 8 additions and 5 deletions.
@@ -85,8 +85,9 @@ private static void check(long sampleSize,
}
}

if (chiSquareTest.chiSquareTest(expected, observed, 0.01)) {
failedStat.add(chiSquareTest.chiSquareTest(expected, observed));
final double p = chiSquareTest.chiSquareTest(expected, observed);
if (p < 0.01) {
failedStat.add(p);
++numFailures;
}
}
@@ -104,9 +105,11 @@ private static void check(long sampleSize,
// 3 0.0016

if (numFailures > 3) { // Test will fail with 0.16% probability
Assertions.fail(sampler + ": Too many failures for sample size = " + sampleSize +
" (" + numFailures + " out of " + numTests + " tests failed, " +
"chi2=" + Arrays.toString(failedStat.toArray(new Double[0])));
Assertions.fail(String.format(
"%s: Too many failures for sample size = %d " +
" (%d out of %d tests failed, chi2=%s",
sampler, sampleSize, numFailures, numTests,
Arrays.toString(failedStat.toArray(new Double[0]))));
}
}
}

0 comments on commit 52a5b80

Please sign in to comment.