Skip to content

Commit

Permalink
Dropped useless tests; added KS test for uniformity of nextDouble. JI…
Browse files Browse the repository at this point in the history
…RA: MATH-1317.
  • Loading branch information
psteitz committed Jan 12, 2016
1 parent d749b2e commit 4742149
Showing 1 changed file with 11 additions and 23 deletions.
Expand Up @@ -19,16 +19,16 @@
import java.util.Arrays;

import org.apache.commons.math4.TestUtils;
import org.apache.commons.math4.distribution.RealDistribution;
import org.apache.commons.math4.distribution.UniformRealDistribution;
import org.apache.commons.math4.exception.MathIllegalArgumentException;
import org.apache.commons.math4.random.RandomDataGenerator;
import org.apache.commons.math4.random.RandomGenerator;
import org.apache.commons.math4.stat.Frequency;
import org.apache.commons.math4.stat.descriptive.SummaryStatistics;
import org.apache.commons.math4.stat.inference.KolmogorovSmirnovTest;
import org.apache.commons.math4.util.FastMath;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.Ignore;
import org.junit.Test;

/**
* Base class for RandomGenerator tests.
Expand Down Expand Up @@ -247,28 +247,16 @@ public void testNextFloatDirect() {
}

@Test
public void testDoubleDirect() {
SummaryStatistics sample = new SummaryStatistics();
final int N = 10000;
for (int i = 0; i < N; ++i) {
sample.addValue(generator.nextDouble());
public void testNextDouble() {
final double[] sample = new double[1000];
for (int i = 0; i < sample.length; i++) {
sample[i] = generator.nextDouble();
}
Assert.assertEquals(0.5, sample.getMean(), 0.01);
Assert.assertEquals(1.0 / (2.0 * FastMath.sqrt(3.0)),
sample.getStandardDeviation(), 0.01);
final RealDistribution uniformDistribution = new UniformRealDistribution(0,1);
final KolmogorovSmirnovTest ks = new KolmogorovSmirnovTest();
Assert.assertFalse(ks.kolmogorovSmirnovTest(uniformDistribution, sample, .01));
}

@Test
public void testFloatDirect() {
SummaryStatistics sample = new SummaryStatistics();
final int N = 10000;
for (int i = 0; i < N; ++i) {
sample.addValue(generator.nextFloat());
}
Assert.assertEquals(0.5, sample.getMean(), 0.01);
Assert.assertEquals(1.0 / (2.0 * FastMath.sqrt(3.0)),
sample.getStandardDeviation(), 0.01);
}

@Test(expected=MathIllegalArgumentException.class)
public void testNextIntPrecondition1() {
Expand Down

0 comments on commit 4742149

Please sign in to comment.