http://git-wip-us.apache.org/repos/asf/commons-math/blob/7550cb46/src/test/java/org/apache/commons/math4/random/RandomDataGeneratorTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math4/random/RandomDataGeneratorTest.java b/src/test/java/org/apache/commons/math4/random/RandomDataGeneratorTest.java deleted file mode 100644 index d7c4906..0000000 --- a/src/test/java/org/apache/commons/math4/random/RandomDataGeneratorTest.java +++ /dev/null @@ -1,1212 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.math4.random; - -import java.text.DecimalFormat; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; - -import org.apache.commons.math4.Retry; -import org.apache.commons.math4.RetryRunner; -import org.apache.commons.math4.TestUtils; -import org.apache.commons.math4.distribution.BetaDistribution; -import org.apache.commons.math4.distribution.BinomialDistribution; -import org.apache.commons.math4.distribution.BinomialDistributionTest; -import org.apache.commons.math4.distribution.CauchyDistribution; -import org.apache.commons.math4.distribution.ChiSquaredDistribution; -import org.apache.commons.math4.distribution.ExponentialDistribution; -import org.apache.commons.math4.distribution.FDistribution; -import org.apache.commons.math4.distribution.GammaDistribution; -import org.apache.commons.math4.distribution.HypergeometricDistribution; -import org.apache.commons.math4.distribution.HypergeometricDistributionTest; -import org.apache.commons.math4.distribution.NormalDistribution; -import org.apache.commons.math4.distribution.PascalDistribution; -import org.apache.commons.math4.distribution.PascalDistributionTest; -import org.apache.commons.math4.distribution.PoissonDistribution; -import org.apache.commons.math4.distribution.TDistribution; -import org.apache.commons.math4.distribution.WeibullDistribution; -import org.apache.commons.math4.distribution.ZipfDistribution; -import org.apache.commons.math4.distribution.ZipfDistributionTest; -import org.apache.commons.math4.exception.MathIllegalArgumentException; -import org.apache.commons.math4.random.RandomDataGenerator; -import org.apache.commons.math4.stat.Frequency; -import org.apache.commons.math4.stat.inference.ChiSquareTest; -import org.apache.commons.math4.util.FastMath; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; - -/** - * Test cases for the RandomDataGenerator class. - * - */ -@RunWith(RetryRunner.class) -public class RandomDataGeneratorTest { - - public RandomDataGeneratorTest() { - randomData = new RandomDataGenerator(); - randomData.reSeed(1000); - } - - protected final long smallSampleSize = 1000; - protected final double[] expected = { 250, 250, 250, 250 }; - protected final int largeSampleSize = 10000; - private final String[] hex = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", - "a", "b", "c", "d", "e", "f" }; - protected RandomDataGenerator randomData = null; - protected final ChiSquareTest testStatistic = new ChiSquareTest(); - - @Test - public void testNextIntExtremeValues() { - int x = randomData.nextInt(Integer.MIN_VALUE, Integer.MAX_VALUE); - int y = randomData.nextInt(Integer.MIN_VALUE, Integer.MAX_VALUE); - Assert.assertFalse(x == y); - } - - @Test - public void testNextLongExtremeValues() { - long x = randomData.nextLong(Long.MIN_VALUE, Long.MAX_VALUE); - long y = randomData.nextLong(Long.MIN_VALUE, Long.MAX_VALUE); - Assert.assertFalse(x == y); - } - - @Test - public void testNextUniformExtremeValues() { - double x = randomData.nextUniform(-Double.MAX_VALUE, Double.MAX_VALUE); - double y = randomData.nextUniform(-Double.MAX_VALUE, Double.MAX_VALUE); - Assert.assertFalse(x == y); - Assert.assertFalse(Double.isNaN(x)); - Assert.assertFalse(Double.isNaN(y)); - Assert.assertFalse(Double.isInfinite(x)); - Assert.assertFalse(Double.isInfinite(y)); - } - - @Test - public void testNextIntIAE() { - try { - randomData.nextInt(4, 3); - Assert.fail("MathIllegalArgumentException expected"); - } catch (MathIllegalArgumentException ex) { - // ignored - } - } - - @Test - public void testNextIntNegativeToPositiveRange() { - for (int i = 0; i < 5; i++) { - checkNextIntUniform(-3, 5); - checkNextIntUniform(-3, 6); - } - } - - @Test - public void testNextIntNegativeRange() { - for (int i = 0; i < 5; i++) { - checkNextIntUniform(-7, -4); - checkNextIntUniform(-15, -2); - checkNextIntUniform(Integer.MIN_VALUE + 1, Integer.MIN_VALUE + 12); - } - } - - @Test - public void testNextIntPositiveRange() { - for (int i = 0; i < 5; i++) { - checkNextIntUniform(0, 3); - checkNextIntUniform(2, 12); - checkNextIntUniform(1,2); - checkNextIntUniform(Integer.MAX_VALUE - 12, Integer.MAX_VALUE - 1); - } - } - - private void checkNextIntUniform(int min, int max) { - final Frequency freq = new Frequency(); - for (int i = 0; i < smallSampleSize; i++) { - final int value = randomData.nextInt(min, max); - Assert.assertTrue("nextInt range", (value >= min) && (value <= max)); - freq.addValue(value); - } - final int len = max - min + 1; - final long[] observed = new long[len]; - for (int i = 0; i < len; i++) { - observed[i] = freq.getCount(min + i); - } - final double[] expected = new double[len]; - for (int i = 0; i < len; i++) { - expected[i] = 1d / len; - } - - TestUtils.assertChiSquareAccept(expected, observed, 0.001); - } - - @Test - public void testNextIntWideRange() { - int lower = -0x6543210F; - int upper = 0x456789AB; - int max = Integer.MIN_VALUE; - int min = Integer.MAX_VALUE; - for (int i = 0; i < 1000000; ++i) { - int r = randomData.nextInt(lower, upper); - max = FastMath.max(max, r); - min = FastMath.min(min, r); - Assert.assertTrue(r >= lower); - Assert.assertTrue(r <= upper); - } - double ratio = (((double) max) - ((double) min)) / - (((double) upper) - ((double) lower)); - Assert.assertTrue(ratio > 0.99999); - } - - @Test - public void testNextLongIAE() { - try { - randomData.nextLong(4, 3); - Assert.fail("MathIllegalArgumentException expected"); - } catch (MathIllegalArgumentException ex) { - // ignored - } - } - - @Test - public void testNextLongNegativeToPositiveRange() { - for (int i = 0; i < 5; i++) { - checkNextLongUniform(-3, 5); - checkNextLongUniform(-3, 6); - } - } - - @Test - public void testNextLongNegativeRange() { - for (int i = 0; i < 5; i++) { - checkNextLongUniform(-7, -4); - checkNextLongUniform(-15, -2); - checkNextLongUniform(Long.MIN_VALUE + 1, Long.MIN_VALUE + 12); - } - } - - @Test - public void testNextLongPositiveRange() { - for (int i = 0; i < 5; i++) { - checkNextLongUniform(0, 3); - checkNextLongUniform(2, 12); - checkNextLongUniform(Long.MAX_VALUE - 12, Long.MAX_VALUE - 1); - } - } - - private void checkNextLongUniform(long min, long max) { - final Frequency freq = new Frequency(); - for (int i = 0; i < smallSampleSize; i++) { - final long value = randomData.nextLong(min, max); - Assert.assertTrue("nextLong range: " + value + " " + min + " " + max, - (value >= min) && (value <= max)); - freq.addValue(value); - } - final int len = ((int) (max - min)) + 1; - final long[] observed = new long[len]; - for (int i = 0; i < len; i++) { - observed[i] = freq.getCount(min + i); - } - final double[] expected = new double[len]; - for (int i = 0; i < len; i++) { - expected[i] = 1d / len; - } - - TestUtils.assertChiSquareAccept(expected, observed, 0.01); - } - - @Test - public void testNextLongWideRange() { - long lower = -0x6543210FEDCBA987L; - long upper = 0x456789ABCDEF0123L; - long max = Long.MIN_VALUE; - long min = Long.MAX_VALUE; - for (int i = 0; i < 10000000; ++i) { - long r = randomData.nextLong(lower, upper); - max = FastMath.max(max, r); - min = FastMath.min(min, r); - Assert.assertTrue(r >= lower); - Assert.assertTrue(r <= upper); - } - double ratio = (((double) max) - ((double) min)) / - (((double) upper) - ((double) lower)); - Assert.assertTrue(ratio > 0.99999); - } - - @Test - public void testNextSecureLongIAE() { - try { - randomData.nextSecureLong(4, 3); - Assert.fail("MathIllegalArgumentException expected"); - } catch (MathIllegalArgumentException ex) { - // ignored - } - } - - @Test - @Retry(3) - public void testNextSecureLongNegativeToPositiveRange() { - for (int i = 0; i < 5; i++) { - checkNextSecureLongUniform(-3, 5); - checkNextSecureLongUniform(-3, 6); - } - } - - @Test - @Retry(3) - public void testNextSecureLongNegativeRange() { - for (int i = 0; i < 5; i++) { - checkNextSecureLongUniform(-7, -4); - checkNextSecureLongUniform(-15, -2); - } - } - - @Test - @Retry(3) - public void testNextSecureLongPositiveRange() { - for (int i = 0; i < 5; i++) { - checkNextSecureLongUniform(0, 3); - checkNextSecureLongUniform(2, 12); - } - } - - private void checkNextSecureLongUniform(int min, int max) { - final Frequency freq = new Frequency(); - for (int i = 0; i < smallSampleSize; i++) { - final long value = randomData.nextSecureLong(min, max); - Assert.assertTrue("nextLong range", (value >= min) && (value <= max)); - freq.addValue(value); - } - final int len = max - min + 1; - final long[] observed = new long[len]; - for (int i = 0; i < len; i++) { - observed[i] = freq.getCount(min + i); - } - final double[] expected = new double[len]; - for (int i = 0; i < len; i++) { - expected[i] = 1d / len; - } - - TestUtils.assertChiSquareAccept(expected, observed, 0.0001); - } - - @Test - public void testNextSecureIntIAE() { - try { - randomData.nextSecureInt(4, 3); - Assert.fail("MathIllegalArgumentException expected"); - } catch (MathIllegalArgumentException ex) { - // ignored - } - } - - @Test - @Retry(3) - public void testNextSecureIntNegativeToPositiveRange() { - for (int i = 0; i < 5; i++) { - checkNextSecureIntUniform(-3, 5); - checkNextSecureIntUniform(-3, 6); - } - } - - @Test - @Retry(3) - public void testNextSecureIntNegativeRange() { - for (int i = 0; i < 5; i++) { - checkNextSecureIntUniform(-7, -4); - checkNextSecureIntUniform(-15, -2); - } - } - - @Test - @Retry(3) - public void testNextSecureIntPositiveRange() { - for (int i = 0; i < 5; i++) { - checkNextSecureIntUniform(0, 3); - checkNextSecureIntUniform(2, 12); - } - } - - private void checkNextSecureIntUniform(int min, int max) { - final Frequency freq = new Frequency(); - for (int i = 0; i < smallSampleSize; i++) { - final int value = randomData.nextSecureInt(min, max); - Assert.assertTrue("nextInt range", (value >= min) && (value <= max)); - freq.addValue(value); - } - final int len = max - min + 1; - final long[] observed = new long[len]; - for (int i = 0; i < len; i++) { - observed[i] = freq.getCount(min + i); - } - final double[] expected = new double[len]; - for (int i = 0; i < len; i++) { - expected[i] = 1d / len; - } - - TestUtils.assertChiSquareAccept(expected, observed, 0.0001); - } - - - - /** - * Make sure that empirical distribution of random Poisson(4)'s has P(X <= - * 5) close to actual cumulative Poisson probability and that nextPoisson - * fails when mean is non-positive. - */ - @Test - public void testNextPoisson() { - try { - randomData.nextPoisson(0); - Assert.fail("zero mean -- expecting MathIllegalArgumentException"); - } catch (MathIllegalArgumentException ex) { - // ignored - } - try { - randomData.nextPoisson(-1); - Assert.fail("negative mean supplied -- MathIllegalArgumentException expected"); - } catch (MathIllegalArgumentException ex) { - // ignored - } - try { - randomData.nextPoisson(0); - Assert.fail("0 mean supplied -- MathIllegalArgumentException expected"); - } catch (MathIllegalArgumentException ex) { - // ignored - } - - final double mean = 4.0d; - final int len = 5; - PoissonDistribution poissonDistribution = new PoissonDistribution(mean); - Frequency f = new Frequency(); - randomData.reSeed(1000); - for (int i = 0; i < largeSampleSize; i++) { - f.addValue(randomData.nextPoisson(mean)); - } - final long[] observed = new long[len]; - for (int i = 0; i < len; i++) { - observed[i] = f.getCount(i + 1); - } - final double[] expected = new double[len]; - for (int i = 0; i < len; i++) { - expected[i] = poissonDistribution.probability(i + 1) * largeSampleSize; - } - - TestUtils.assertChiSquareAccept(expected, observed, 0.0001); - } - - @Test - public void testNextPoissonConsistency() { - - // Small integral means - for (int i = 1; i < 100; i++) { - checkNextPoissonConsistency(i); - } - // non-integer means - for (int i = 1; i < 10; i++) { - checkNextPoissonConsistency(randomData.nextUniform(1, 1000)); - } - // large means - for (int i = 1; i < 10; i++) { - checkNextPoissonConsistency(randomData.nextUniform(1000, 10000)); - } - } - - /** - * Verifies that nextPoisson(mean) generates an empirical distribution of values - * consistent with PoissonDistributionImpl by generating 1000 values, computing a - * grouped frequency distribution of the observed values and comparing this distribution - * to the corresponding expected distribution computed using PoissonDistributionImpl. - * Uses ChiSquare test of goodness of fit to evaluate the null hypothesis that the - * distributions are the same. If the null hypothesis can be rejected with confidence - * 1 - alpha, the check fails. - */ - public void checkNextPoissonConsistency(double mean) { - // Generate sample values - final int sampleSize = 1000; // Number of deviates to generate - final int minExpectedCount = 7; // Minimum size of expected bin count - long maxObservedValue = 0; - final double alpha = 0.001; // Probability of false failure - Frequency frequency = new Frequency(); - for (int i = 0; i < sampleSize; i++) { - long value = randomData.nextPoisson(mean); - if (value > maxObservedValue) { - maxObservedValue = value; - } - frequency.addValue(value); - } - - /* - * Set up bins for chi-square test. - * Ensure expected counts are all at least minExpectedCount. - * Start with upper and lower tail bins. - * Lower bin = [0, lower); Upper bin = [upper, +inf). - */ - PoissonDistribution poissonDistribution = new PoissonDistribution(mean); - int lower = 1; - while (poissonDistribution.cumulativeProbability(lower - 1) * sampleSize < minExpectedCount) { - lower++; - } - int upper = (int) (5 * mean); // Even for mean = 1, not much mass beyond 5 - while ((1 - poissonDistribution.cumulativeProbability(upper - 1)) * sampleSize < minExpectedCount) { - upper--; - } - - // Set bin width for interior bins. For poisson, only need to look at end bins. - int binWidth = 0; - boolean widthSufficient = false; - double lowerBinMass = 0; - double upperBinMass = 0; - while (!widthSufficient) { - binWidth++; - lowerBinMass = poissonDistribution.probability(lower - 1, lower + binWidth - 1); - upperBinMass = poissonDistribution.probability(upper - binWidth - 1, upper - 1); - widthSufficient = FastMath.min(lowerBinMass, upperBinMass) * sampleSize >= minExpectedCount; - } - - /* - * Determine interior bin bounds. Bins are - * [1, lower = binBounds[0]), [lower, binBounds[1]), [binBounds[1], binBounds[2]), ... , - * [binBounds[binCount - 2], upper = binBounds[binCount - 1]), [upper, +inf) - * - */ - List<Integer> binBounds = new ArrayList<Integer>(); - binBounds.add(lower); - int bound = lower + binWidth; - while (bound < upper - binWidth) { - binBounds.add(bound); - bound += binWidth; - } - binBounds.add(upper); // The size of bin [binBounds[binCount - 2], upper) satisfies binWidth <= size < 2*binWidth. - - // Compute observed and expected bin counts - final int binCount = binBounds.size() + 1; - long[] observed = new long[binCount]; - double[] expected = new double[binCount]; - - // Bottom bin - observed[0] = 0; - for (int i = 0; i < lower; i++) { - observed[0] += frequency.getCount(i); - } - expected[0] = poissonDistribution.cumulativeProbability(lower - 1) * sampleSize; - - // Top bin - observed[binCount - 1] = 0; - for (int i = upper; i <= maxObservedValue; i++) { - observed[binCount - 1] += frequency.getCount(i); - } - expected[binCount - 1] = (1 - poissonDistribution.cumulativeProbability(upper - 1)) * sampleSize; - - // Interior bins - for (int i = 1; i < binCount - 1; i++) { - observed[i] = 0; - for (int j = binBounds.get(i - 1); j < binBounds.get(i); j++) { - observed[i] += frequency.getCount(j); - } // Expected count is (mass in [binBounds[i-1], binBounds[i])) * sampleSize - expected[i] = (poissonDistribution.cumulativeProbability(binBounds.get(i) - 1) - - poissonDistribution.cumulativeProbability(binBounds.get(i - 1) -1)) * sampleSize; - } - - // Use chisquare test to verify that generated values are poisson(mean)-distributed - ChiSquareTest chiSquareTest = new ChiSquareTest(); - // Fail if we can reject null hypothesis that distributions are the same - if (chiSquareTest.chiSquareTest(expected, observed, alpha)) { - StringBuilder msgBuffer = new StringBuilder(); - DecimalFormat df = new DecimalFormat("#.##"); - msgBuffer.append("Chisquare test failed for mean = "); - msgBuffer.append(mean); - msgBuffer.append(" p-value = "); - msgBuffer.append(chiSquareTest.chiSquareTest(expected, observed)); - msgBuffer.append(" chisquare statistic = "); - msgBuffer.append(chiSquareTest.chiSquare(expected, observed)); - msgBuffer.append(". \n"); - msgBuffer.append("bin\t\texpected\tobserved\n"); - for (int i = 0; i < expected.length; i++) { - msgBuffer.append("["); - msgBuffer.append(i == 0 ? 1: binBounds.get(i - 1)); - msgBuffer.append(","); - msgBuffer.append(i == binBounds.size() ? "inf": binBounds.get(i)); - msgBuffer.append(")"); - msgBuffer.append("\t\t"); - msgBuffer.append(df.format(expected[i])); - msgBuffer.append("\t\t"); - msgBuffer.append(observed[i]); - msgBuffer.append("\n"); - } - msgBuffer.append("This test can fail randomly due to sampling error with probability "); - msgBuffer.append(alpha); - msgBuffer.append("."); - Assert.fail(msgBuffer.toString()); - } - } - - /** test dispersion and failure modes for nextHex() */ - @Test - public void testNextHex() { - try { - randomData.nextHexString(-1); - Assert.fail("negative length supplied -- MathIllegalArgumentException expected"); - } catch (MathIllegalArgumentException ex) { - // ignored - } - try { - randomData.nextHexString(0); - Assert.fail("zero length supplied -- MathIllegalArgumentException expected"); - } catch (MathIllegalArgumentException ex) { - // ignored - } - String hexString = randomData.nextHexString(3); - if (hexString.length() != 3) { - Assert.fail("incorrect length for generated string"); - } - hexString = randomData.nextHexString(1); - if (hexString.length() != 1) { - Assert.fail("incorrect length for generated string"); - } - try { - hexString = randomData.nextHexString(0); - Assert.fail("zero length requested -- expecting MathIllegalArgumentException"); - } catch (MathIllegalArgumentException ex) { - // ignored - } - Frequency f = new Frequency(); - for (int i = 0; i < smallSampleSize; i++) { - hexString = randomData.nextHexString(100); - if (hexString.length() != 100) { - Assert.fail("incorrect length for generated string"); - } - for (int j = 0; j < hexString.length(); j++) { - f.addValue(hexString.substring(j, j + 1)); - } - } - double[] expected = new double[16]; - long[] observed = new long[16]; - for (int i = 0; i < 16; i++) { - expected[i] = (double) smallSampleSize * 100 / 16; - observed[i] = f.getCount(hex[i]); - } - TestUtils.assertChiSquareAccept(expected, observed, 0.001); - } - - /** test dispersion and failure modes for nextHex() */ - @Test - @Retry(3) - public void testNextSecureHex() { - try { - randomData.nextSecureHexString(-1); - Assert.fail("negative length -- MathIllegalArgumentException expected"); - } catch (MathIllegalArgumentException ex) { - // ignored - } - try { - randomData.nextSecureHexString(0); - Assert.fail("zero length -- MathIllegalArgumentException expected"); - } catch (MathIllegalArgumentException ex) { - // ignored - } - String hexString = randomData.nextSecureHexString(3); - if (hexString.length() != 3) { - Assert.fail("incorrect length for generated string"); - } - hexString = randomData.nextSecureHexString(1); - if (hexString.length() != 1) { - Assert.fail("incorrect length for generated string"); - } - try { - hexString = randomData.nextSecureHexString(0); - Assert.fail("zero length requested -- expecting MathIllegalArgumentException"); - } catch (MathIllegalArgumentException ex) { - // ignored - } - Frequency f = new Frequency(); - for (int i = 0; i < smallSampleSize; i++) { - hexString = randomData.nextSecureHexString(100); - if (hexString.length() != 100) { - Assert.fail("incorrect length for generated string"); - } - for (int j = 0; j < hexString.length(); j++) { - f.addValue(hexString.substring(j, j + 1)); - } - } - double[] expected = new double[16]; - long[] observed = new long[16]; - for (int i = 0; i < 16; i++) { - expected[i] = (double) smallSampleSize * 100 / 16; - observed[i] = f.getCount(hex[i]); - } - TestUtils.assertChiSquareAccept(expected, observed, 0.001); - } - - @Test - public void testNextUniformIAE() { - try { - randomData.nextUniform(4, 3); - Assert.fail("MathIllegalArgumentException expected"); - } catch (MathIllegalArgumentException ex) { - // ignored - } - try { - randomData.nextUniform(0, Double.POSITIVE_INFINITY); - Assert.fail("MathIllegalArgumentException expected"); - } catch (MathIllegalArgumentException ex) { - // ignored - } - try { - randomData.nextUniform(Double.NEGATIVE_INFINITY, 0); - Assert.fail("MathIllegalArgumentException expected"); - } catch (MathIllegalArgumentException ex) { - // ignored - } - try { - randomData.nextUniform(0, Double.NaN); - Assert.fail("MathIllegalArgumentException expected"); - } catch (MathIllegalArgumentException ex) { - // ignored - } - try { - randomData.nextUniform(Double.NaN, 0); - Assert.fail("MathIllegalArgumentException expected"); - } catch (MathIllegalArgumentException ex) { - // ignored - } - } - - @Test - public void testNextUniformUniformPositiveBounds() { - for (int i = 0; i < 5; i++) { - checkNextUniformUniform(0, 10); - } - } - - @Test - public void testNextUniformUniformNegativeToPositiveBounds() { - for (int i = 0; i < 5; i++) { - checkNextUniformUniform(-3, 5); - } - } - - @Test - public void testNextUniformUniformNegaiveBounds() { - for (int i = 0; i < 5; i++) { - checkNextUniformUniform(-7, -3); - } - } - - @Test - public void testNextUniformUniformMaximalInterval() { - for (int i = 0; i < 5; i++) { - checkNextUniformUniform(-Double.MAX_VALUE, Double.MAX_VALUE); - } - } - - private void checkNextUniformUniform(double min, double max) { - // Set up bin bounds - min, binBound[0], ..., binBound[binCount-2], max - final int binCount = 5; - final double binSize = max / binCount - min/binCount; // Prevent overflow in extreme value case - final double[] binBounds = new double[binCount - 1]; - binBounds[0] = min + binSize; - for (int i = 1; i < binCount - 1; i++) { - binBounds[i] = binBounds[i - 1] + binSize; // + instead of * to avoid overflow in extreme case - } - - final Frequency freq = new Frequency(); - for (int i = 0; i < smallSampleSize; i++) { - final double value = randomData.nextUniform(min, max); - Assert.assertTrue("nextUniform range", (value > min) && (value < max)); - // Find bin - int j = 0; - while (j < binCount - 1 && value > binBounds[j]) { - j++; - } - freq.addValue(j); - } - - final long[] observed = new long[binCount]; - for (int i = 0; i < binCount; i++) { - observed[i] = freq.getCount(i); - } - final double[] expected = new double[binCount]; - for (int i = 0; i < binCount; i++) { - expected[i] = 1d / binCount; - } - - TestUtils.assertChiSquareAccept(expected, observed, 0.01); - } - - /** test exclusive endpoints of nextUniform **/ - @Test - public void testNextUniformExclusiveEndpoints() { - for (int i = 0; i < 1000; i++) { - double u = randomData.nextUniform(0.99, 1); - Assert.assertTrue(u > 0.99 && u < 1); - } - } - - /** test failure modes and distribution of nextGaussian() */ - @Test - public void testNextGaussian() { - try { - randomData.nextGaussian(0, 0); - Assert.fail("zero sigma -- MathIllegalArgumentException expected"); - } catch (MathIllegalArgumentException ex) { - // ignored - } - double[] quartiles = TestUtils.getDistributionQuartiles(new NormalDistribution(0,1)); - long[] counts = new long[4]; - randomData.reSeed(1000); - for (int i = 0; i < 1000; i++) { - double value = randomData.nextGaussian(0, 1); - TestUtils.updateCounts(value, counts, quartiles); - } - TestUtils.assertChiSquareAccept(expected, counts, 0.001); - } - - /** test failure modes and distribution of nextExponential() */ - @Test - public void testNextExponential() { - try { - randomData.nextExponential(-1); - Assert.fail("negative mean -- expecting MathIllegalArgumentException"); - } catch (MathIllegalArgumentException ex) { - // ignored - } - try { - randomData.nextExponential(0); - Assert.fail("zero mean -- expecting MathIllegalArgumentException"); - } catch (MathIllegalArgumentException ex) { - // ignored - } - double[] quartiles; - long[] counts; - - // Mean 1 - quartiles = TestUtils.getDistributionQuartiles(new ExponentialDistribution(1)); - counts = new long[4]; - randomData.reSeed(1000); - for (int i = 0; i < 1000; i++) { - double value = randomData.nextExponential(1); - TestUtils.updateCounts(value, counts, quartiles); - } - TestUtils.assertChiSquareAccept(expected, counts, 0.001); - - // Mean 5 - quartiles = TestUtils.getDistributionQuartiles(new ExponentialDistribution(5)); - counts = new long[4]; - randomData.reSeed(1000); - for (int i = 0; i < 1000; i++) { - double value = randomData.nextExponential(5); - TestUtils.updateCounts(value, counts, quartiles); - } - TestUtils.assertChiSquareAccept(expected, counts, 0.001); - } - - /** test reseeding, algorithm/provider games */ - @Test - public void testConfig() { - randomData.reSeed(1000); - double v = randomData.nextUniform(0, 1); - randomData.reSeed(); - Assert.assertTrue("different seeds", FastMath.abs(v - randomData.nextUniform(0, 1)) > 10E-12); - randomData.reSeed(1000); - Assert.assertEquals("same seeds", v, randomData.nextUniform(0, 1), 10E-12); - randomData.reSeedSecure(1000); - String hex = randomData.nextSecureHexString(40); - randomData.reSeedSecure(); - Assert.assertTrue("different seeds", !hex.equals(randomData - .nextSecureHexString(40))); - randomData.reSeedSecure(1000); - Assert.assertTrue("same seeds", !hex - .equals(randomData.nextSecureHexString(40))); - - /* - * remove this test back soon, since it takes about 4 seconds - * - * try { randomData.setSecureAlgorithm("SHA1PRNG","SUN"); } catch - * (NoSuchProviderException ex) { ; } Assert.assertTrue("different seeds", - * !hex.equals(randomData.nextSecureHexString(40))); try { - * randomData.setSecureAlgorithm("NOSUCHTHING","SUN"); - * Assert.fail("expecting NoSuchAlgorithmException"); } catch - * (NoSuchProviderException ex) { ; } catch (NoSuchAlgorithmException - * ex) { ; } - * - * try { randomData.setSecureAlgorithm("SHA1PRNG","NOSUCHPROVIDER"); - * Assert.fail("expecting NoSuchProviderException"); } catch - * (NoSuchProviderException ex) { ; } - */ - - // test reseeding without first using the generators - RandomDataGenerator rd = new RandomDataGenerator(); - rd.reSeed(100); - rd.nextLong(1, 2); - RandomDataGenerator rd2 = new RandomDataGenerator(); - rd2.reSeedSecure(2000); - rd2.nextSecureLong(1, 2); - rd = new RandomDataGenerator(); - rd.reSeed(); - rd.nextLong(1, 2); - rd2 = new RandomDataGenerator(); - rd2.reSeedSecure(); - rd2.nextSecureLong(1, 2); - } - - /** tests for nextSample() sampling from Collection */ - @Test - public void testNextSample() { - Object[][] c = { { "0", "1" }, { "0", "2" }, { "0", "3" }, - { "0", "4" }, { "1", "2" }, { "1", "3" }, { "1", "4" }, - { "2", "3" }, { "2", "4" }, { "3", "4" } }; - long[] observed = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - double[] expected = { 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 }; - - HashSet<Object> cPop = new HashSet<Object>(); // {0,1,2,3,4} - for (int i = 0; i < 5; i++) { - cPop.add(Integer.toString(i)); - } - - Object[] sets = new Object[10]; // 2-sets from 5 - for (int i = 0; i < 10; i++) { - HashSet<Object> hs = new HashSet<Object>(); - hs.add(c[i][0]); - hs.add(c[i][1]); - sets[i] = hs; - } - - for (int i = 0; i < 1000; i++) { - Object[] cSamp = randomData.nextSample(cPop, 2); - observed[findSample(sets, cSamp)]++; - } - - /* - * Use ChiSquare dist with df = 10-1 = 9, alpha = .001 Change to 21.67 - * for alpha = .01 - */ - Assert.assertTrue("chi-square test -- will fail about 1 in 1000 times", - testStatistic.chiSquare(expected, observed) < 27.88); - - // Make sure sample of size = size of collection returns same collection - HashSet<Object> hs = new HashSet<Object>(); - hs.add("one"); - Object[] one = randomData.nextSample(hs, 1); - String oneString = (String) one[0]; - if ((one.length != 1) || !oneString.equals("one")) { - Assert.fail("bad sample for set size = 1, sample size = 1"); - } - - // Make sure we fail for sample size > collection size - try { - one = randomData.nextSample(hs, 2); - Assert.fail("sample size > set size, expecting MathIllegalArgumentException"); - } catch (MathIllegalArgumentException ex) { - // ignored - } - - // Make sure we fail for empty collection - try { - hs = new HashSet<Object>(); - one = randomData.nextSample(hs, 0); - Assert.fail("n = k = 0, expecting MathIllegalArgumentException"); - } catch (MathIllegalArgumentException ex) { - // ignored - } - } - - @SuppressWarnings("unchecked") - private int findSample(Object[] u, Object[] samp) { - for (int i = 0; i < u.length; i++) { - HashSet<Object> set = (HashSet<Object>) u[i]; - HashSet<Object> sampSet = new HashSet<Object>(); - for (int j = 0; j < samp.length; j++) { - sampSet.add(samp[j]); - } - if (set.equals(sampSet)) { - return i; - } - } - Assert.fail("sample not found:{" + samp[0] + "," + samp[1] + "}"); - return -1; - } - - /** tests for nextPermutation */ - @Test - public void testNextPermutation() { - int[][] p = { { 0, 1, 2 }, { 0, 2, 1 }, { 1, 0, 2 }, { 1, 2, 0 }, - { 2, 0, 1 }, { 2, 1, 0 } }; - long[] observed = { 0, 0, 0, 0, 0, 0 }; - double[] expected = { 100, 100, 100, 100, 100, 100 }; - - for (int i = 0; i < 600; i++) { - int[] perm = randomData.nextPermutation(3, 3); - observed[findPerm(p, perm)]++; - } - - String[] labels = {"{0, 1, 2}", "{ 0, 2, 1 }", "{ 1, 0, 2 }", - "{ 1, 2, 0 }", "{ 2, 0, 1 }", "{ 2, 1, 0 }"}; - TestUtils.assertChiSquareAccept(labels, expected, observed, 0.001); - - // Check size = 1 boundary case - int[] perm = randomData.nextPermutation(1, 1); - if ((perm.length != 1) || (perm[0] != 0)) { - Assert.fail("bad permutation for n = 1, sample k = 1"); - - // Make sure we fail for k size > n - try { - perm = randomData.nextPermutation(2, 3); - Assert.fail("permutation k > n, expecting MathIllegalArgumentException"); - } catch (MathIllegalArgumentException ex) { - // ignored - } - - // Make sure we fail for n = 0 - try { - perm = randomData.nextPermutation(0, 0); - Assert.fail("permutation k = n = 0, expecting MathIllegalArgumentException"); - } catch (MathIllegalArgumentException ex) { - // ignored - } - - // Make sure we fail for k < n < 0 - try { - perm = randomData.nextPermutation(-1, -3); - Assert.fail("permutation k < n < 0, expecting MathIllegalArgumentException"); - } catch (MathIllegalArgumentException ex) { - // ignored - } - - } - } - - // Disable until we have equals - //public void testSerial() { - // Assert.assertEquals(randomData, TestUtils.serializeAndRecover(randomData)); - //} - - private int findPerm(int[][] p, int[] samp) { - for (int i = 0; i < p.length; i++) { - boolean good = true; - for (int j = 0; j < samp.length; j++) { - if (samp[j] != p[i][j]) { - good = false; - } - } - if (good) { - return i; - } - } - Assert.fail("permutation not found"); - return -1; - } - - @Test - public void testNextBeta() { - double[] quartiles = TestUtils.getDistributionQuartiles(new BetaDistribution(2,5)); - long[] counts = new long[4]; - randomData.reSeed(1000); - for (int i = 0; i < 1000; i++) { - double value = randomData.nextBeta(2, 5); - TestUtils.updateCounts(value, counts, quartiles); - } - TestUtils.assertChiSquareAccept(expected, counts, 0.001); - } - - @Test - public void testNextCauchy() { - double[] quartiles = TestUtils.getDistributionQuartiles(new CauchyDistribution(1.2, 2.1)); - long[] counts = new long[4]; - randomData.reSeed(1000); - for (int i = 0; i < 1000; i++) { - double value = randomData.nextCauchy(1.2, 2.1); - TestUtils.updateCounts(value, counts, quartiles); - } - TestUtils.assertChiSquareAccept(expected, counts, 0.001); - } - - @Test - public void testNextChiSquare() { - double[] quartiles = TestUtils.getDistributionQuartiles(new ChiSquaredDistribution(12)); - long[] counts = new long[4]; - randomData.reSeed(1000); - for (int i = 0; i < 1000; i++) { - double value = randomData.nextChiSquare(12); - TestUtils.updateCounts(value, counts, quartiles); - } - TestUtils.assertChiSquareAccept(expected, counts, 0.001); - } - - @Test - public void testNextF() { - double[] quartiles = TestUtils.getDistributionQuartiles(new FDistribution(12, 5)); - long[] counts = new long[4]; - randomData.reSeed(1000); - for (int i = 0; i < 1000; i++) { - double value = randomData.nextF(12, 5); - TestUtils.updateCounts(value, counts, quartiles); - } - TestUtils.assertChiSquareAccept(expected, counts, 0.001); - } - - @Test - public void testNextGamma() { - double[] quartiles; - long[] counts; - - // Tests shape > 1, one case in the rejection sampling - quartiles = TestUtils.getDistributionQuartiles(new GammaDistribution(4, 2)); - counts = new long[4]; - randomData.reSeed(1000); - for (int i = 0; i < 1000; i++) { - double value = randomData.nextGamma(4, 2); - TestUtils.updateCounts(value, counts, quartiles); - } - TestUtils.assertChiSquareAccept(expected, counts, 0.001); - - // Tests shape <= 1, another case in the rejection sampling - quartiles = TestUtils.getDistributionQuartiles(new GammaDistribution(0.3, 3)); - counts = new long[4]; - randomData.reSeed(1000); - for (int i = 0; i < 1000; i++) { - double value = randomData.nextGamma(0.3, 3); - TestUtils.updateCounts(value, counts, quartiles); - } - TestUtils.assertChiSquareAccept(expected, counts, 0.001); - } - - @Test - public void testNextT() { - double[] quartiles = TestUtils.getDistributionQuartiles(new TDistribution(10)); - long[] counts = new long[4]; - randomData.reSeed(1000); - for (int i = 0; i < 1000; i++) { - double value = randomData.nextT(10); - TestUtils.updateCounts(value, counts, quartiles); - } - TestUtils.assertChiSquareAccept(expected, counts, 0.001); - } - - @Test - public void testNextWeibull() { - double[] quartiles = TestUtils.getDistributionQuartiles(new WeibullDistribution(1.2, 2.1)); - long[] counts = new long[4]; - randomData.reSeed(1000); - for (int i = 0; i < 1000; i++) { - double value = randomData.nextWeibull(1.2, 2.1); - TestUtils.updateCounts(value, counts, quartiles); - } - TestUtils.assertChiSquareAccept(expected, counts, 0.001); - } - - @Test - public void testNextBinomial() { - BinomialDistributionTest testInstance = new BinomialDistributionTest(); - int[] densityPoints = testInstance.makeDensityTestPoints(); - double[] densityValues = testInstance.makeDensityTestValues(); - int sampleSize = 1000; - int length = TestUtils.eliminateZeroMassPoints(densityPoints, densityValues); - BinomialDistribution distribution = (BinomialDistribution) testInstance.makeDistribution(); - double[] expectedCounts = new double[length]; - long[] observedCounts = new long[length]; - for (int i = 0; i < length; i++) { - expectedCounts[i] = sampleSize * densityValues[i]; - } - randomData.reSeed(1000); - for (int i = 0; i < sampleSize; i++) { - int value = randomData.nextBinomial(distribution.getNumberOfTrials(), - distribution.getProbabilityOfSuccess()); - for (int j = 0; j < length; j++) { - if (value == densityPoints[j]) { - observedCounts[j]++; - } - } - } - TestUtils.assertChiSquareAccept(densityPoints, expectedCounts, observedCounts, .001); - } - - @Test - public void testNextHypergeometric() { - HypergeometricDistributionTest testInstance = new HypergeometricDistributionTest(); - int[] densityPoints = testInstance.makeDensityTestPoints(); - double[] densityValues = testInstance.makeDensityTestValues(); - int sampleSize = 1000; - int length = TestUtils.eliminateZeroMassPoints(densityPoints, densityValues); - HypergeometricDistribution distribution = (HypergeometricDistribution) testInstance.makeDistribution(); - double[] expectedCounts = new double[length]; - long[] observedCounts = new long[length]; - for (int i = 0; i < length; i++) { - expectedCounts[i] = sampleSize * densityValues[i]; - } - randomData.reSeed(1000); - for (int i = 0; i < sampleSize; i++) { - int value = randomData.nextHypergeometric(distribution.getPopulationSize(), - distribution.getNumberOfSuccesses(), distribution.getSampleSize()); - for (int j = 0; j < length; j++) { - if (value == densityPoints[j]) { - observedCounts[j]++; - } - } - } - TestUtils.assertChiSquareAccept(densityPoints, expectedCounts, observedCounts, .001); - } - - @Test - public void testNextPascal() { - PascalDistributionTest testInstance = new PascalDistributionTest(); - int[] densityPoints = testInstance.makeDensityTestPoints(); - double[] densityValues = testInstance.makeDensityTestValues(); - int sampleSize = 1000; - int length = TestUtils.eliminateZeroMassPoints(densityPoints, densityValues); - PascalDistribution distribution = (PascalDistribution) testInstance.makeDistribution(); - double[] expectedCounts = new double[length]; - long[] observedCounts = new long[length]; - for (int i = 0; i < length; i++) { - expectedCounts[i] = sampleSize * densityValues[i]; - } - randomData.reSeed(1000); - for (int i = 0; i < sampleSize; i++) { - int value = randomData.nextPascal(distribution.getNumberOfSuccesses(), distribution.getProbabilityOfSuccess()); - for (int j = 0; j < length; j++) { - if (value == densityPoints[j]) { - observedCounts[j]++; - } - } - } - TestUtils.assertChiSquareAccept(densityPoints, expectedCounts, observedCounts, .001); - } - - @Test - public void testNextZipf() { - ZipfDistributionTest testInstance = new ZipfDistributionTest(); - int[] densityPoints = testInstance.makeDensityTestPoints(); - double[] densityValues = testInstance.makeDensityTestValues(); - int sampleSize = 1000; - int length = TestUtils.eliminateZeroMassPoints(densityPoints, densityValues); - ZipfDistribution distribution = (ZipfDistribution) testInstance.makeDistribution(); - double[] expectedCounts = new double[length]; - long[] observedCounts = new long[length]; - for (int i = 0; i < length; i++) { - expectedCounts[i] = sampleSize * densityValues[i]; - } - randomData.reSeed(1000); - for (int i = 0; i < sampleSize; i++) { - int value = randomData.nextZipf(distribution.getNumberOfElements(), distribution.getExponent()); - for (int j = 0; j < length; j++) { - if (value == densityPoints[j]) { - observedCounts[j]++; - } - } - } - TestUtils.assertChiSquareAccept(densityPoints, expectedCounts, observedCounts, .001); - } -}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/7550cb46/src/test/java/org/apache/commons/math4/random/RandomGeneratorAbstractTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math4/random/RandomGeneratorAbstractTest.java b/src/test/java/org/apache/commons/math4/random/RandomGeneratorAbstractTest.java deleted file mode 100644 index f4ddfbd..0000000 --- a/src/test/java/org/apache/commons/math4/random/RandomGeneratorAbstractTest.java +++ /dev/null @@ -1,462 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.math4.random; - -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.stat.Frequency; -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.Ignore; -import org.junit.Test; - -/** - * Base class for RandomGenerator tests. - * - * Tests RandomGenerator methods directly and also executes RandomDataTest - * test cases against a RandomDataImpl created using the provided generator. - * - * RandomGenerator test classes should extend this class, implementing - * makeGenerator() to provide a concrete generator to test. The generator - * returned by makeGenerator should be seeded with a fixed seed. - * - */ - -public abstract class RandomGeneratorAbstractTest extends RandomDataGeneratorTest { - - /** RandomGenerator under test */ - protected RandomGenerator generator; - - /** - * Override this method in subclasses to provide a concrete generator to test. - * Return a generator seeded with a fixed seed. - */ - protected abstract RandomGenerator makeGenerator(); - - /** - * Initialize generator and randomData instance in superclass. - */ - public RandomGeneratorAbstractTest() { - generator = makeGenerator(); - randomData = new RandomDataGenerator(generator); - } - - /** - * Set a fixed seed for the tests - */ - @Before - public void setUp() { - generator = makeGenerator(); - } - - // Omit secureXxx tests, since they do not use the provided generator - @Override - public void testNextSecureLongIAE() {} - @Override - public void testNextSecureLongNegativeToPositiveRange() {} - @Override - public void testNextSecureLongNegativeRange() {} - @Override - public void testNextSecureLongPositiveRange() {} - @Override - public void testNextSecureIntIAE() {} - @Override - public void testNextSecureIntNegativeToPositiveRange() {} - @Override - public void testNextSecureIntNegativeRange() {} - @Override - public void testNextSecureIntPositiveRange() {} - @Override - public void testNextSecureHex() {} - - @Test - /** - * Tests uniformity of nextInt(int) distribution by generating 1000 - * samples for each of 10 test values and for each sample performing - * a chi-square test of homogeneity of the observed distribution with - * the expected uniform distribution. Tests are performed at the .01 - * level and an average failure rate higher than 2% (i.e. more than 20 - * null hypothesis rejections) causes the test case to fail. - * - * All random values are generated using the generator instance used by - * other tests and the generator is not reseeded, so this is a fixed seed - * test. - */ - public void testNextIntDirect() { - // Set up test values - end of the array filled randomly - int[] testValues = new int[] {4, 10, 12, 32, 100, 10000, 0, 0, 0, 0}; - for (int i = 6; i < 10; i++) { - final int val = generator.nextInt(); - testValues[i] = val < 0 ? -val : val + 1; - } - - final int numTests = 1000; - for (int i = 0; i < testValues.length; i++) { - final int n = testValues[i]; - // Set up bins - int[] binUpperBounds; - if (n < 32) { - binUpperBounds = new int[n]; - for (int k = 0; k < n; k++) { - binUpperBounds[k] = k; - } - } else { - binUpperBounds = new int[10]; - final int step = n / 10; - for (int k = 0; k < 9; k++) { - binUpperBounds[k] = (k + 1) * step; - } - binUpperBounds[9] = n - 1; - } - // Run the tests - int numFailures = 0; - final int binCount = binUpperBounds.length; - final long[] observed = new long[binCount]; - final double[] expected = new double[binCount]; - expected[0] = binUpperBounds[0] == 0 ? (double) smallSampleSize / (double) n : - (double) ((binUpperBounds[0] + 1) * smallSampleSize) / (double) n; - for (int k = 1; k < binCount; k++) { - expected[k] = (double) smallSampleSize * - (double) (binUpperBounds[k] - binUpperBounds[k - 1]) / n; - } - for (int j = 0; j < numTests; j++) { - Arrays.fill(observed, 0); - for (int k = 0; k < smallSampleSize; k++) { - final int value = generator.nextInt(n); - Assert.assertTrue("nextInt range",(value >= 0) && (value < n)); - for (int l = 0; l < binCount; l++) { - if (binUpperBounds[l] >= value) { - observed[l]++; - break; - } - } - } - if (testStatistic.chiSquareTest(expected, observed) < 0.01) { - numFailures++; - } - } - if ((double) numFailures / (double) numTests > 0.02) { - Assert.fail("Too many failures for n = " + n + - " " + numFailures + " out of " + numTests + " tests failed."); - } - } - } - - @Test - public void testNextLongDirect() { - long q1 = Long.MAX_VALUE/4; - long q2 = 2 * q1; - long q3 = 3 * q1; - - Frequency freq = new Frequency(); - long val = 0; - int value = 0; - for (int i=0; i<smallSampleSize; i++) { - val = generator.nextLong(); - val = val < 0 ? -val : val; - if (val < q1) { - value = 0; - } else if (val < q2) { - value = 1; - } else if (val < q3) { - value = 2; - } else { - value = 3; - } - freq.addValue(value); - } - long[] observed = new long[4]; - for (int i=0; i<4; i++) { - observed[i] = freq.getCount(i); - } - - /* Use ChiSquare dist with df = 4-1 = 3, alpha = .001 - * Change to 11.34 for alpha = .01 - */ - Assert.assertTrue("chi-square test -- will fail about 1 in 1000 times", - testStatistic.chiSquare(expected,observed) < 16.27); - } - - @Test - public void testNextBooleanDirect() { - long halfSampleSize = smallSampleSize / 2; - double[] expected = {halfSampleSize, halfSampleSize}; - long[] observed = new long[2]; - for (int i=0; i<smallSampleSize; i++) { - if (generator.nextBoolean()) { - observed[0]++; - } else { - observed[1]++; - } - } - /* Use ChiSquare dist with df = 2-1 = 1, alpha = .001 - * Change to 6.635 for alpha = .01 - */ - Assert.assertTrue("chi-square test -- will fail about 1 in 1000 times", - testStatistic.chiSquare(expected,observed) < 10.828); - } - - @Test - public void testNextFloatDirect() { - Frequency freq = new Frequency(); - float val = 0; - int value = 0; - for (int i=0; i<smallSampleSize; i++) { - val = generator.nextFloat(); - if (val < 0.25) { - value = 0; - } else if (val < 0.5) { - value = 1; - } else if (val < 0.75) { - value = 2; - } else { - value = 3; - } - freq.addValue(value); - } - long[] observed = new long[4]; - for (int i=0; i<4; i++) { - observed[i] = freq.getCount(i); - } - - /* Use ChiSquare dist with df = 4-1 = 3, alpha = .001 - * Change to 11.34 for alpha = .01 - */ - Assert.assertTrue("chi-square test -- will fail about 1 in 1000 times", - testStatistic.chiSquare(expected,observed) < 16.27); - } - - @Test - public void testNextDouble() { - final double[] sample = new double[1000]; - for (int i = 0; i < sample.length; i++) { - sample[i] = generator.nextDouble(); - } - final RealDistribution uniformDistribution = new UniformRealDistribution(0,1); - final KolmogorovSmirnovTest ks = new KolmogorovSmirnovTest(); - Assert.assertFalse(ks.kolmogorovSmirnovTest(uniformDistribution, sample, .01)); - } - - - @Test(expected=MathIllegalArgumentException.class) - public void testNextIntPrecondition1() { - generator.nextInt(-1); - } - - @Test(expected=MathIllegalArgumentException.class) - public void testNextIntPrecondition2() { - generator.nextInt(0); - } - - @Test - public void testNextInt2() { - int walk = 0; - final int N = 10000; - for (int k = 0; k < N; ++k) { - if (generator.nextInt() >= 0) { - ++walk; - } else { - --walk; - } - } - Assert.assertTrue("Walked too far astray: " + walk + "\nNote: This " + - "test will fail randomly about 1 in 100 times.", - FastMath.abs(walk) < FastMath.sqrt(N) * 2.576); - } - - @Test - public void testNextLong2() { - int walk = 0; - final int N = 1000; - for (int k = 0; k < N; ++k) { - if (generator.nextLong() >= 0) { - ++walk; - } else { - --walk; - } - } - Assert.assertTrue("Walked too far astray: " + walk + "\nNote: This " + - "test will fail randomly about 1 in 100 times.", - FastMath.abs(walk) < FastMath.sqrt(N) * 2.576); - } - - @Test - public void testNextBoolean2() { - int walk = 0; - final int N = 10000; - for (int k = 0; k < N; ++k) { - if (generator.nextBoolean()) { - ++walk; - } else { - --walk; - } - } - Assert.assertTrue("Walked too far astray: " + walk + "\nNote: This " + - "test will fail randomly about 1 in 100 times.", - FastMath.abs(walk) < FastMath.sqrt(N) * 2.576); - } - - @Test - public void testNextBytes() { - long[] count = new long[256]; - byte[] bytes = new byte[10]; - double[] expected = new double[256]; - final int sampleSize = 100000; - - for (int i = 0; i < 256; i++) { - expected[i] = (double) sampleSize / 265f; - } - - for (int k = 0; k < sampleSize; ++k) { - generator.nextBytes(bytes); - for (byte b : bytes) { - ++count[b + 128]; - } - } - - TestUtils.assertChiSquareAccept(expected, count, 0.001); - - } - - // MATH-1300 - @Test - public void testNextBytesChunks() { - final int[] chunkSizes = { 4, 8, 12, 16 }; - final int[] chunks = { 1, 2, 3, 4, 5 }; - for (int chunkSize : chunkSizes) { - for (int numChunks : chunks) { - checkNextBytesChunks(chunkSize, numChunks); - } - } - } - - // MATH-1300: Test is ignored because it will fail due to the array - // size not being a multiple of 4. - @Ignore@Test - public void testNextBytesChunksFail() { - final int[] chunkSizes = { 5 }; - final int[] chunks = { 4 }; - for (int chunkSize : chunkSizes) { - for (int numChunks : chunks) { - checkNextBytesChunks(chunkSize, numChunks); - } - } - } - - @Test - public void testSeeding() { - // makeGenerator initializes with fixed seed - RandomGenerator gen = makeGenerator(); - RandomGenerator gen1 = makeGenerator(); - checkSameSequence(gen, gen1); - // reseed, but recreate the second one - // verifies MATH-723 - gen.setSeed(100); - gen1 = makeGenerator(); - gen1.setSeed(100); - checkSameSequence(gen, gen1); - } - - private void checkSameSequence(RandomGenerator gen1, RandomGenerator gen2) { - final int len = 11; // Needs to be an odd number to check MATH-723 - final double[][] values = new double[2][len]; - for (int i = 0; i < len; i++) { - values[0][i] = gen1.nextDouble(); - } - for (int i = 0; i < len; i++) { - values[1][i] = gen2.nextDouble(); - } - Assert.assertTrue(Arrays.equals(values[0], values[1])); - for (int i = 0; i < len; i++) { - values[0][i] = gen1.nextFloat(); - } - for (int i = 0; i < len; i++) { - values[1][i] = gen2.nextFloat(); - } - Assert.assertTrue(Arrays.equals(values[0], values[1])); - for (int i = 0; i < len; i++) { - values[0][i] = gen1.nextInt(); - } - for (int i = 0; i < len; i++) { - values[1][i] = gen2.nextInt(); - } - Assert.assertTrue(Arrays.equals(values[0], values[1])); - for (int i = 0; i < len; i++) { - values[0][i] = gen1.nextLong(); - } - for (int i = 0; i < len; i++) { - values[1][i] = gen2.nextLong(); - } - Assert.assertTrue(Arrays.equals(values[0], values[1])); - for (int i = 0; i < len; i++) { - values[0][i] = gen1.nextInt(len); - } - for (int i = 0; i < len; i++) { - values[1][i] = gen2.nextInt(len); - } - Assert.assertTrue(Arrays.equals(values[0], values[1])); - for (int i = 0; i < len; i++) { - values[0][i] = gen1.nextBoolean() ? 1 : 0; - } - for (int i = 0; i < len; i++) { - values[1][i] = gen2.nextBoolean() ? 1 : 0; - } - Assert.assertTrue(Arrays.equals(values[0], values[1])); - for (int i = 0; i < len; i++) { - values[0][i] = gen1.nextGaussian(); - } - for (int i = 0; i < len; i++) { - values[1][i] = gen2.nextGaussian(); - } - Assert.assertTrue(Arrays.equals(values[0], values[1])); - } - - // MATH-1300 - private void checkNextBytesChunks(int chunkSize, - int numChunks) { - final RandomGenerator rg = makeGenerator(); - final long seed = 1234567L; - - final byte[] b1 = new byte[chunkSize * numChunks]; - final byte[] b2 = new byte[chunkSize]; - - // Generate the chunks in a single call. - rg.setSeed(seed); - rg.nextBytes(b1); - - // Reset. - rg.setSeed(seed); - // Generate the chunks in consecutive calls. - for (int i = 0; i < numChunks; i++) { - rg.nextBytes(b2); - } - - // Store last 128 bytes chunk of b1 into b3. - final byte[] b3 = new byte[chunkSize]; - System.arraycopy(b1, b1.length - b3.length, b3, 0, b3.length); - - // Sequence of calls must be the same. - Assert.assertArrayEquals("chunkSize=" + chunkSize + " numChunks=" + numChunks, - b2, b3); - } -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/7550cb46/src/test/java/org/apache/commons/math4/random/RandomGeneratorFactoryTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math4/random/RandomGeneratorFactoryTest.java b/src/test/java/org/apache/commons/math4/random/RandomGeneratorFactoryTest.java deleted file mode 100644 index fc94e88..0000000 --- a/src/test/java/org/apache/commons/math4/random/RandomGeneratorFactoryTest.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.math4.random; - -import java.util.Random; - -import org.apache.commons.math4.random.RandomGenerator; -import org.apache.commons.math4.random.RandomGeneratorFactory; - -/** - * Test cases for the {@link RandomGeneratorFactory} class. - * - */ -public class RandomGeneratorFactoryTest extends RandomGeneratorAbstractTest { - - @Override - protected RandomGenerator makeGenerator() { - RandomGenerator generator = RandomGeneratorFactory.createRandomGenerator(new Random()); - generator.setSeed(1001); - return generator; - } -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/7550cb46/src/test/java/org/apache/commons/math4/random/Well19937cTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math4/random/Well19937cTest.java b/src/test/java/org/apache/commons/math4/random/Well19937cTest.java deleted file mode 100644 index cfffcd1..0000000 --- a/src/test/java/org/apache/commons/math4/random/Well19937cTest.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.math4.random; - -import org.apache.commons.math4.random.RandomGenerator; -import org.apache.commons.math4.random.Well19937c; -import org.junit.Assert; -import org.junit.Test; - -public class Well19937cTest extends RandomGeneratorAbstractTest { - - @Override - public RandomGenerator makeGenerator() { - return new Well19937c(100); - } - - @Test - public void testReferenceCode() { - int[] base = { - 740849862, 1202665156, -199039369, -259008301, -291878969, -1164428990, -1565918811, 491009864, - -1883086670, 1383450241, 1244617256, 689006653, -1576746370, -1307940314, 1421489086, 1742094000, - -595495729, 1047766204, 1875773301, -1637793284, 1379017098, 262792705, 191880010, -251000180, - -1753047622, -972355720, 90626881, 1644693418, 1503365577, 439653419, 1806361562, 1268823869 - }; - int[] init = new int[624]; - for (int i = 0; i < init.length; ++i) { - init[i] = base[i % base.length] + i; - } - Well19937c mt = new Well19937c(init); - int[] refInt = { - 2128528153, 327121884, 935445371, -83026433, -1041143083, 2084595880, -1073535198, -1678863790, -523636021, -1514837782, -736786810, 1527711112, -1051227939, 978703380, 410322163, 1727815703, - -648426354, 636056441, 1954420292, 17754810, -958628705, -1091307602, 1793078738, -1680336346, 1792171272, 941973796, -2066152330, -1248758068, -1061211586, 262020189, 1276960217, -233886784, - 1767509252, -1811939255, -406116097, -742435920, -1349799525, 240329556, -332161345, 1488943143, -332244280, 2093328957, 674753300, -1930135556, 257111467, 63793650, -1964335223, 1315849133, - -797349146, 1372022250, -1451892049, -1325138957, -870401239, -1294317369, 91490879, 386205044, -704074702, -1230679067, 1513674392, -262996240, 1196007314, 1398903796, 803719762, -1750926831, - -1268814180, 1233515404, 1498313934, -970591257, 611113671, -261632474, 1834097325, 1709440492, -150396854, 2120561003, -62645660, 479080234, 1535125050, 1823378695, -1129289329, -1095198399, - 2092564733, 78836308, -692015409, 1647147229, -1847922219, 1838279320, -848333841, -1375151778, 920238861, 1512628290, -749439404, 288851918, -427218675, 679640964, 425700808, -2077624511, - -1929434455, -647176419, 650437190, -1926749131, -1564744729, 734494454, 108193743, 246246679, 810042628, 1952337771, 1089253730, -1874275331, 1428419392, -492969232, 1945270770, -201265602, - -755490251, -624426214, -699605715, -113446478, 809091299, -1521531511, 1136505389, -523660964, 132928433, 1926559713, -1485314325, -508322506, 46307756, -1627479740, -589386406, -1855555892, - 584299545, 1272841066, -597242658, 925134545, 1102566453, -753335037, -9523218, -1778632375, 568963646, 764338254, 1259944540, -2000124642, 1307414525, -151384482, 807294400, 1993749511, - -15503094, -709471492, 2104830082, 1387684315, -1929056119, 224254668, -733550950, -889466978, -1987783335, -437144026, 995905753, -1021386158, -1096313388, -1014152835, -1303258241, 1201884788, - -1845042397, 1421462511, 980805867, 2143771251, 481226968, 1790544569, 328448328, 1995857639, -66668269, -1411421267, -222586606, 866950765, -308713926, -1048350893, 993222402, -1139265642, - -871837948, 1145571913, 381928580, 35386691, 1640961123, -1192981020, 775971009, 594246635, 1603197812, -575106766, 2023682000, -1636301903, -718093720, -1666421635, -2146115988, 320593570, - 287355418, 454400027, 1112753817, 1751196267, 782077910, -1478447368, -1007557264, -862315517, -2035355952, 2123515250, -557641502, -1789932035, 879640129, 44167603, 791148984, 1382939723, - -2135684233, 1825489580, 937345485, -1839983359, -1536880111, -1472578359, 1548052748, -1471535862, -14508727, 1509621398, -2134967452, -787485401, 815341660, -327905128, 1028096737, 866906991, - -1585990806, 859229080, 234806270, 998518056, -1897890815, -900923587, 1179856752, 1529572451, 620486106, 1119836556, 1661285564, 2097404633, -1437490790, 265306115, -984880135, 1326751968, - 1280043536, 680210701, 155786166, 1550973250, -325781949, -597789777, -1939780, 1345275487, 1930450001, 941449704, 669301309, 693651713, -990721514, 582968326, 976132553, -1892942099, - -1065070157, -711990993, -688974833, -1026091683, 1115346827, -1305730749, -1733626381, -364566696, -21761572, -37152746, -262011730, 1302722752, -1806313409, -767072509, 764112137, 1671157377, - 1837645038, -1021606421, -1781898911, -232127459, -310742675, -1818095744, -1128320656, -705565953, -354445532, -523172807, -433877202, 131904485, -64292316, 381829280, 229820263, 1797992622, - 1359665678, 978481451, -885267130, -1415988446, -356533788, -961419072, 1938703090, 708344111, 679299953, 744615129, 1328811158, 1257588574, 569216282, -753296151, -1519838713, 2016884452, - 1062684606, 1561736790, 2028643511, -1353001615, 886376832, 1466953172, 1664783899, 1290079981, -57483993, -1176112430, 1634916316, 1976304475, 1374136869, -648738039, 1058175869, -909000745, - -1526439218, 726626991, 2066596202, 64980943, -26166577, -885900005, -1821546816, -1103727665, 730606315, -1324948459, -696956940, -1300869403, 1171578314, 797249074, -1600611618, 1928247682, - 307164165, -1482476232, -1886179640, 1306433392, 1945271359, -1272113751, -1285984081, -2057145549, 795047465, 1262569087, -1239828121, 1426641636, -786371495, 2120199316, 1273690652, 74457589, - -1033394229, 338952565, 46122958, 1225741533, 2115308090, 678200841, -1618264885, -101162569, -1628976330, -1232839500, 468709044, 1876019116, 92723122, 233398255, -554960844, 38494196, - -406437278, 2083528643, -1106878615, -340722557, -2123964932, 223183343, 108918116, -1014629054, -901344544, -838896840, -1908460517, -1763508731, -926890833, 1703791049, -667755577, 1694418389, - 791641263, 1095689677, 1119202039, -1419111438, -2012259010, 188017439, -1775110395, -1971099661, -1688113734, 131472813, -776304959, 1511388884, 2080864872, -1733824651, 1992147495, 1119828320, - 1065336924, -1357606762, 462963503, 1180719494, -202678962, -892646595, 605869323, 1144255663, 878462678, -1051371303, 872374876, 631322271, -172600544, -1552071375, -1939570033, 151973117, - 1640861022, 310682640, 34192866, 2057773671, -2004476027, -1879238973, 582736114, 900581664, -427390545, -1232348528, -535115984, 1321853054, 69386780, -1729375922, 1418473715, 1022091451, - 496799289, -80757405, -1903543310, -1128846846, 1703964, 1984450945, 856753858, -812919184, 775486323, -1376056193, 638628840, 314243536, 1030626207, 644050997, 73923896, 362270613, - 236584904, 1463240891, -223614432, 435371594, -751940030, -124274553, -1991092884, 1579624267, 1249632649, 157589625, -345229739, -366245207, -1399995986, 1651729983, 1965074340, -1108970305, - 1163690769, 1732013523, -1461252895, 669755552, -476503675, -264578685, -32813949, 288222188, -25734262, 106040916, 1654395626, -365148479, 2014455846, -2040447994, 1351639280, -919975757, - -1970412139, -47306532, 222377665, -363434917, -1091717516, 2090685531, -1221091649, -1729649190, -1239406708, 1064945398, -105437479, -419675255, 74701669, -12862899, -498269844, 1566898997, - -1872838355, 1596887574, 485902962, 469225597, -881763553, 1307841032, -1642872487, 1388543045, 379792876, 1095683384, 840780732, 1934378038, 1851278350, -1359389423, 130868458, -313448799, - -663624816, 1031714153, -608443411, -205137499, -1849464427, 1973593637, 1068741808, -1420655961, 1188762305, 954044841, -995454462, -1818101092, -1937201943, -324541290, -1520603933, 572873173, - -554764496, 1051557081, -1245136076, -985349536, 329320398, 1787901464, -37803304, -1759310177, -1463492617, -1861729663, 1251768782, 256937091, -779036948, -2049893864, 1256022877, 1228075657, - -1550195255, -611319853, 1190797155, 2047604112, -576077160, -1532843331, -1324899394, -159729560, -622525946, -1080302767, -236033484, 1895243903, -410123689, -1944154157, -681781021, 1208453003, - 579595878, 1303914051, -145607082, -131567277, -1917288455, 894217359, -175688726, -1585480723, 663691440, -1140068263, -641711178, 1596080008, 629197693, 976422358, -1570451095, 525923776, - 895046136, -504151767, 1602553020, -1233054923, -1798474837, -1488857895, 1055782627, 261863143, 1879276655, 488240679, 1910982611, -1919441259, 370435945, 1265230086, -1293284428, -1503576227, - 2076963035, -1379628250, 1157098875, 1984461153, -1947837397, 1705880124, 1453607404, -1233649748, 1479943773, -863878721, -862415630, -736723275, 940306358, -1596000684, -1174889953, -615723892, - -885006597, -1796723178, 1844159055, -188942309, 2107251811, -1675486996, -1009475178, -859263556, -431866963, -9593673, -1878920923, -104853791, -1535224994, -69315537, 586690130, -1292234796, - 1378749456, -301873019, -319297563, 1677205851, 292450579, -1289441171, 1788113680, 1907606333, 1464711611, -1372023606, -1978832445, -1772259768, 1949124464, 1818322887, -1138036603, 1249727628, - -1474866449, -1868013169, -1384567593, 717007936, 954189997, -1900561040, 738470389, -158973180, 1732860784, 1936031206, -1133354740, -1173166665, 1432976712, 852636081, 1732064691, -1831788120, - 1273933579, 455403217, 1988395890, 106493468, 506092152, -610530423, 1698053512, 1311747476, 1969503012, -1887461759, 1613543073, 903200334, -737865837, 325656800, -1234001200, 1492148864, - 2009861533, -368262605, 1091338541, 2076108119, -961392337, 1835877112, 316250307, -853333391, -2125443777, 815363504, -798707803, -158146540, 690786114, -530775684, 1203556940, 1611485582, - -1661412270, -53184506, 2126287444, -232222229, 1559486057, 283532250, 1202760418, 932144172, 1082594656, -570104011, 413509167, -995027177, -996477516, -540544, -745537167, -712135469, - -996294983, -592787198, 1889840948, 1314628747, -394266926, -682316577, 456447239, 1728806063, -396279614, -43387643, 1915717013, -861574144, -1078710588, -561401249, 1111464540, 63643984, - -1693870413, -968369980, -1053148188, 708799038, 1883537988, 373371671, -156410415, -1596483236, -1846890431, 888692915, -1025632583, -1666477591, -343066267, -2059058792, 641501628, -1744347292, - 1648632991, 1743540146, 2020952406, 164014499, 990508262, 1706408228, -1236471842, -347116260, 1843634523, 827255665, 300519853, -1265974830, -547247177, -583064554, -1995437077, 689210107, - -93151393, 835365056, 1706367315, -1605902756, 200954895, 431093688, -277573364, -928486713, -552221973, 145432789, 1128919795, 1675095586, 1930359882, 1215849501, -1447770583, 657776490, - 1885869860, -1629237204, -868897479, -1258169760, 1828140195, -883850439, 463933909, -347361158, 1478116648, 801176896, -1501915899, 1017335748, -1654508882, 123994786, 1588785290, 791166651, - -1523108535, 340411166, -496474762, -1189711141, -7392628, 2045171250, -1245366209, 834787230, -1346883181, 2034209454, 737043362, 898803323, 1983089087, -1845404320, 9585188, -1180608323, - 1665100606, 1949474222, -211115008, 1151308295, -2132174259, 913126312, -2085061672, 1419864120, -1134542954, -53833957, -246913211, 468382370, -1759479323, 1136686211, 1307012488, -2036299559, - -1346099736, 314743106, -1683101865, -947151948, -234529696, -2103334293, -279256894, -1484257, -1053953017, 1801205399, 941594454, -874119215, -672865187, 762284205, -1494975451, 486607927, - -898264389, -1711861093, -212572760, 2106484281, -1610786470, 1352525590, -837779586, 1568282001, -593019125, -1146260782, -1595879979, -640781858, 1107692311, 1547132709, -1928385535, -2057772805, - 634887038, 329772618, 942136006, -864405576, 501883884, 1537141484, -1180626836, 1123055420, 1090885851, 421662750, 2033111605, 1710917425, -1118058244, 74321279, 257328195, -1199940697, - 208625996, -442341447, 808119183, 1166827075, 1177417517, -1856155370, -1464837036, -60624923, -1306220638, -91104698, -1434621430, 548899241, 37351476, 1478278431, -1255061434, 248470035, - -104642597, -1865169521, 1418373655, -1660810523, -2129015436, 154612798, 276575732, 1930338442, 179503250, -929294855, -39452027, -1377657544, 1442322193, 1137511318, -432158653, -984801987, - 743099148, -1118893528, -904123623, -1273146363, -1884800406, -803169061, 1254123158, -484252077, 317646844, 404246525, -1230293916, 1121445742, -19657507, 652967153, -1055406692, -468950719, - -1493532921, -1447624258, -1369679689, -1517000228, -145853307, 1518006526, 1591195514, -1475557146, -909722097, 2103182976, -406830579, -2124025254, -1804819507, -1357512858, 567321869, 409048156, - 567805180, 1749009386, 1762759722, -1770324077, 1271140844, 468219092, 955792405, 1911965665, 1876314424, -718200715, -1278883927, 1392281730, -120519585, 851473793, 245054754, -33369039, - -284877584, -479534880, -212346563, -122017521, -1461429983, 1331007370, 1788621721, 1739036536, 1446350953, -1985448033, 685528610, -1386434659, 1368233993, 2021786790, 1596478397, -1716635278, - -2011083017, 171876097, -311529197, 687812052, 377000657, -1055547517, -1499047842, -1818434951, -120863666, 33888043, -1387509273, -541540700, 1162597745, -1331415338, 1931708792, -850270000, - 663845594, 1536495943, -322924971, -1380272203, 261190298, -204874428, -2104974031, 883819928, 155808204, -1454446035, 1323388464, -1696505728, 1549800285, 1018150463, -1327715703, -1582480640, - 1013659809, -1820360082, 1666498787, 1406120540, -196541482, 1248470531, -1250433281, 836375878, 177646854, -1927020253, 2145878321, 689712096, -596605921, 348283199, 1916993096, 481356808, - -339687826, 1219340319, 718895887, -2007521340, -1859185806, 2042164737, -58146784, 742449142, 1930754708, 780832111, 715056441, -1393886151, -8150527, -599607443, -537300865, -1212516084 - }; - - for (int i = 0; i < refInt.length; ++i) { - Assert.assertEquals(refInt[i], mt.nextInt()); - } - - } - -}