You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ah...@apache.org on 2022/10/13 15:53:09 UTC
[commons-math] 04/11: Update sampling test
This is an automated email from the ASF dual-hosted git repository.
aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-math.git
commit 45e48f9d97d173a66e4d6e0b0c7bd5b641f5deb1
Author: aherbert <ah...@apache.org>
AuthorDate: Thu Oct 13 14:48:32 2022 +0100
Update sampling test
Use faster and more robust RNG. Add better error tolerance.
---
.../distribution/EnumeratedIntegerDistributionTest.java | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/distribution/EnumeratedIntegerDistributionTest.java b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/distribution/EnumeratedIntegerDistributionTest.java
index b3d948a9f..f2b5075d5 100644
--- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/distribution/EnumeratedIntegerDistributionTest.java
+++ b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/distribution/EnumeratedIntegerDistributionTest.java
@@ -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