Update sampling test

Use faster and more robust RNG. Add better error tolerance.
This commit is contained in:
aherbert 2022-10-13 14:48:32 +01:00
parent fed7dd881b
commit 45e48f9d97
1 changed files with 6 additions and 6 deletions

View File

@ -148,8 +148,8 @@ public class EnumeratedIntegerDistributionTest {
@Test
public void testSample() {
final int n = 1000000;
final DiscreteDistribution.Sampler sampler
= testDistribution.createSampler(RandomSource.WELL_19937_C.create());
final DiscreteDistribution.Sampler sampler =
testDistribution.createSampler(RandomSource.XO_RO_SHI_RO_128_PP.create());
final int[] samples = AbstractIntegerDistribution.sample(n, sampler);
Assert.assertEquals(n, samples.length);
double sum = 0;
@ -158,10 +158,10 @@ public class EnumeratedIntegerDistributionTest {
sum += samples[i];
sumOfSquares += samples[i] * samples[i];
}
Assert.assertEquals(testDistribution.getMean(),
sum / n, 1e-2);
Assert.assertEquals(testDistribution.getVariance(),
sumOfSquares / n - JdkMath.pow(sum / n, 2), 1e-2);
final double mean = testDistribution.getMean();
Assert.assertEquals("Mean", mean, sum / n, mean * 1e-2);
final double var = testDistribution.getVariance();
Assert.assertEquals("Variance", var, sumOfSquares / n - JdkMath.pow(sum / n, 2), var * 1e-2);
}
@Test