Moved some (unit test) classes one level down. Top-level package for this code is "o.a.c.rng.core".
Project: http://git-wip-us.apache.org/repos/asf/commons-rng/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-rng/commit/954a8f2e Tree: http://git-wip-us.apache.org/repos/asf/commons-rng/tree/954a8f2e Diff: http://git-wip-us.apache.org/repos/asf/commons-rng/diff/954a8f2e Branch: refs/heads/1.0-release Commit: 954a8f2eca256abbeff469b0cacecb07fa27483d Parents: 1d032e1 Author: Gilles <er...@apache.org> Authored: Thu Nov 24 17:51:31 2016 +0100 Committer: Gilles <er...@apache.org> Committed: Thu Nov 24 17:51:31 2016 +0100 ---------------------------------------------------------------------- .../commons/rng/Providers32ParametricTest.java | 58 -- .../commons/rng/Providers64ParametricTest.java | 58 -- .../rng/ProvidersCommonParametricTest.java | 613 ------------------ .../org/apache/commons/rng/ProvidersList.java | 138 ----- .../org/apache/commons/rng/RandomAssert.java | 36 -- .../commons/rng/core/BaseProviderTest.java | 48 +- .../rng/core/Providers32ParametricTest.java | 60 ++ .../rng/core/Providers64ParametricTest.java | 60 ++ .../rng/core/ProvidersCommonParametricTest.java | 615 +++++++++++++++++++ .../apache/commons/rng/core/ProvidersList.java | 139 +++++ .../apache/commons/rng/core/RandomAssert.java | 38 ++ .../rng/core/source32/ISAACRandomTest.java | 2 +- .../rng/core/source32/KISSRandomTest.java | 2 +- .../rng/core/source32/MersenneTwisterTest.java | 2 +- .../core/source32/MultiplyWithCarry256Test.java | 2 +- .../rng/core/source32/Well1024aTest.java | 2 +- .../rng/core/source32/Well19937aTest.java | 2 +- .../rng/core/source32/Well19937cTest.java | 2 +- .../rng/core/source32/Well44497aTest.java | 2 +- .../rng/core/source32/Well44497bTest.java | 2 +- .../commons/rng/core/source32/Well512aTest.java | 2 +- .../core/source64/MersenneTwister64Test.java | 2 +- .../rng/core/source64/SplitMix64Test.java | 2 +- .../rng/core/source64/XorShift1024StarTest.java | 2 +- 24 files changed, 949 insertions(+), 940 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-rng/blob/954a8f2e/commons-rng-core/src/test/java/org/apache/commons/rng/Providers32ParametricTest.java ---------------------------------------------------------------------- diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/Providers32ParametricTest.java b/commons-rng-core/src/test/java/org/apache/commons/rng/Providers32ParametricTest.java deleted file mode 100644 index aef8045..0000000 --- a/commons-rng-core/src/test/java/org/apache/commons/rng/Providers32ParametricTest.java +++ /dev/null @@ -1,58 +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.rng; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; - -/** - * Tests which all 32-bits based generators must pass. - */ -@RunWith(value=Parameterized.class) -public class Providers32ParametricTest { - /** RNG under test. */ - private final RestorableUniformRandomProvider generator; - - /** - * Initializes generator instance. - * - * @param rng RNG to be tested. - */ - public Providers32ParametricTest(RestorableUniformRandomProvider rng) { - generator = rng; - } - - @Parameters(name = "{index}: data={0}") - public static Iterable<RestorableUniformRandomProvider[]> getList() { - return ProvidersList.list32(); - } - - @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) { - ProvidersCommonParametricTest.checkNextBytesChunks(generator, - chunkSize, - numChunks); - } - } - } -} http://git-wip-us.apache.org/repos/asf/commons-rng/blob/954a8f2e/commons-rng-core/src/test/java/org/apache/commons/rng/Providers64ParametricTest.java ---------------------------------------------------------------------- diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/Providers64ParametricTest.java b/commons-rng-core/src/test/java/org/apache/commons/rng/Providers64ParametricTest.java deleted file mode 100644 index 79f5e72..0000000 --- a/commons-rng-core/src/test/java/org/apache/commons/rng/Providers64ParametricTest.java +++ /dev/null @@ -1,58 +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.rng; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; - -/** - * Tests which all 64-bits based generators must pass. - */ -@RunWith(value=Parameterized.class) -public class Providers64ParametricTest { - /** RNG under test. */ - private final RestorableUniformRandomProvider generator; - - /** - * Initializes generator instance. - * - * @param rng RNG to be tested. - */ - public Providers64ParametricTest(RestorableUniformRandomProvider rng) { - generator = rng; - } - - @Parameters(name = "{index}: data={0}") - public static Iterable<RestorableUniformRandomProvider[]> getList() { - return ProvidersList.list64(); - } - - @Test - public void testNextBytesChunks() { - final int[] chunkSizes = { 8, 16, 24 }; - final int[] chunks = { 1, 2, 3, 4, 5 }; - for (int chunkSize : chunkSizes) { - for (int numChunks : chunks) { - ProvidersCommonParametricTest.checkNextBytesChunks(generator, - chunkSize, - numChunks); - } - } - } -} http://git-wip-us.apache.org/repos/asf/commons-rng/blob/954a8f2e/commons-rng-core/src/test/java/org/apache/commons/rng/ProvidersCommonParametricTest.java ---------------------------------------------------------------------- diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/ProvidersCommonParametricTest.java b/commons-rng-core/src/test/java/org/apache/commons/rng/ProvidersCommonParametricTest.java deleted file mode 100644 index 471682c..0000000 --- a/commons-rng-core/src/test/java/org/apache/commons/rng/ProvidersCommonParametricTest.java +++ /dev/null @@ -1,613 +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.rng; - -import java.util.Arrays; -import java.util.List; -import java.util.ArrayList; -import java.util.concurrent.Callable; -import java.io.IOException; -import java.io.ObjectOutputStream; -import java.io.ObjectInputStream; -import java.io.ByteArrayOutputStream; -import java.io.ByteArrayInputStream; - -import org.junit.Assert; -import org.junit.Test; -import org.junit.Assume; -import org.junit.Ignore; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; - -import org.apache.commons.rng.core.RandomProviderDefaultState; - -/** - * Tests which all generators must pass. - */ -@RunWith(value=Parameterized.class) -public class ProvidersCommonParametricTest { - /** RNG under test. */ - private final RestorableUniformRandomProvider generator; - - /** - * Initializes generator instance. - * - * @param rng RNG to be tested. - */ - public ProvidersCommonParametricTest(RestorableUniformRandomProvider rng) { - generator = rng; - } - - @Parameters(name = "{index}: data={0}") - public static Iterable<RestorableUniformRandomProvider[]> getList() { - return ProvidersList.list(); - } - - - // Precondition tests - - @Test(expected=IllegalArgumentException.class) - public void testPreconditionNextInt1() { - generator.nextInt(-1); - } - - @Test(expected=IllegalArgumentException.class) - public void testPreconditionNextInt2() { - generator.nextInt(0); - } - - @Test(expected=IllegalArgumentException.class) - public void testPreconditionNextLong1() { - generator.nextLong(-1); - } - - @Test(expected=IllegalArgumentException.class) - public void testPreconditionNextLong2() { - generator.nextLong(0); - } - - @Test(expected=IndexOutOfBoundsException.class) - public void testPreconditionNextBytes1() { - final int size = 10; - final int num = 1; - final byte[] buf = new byte[size]; - generator.nextBytes(buf, -1, num); - } - @Test(expected=IndexOutOfBoundsException.class) - public void testPreconditionNextBytes2() { - final int size = 10; - final byte[] buf = new byte[size]; - generator.nextBytes(buf, size, 0); - } - @Test(expected=IndexOutOfBoundsException.class) - public void testPreconditionNextBytes3() { - final int size = 10; - final int offset = 2; - final byte[] buf = new byte[size]; - generator.nextBytes(buf, offset, size - offset + 1); - } - @Test(expected=IndexOutOfBoundsException.class) - public void testPreconditionNextBytes4() { - final int size = 10; - final int offset = 1; - final byte[] buf = new byte[size]; - generator.nextBytes(buf, offset, -1); - } - - - // Uniformity tests - - @Test - public void testUniformNextBytesFullBuffer() { - // Value chosen to exercise all the code lines in the - // "nextBytes" methods. - final int size = 23; - final byte[] buffer = new byte[size]; - - final Runnable nextMethod = new Runnable() { - @Override - public void run() { - generator.nextBytes(buffer); - } - }; - - Assert.assertTrue(isUniformNextBytes(buffer, 0, size, nextMethod)); - } - - @Test - public void testUniformNextBytesPartialBuffer() { - final int totalSize = 1234; - final int offset = 567; - final int size = 89; - - final byte[] buffer = new byte[totalSize]; - - final Runnable nextMethod = new Runnable() { - @Override - public void run() { - generator.nextBytes(buffer, offset, size); - } - }; - - // Test should pass for the part of the buffer where values are put. - Assert.assertTrue(isUniformNextBytes(buffer, offset, offset + size, nextMethod)); - - // Test must fail for the parts of the buffer where no values are put. - Assert.assertFalse(isUniformNextBytes(buffer, 0, offset, nextMethod)); - Assert.assertFalse(isUniformNextBytes(buffer, offset + size, buffer.length, nextMethod)); - } - - @Test - public void testUniformNextIntegerInRange() { - checkNextIntegerInRange(4, 1000); - checkNextIntegerInRange(10, 1000); - checkNextIntegerInRange(12, 1000); - checkNextIntegerInRange(31, 1000); - checkNextIntegerInRange(32, 1000); - checkNextIntegerInRange(2016128993, 1000); - checkNextIntegerInRange(1834691456, 1000); - checkNextIntegerInRange(869657561, 1000); - checkNextIntegerInRange(1570504788, 1000); - } - - @Test - public void testUniformNextLongInRange() { - checkNextLongInRange(4, 1000); - checkNextLongInRange(11, 1000); - checkNextLongInRange(19, 1000); - checkNextLongInRange(31, 1000); - checkNextLongInRange(32, 1000); - - final long q = Long.MAX_VALUE / 4; - checkNextLongInRange(q, 1000); - checkNextLongInRange(2 * q, 1000); - checkNextLongInRange(3 * q, 1000); - } - - @Test - public void testUniformNextFloat() { - checkNextFloat(1000); - } - - @Test - public void testUniformNextDouble() { - checkNextDouble(1000); - } - - @Test - public void testUniformNextIntRandomWalk() { - final Callable<Boolean> nextMethod = new Callable<Boolean>() { - @Override - public Boolean call() throws Exception { - return generator.nextInt() >= 0; - } - }; - - checkRandomWalk(1000, nextMethod); - } - - @Test - public void testUniformNextLongRandomWalk() { - final Callable<Boolean> nextMethod = new Callable<Boolean>() { - @Override - public Boolean call() throws Exception { - return generator.nextLong() >= 0; - } - }; - - checkRandomWalk(1000, nextMethod); - } - - @Test - public void testUniformNextBooleanRandomWalk() { - final Callable<Boolean> nextMethod = new Callable<Boolean>() { - @Override - public Boolean call() throws Exception { - return generator.nextBoolean(); - } - }; - - checkRandomWalk(1000, nextMethod); - } - - // State save and restore tests. - - @Test - public void testStateSettable() { - // Should be fairly large in order to ensure that all the internal - // state is away from its initial settings. - final int n = 10000; - - // Save. - final RandomProviderState state = generator.saveState(); - // Store some values. - final List<Number> listOrig = makeList(n); - // Discard a few more. - final List<Number> listDiscard = makeList(n); - Assert.assertTrue(listDiscard.size() != 0); - Assert.assertFalse(listOrig.equals(listDiscard)); - // Reset. - generator.restoreState(state); - // Replay. - final List<Number> listReplay = makeList(n); - Assert.assertFalse(listOrig == listReplay); - // Check that the restored state is the same as the orginal. - Assert.assertTrue(listOrig.equals(listReplay)); - } - - @Test(expected=IllegalArgumentException.class) - public void testStateWrongSize() { - // We don't know what is the state of "java.lang.Random": skipping. - Assume.assumeTrue(generator.toString().indexOf("JDKRandom") == -1); - - final RandomProviderState state = new DummyGenerator().saveState(); - // Try to restore with an invalid state (wrong size). - generator.restoreState(state); - } - - @Test(expected=IllegalArgumentException.class) - public void testRestoreForeignState() { - generator.restoreState(new RandomProviderState() {}); - } - - - ///// Support methods below. - - /** - * Populates a list with random numbers. - * - * @param n Loop counter. - * @return a list containing {@code 11 * n} random numbers. - */ - private List<Number> makeList(int n) { - final List<Number> list = new ArrayList<Number>(); - - for (int i = 0; i < n; i++) { - // Append 11 values. - list.add(generator.nextInt()); - list.add(generator.nextInt(21)); - list.add(generator.nextInt(436)); - list.add(generator.nextLong()); - list.add(generator.nextLong(157894)); - list.add(generator.nextLong(5745833)); - list.add(generator.nextFloat()); - list.add(generator.nextFloat()); - list.add(generator.nextDouble()); - list.add(generator.nextDouble()); - list.add(generator.nextDouble()); - } - - return list; - } - - /** - * Checks that the generator values can be placed into 256 bins with - * approximately equal number of counts. - * Test allows to select only part of the buffer for performing the - * statistics. - * - * @param buffer Buffer to be filled. - * @param first First element (included) of {@code buffer} range for - * which statistics must be taken into account. - * @param last Last element (excluded) of {@code buffer} range for - * which statistics must be taken into account. - * @param nextMethod Method that fills the given {@code buffer}. - * @return {@code true} if the distribution is uniform. - */ - private boolean isUniformNextBytes(byte[] buffer, - int first, - int last, - Runnable nextMethod) { - final int sampleSize = 10000; - - // Number of possible values (do not change). - final int byteRange = 256; - // Chi-square critical value with 256 degrees of freedom - // and 1% significance level. - final double chi2CriticalValue = 311.560343; - // To transform a byte value into its bin index. - final int byteRangeOffset = 128; - - // Bins. - final long[] observed = new long[byteRange]; - final double[] expected = new double[byteRange]; - - for (int i = 0; i < byteRange; i++) { - expected[i] = sampleSize * (last - first) / (double) byteRange; - } - - try { - for (int k = 0; k < sampleSize; k++) { - nextMethod.run(); - - for (int i = first; i < last; i++) { - final byte b = buffer[i]; - ++observed[b + byteRangeOffset]; - } - } - } catch (Exception e) { - // Should never happen. - throw new RuntimeException("Unexpected"); - } - - // Compute chi-square. - double chi2 = 0; - for (int k = 0; k < byteRange; k++) { - final double diff = observed[k] - expected[k]; - chi2 += diff * diff / expected[k]; - } - - // Statistics check. - return chi2 < chi2CriticalValue; - } - - /** - * Checks that the generator values can be placed into 2 bins with - * approximately equal number of counts. - * The test uses the expectation from a fixed-step "random walk". - * - * @param nextMethod Method that returns {@code true} if the generated - * values are to be placed in the first bin, {@code false} if it must - * go to the second bin. - */ - private void checkRandomWalk(int sampleSize, - Callable<Boolean> nextMethod) { - int walk = 0; - - try { - for (int k = 0; k < sampleSize; ++k) { - if (nextMethod.call()) { - ++walk; - } else { - --walk; - } - } - } catch (Exception e) { - // Should never happen. - throw new RuntimeException("Unexpected"); - } - - final double actual = Math.abs(walk); - final double max = Math.sqrt(sampleSize) * 2.576; - Assert.assertTrue(generator + ": Walked too far astray: " + actual + - " > " + max + - " (test will fail randomly about 1 in 100 times)", - actual < max); - } - - /** - * Tests uniformity of the distribution produced by {@code nextInt(int)}. - * - * @param max Upper bound. - * @param sampleSize Number of random values generated. - */ - private void checkNextIntegerInRange(final int max, - int sampleSize) { - checkNextIntegerInRange(generator, max, sampleSize); - } - - /** - * Tests uniformity of the distribution produced by {@code nextInt(int)}. - * - * @param rng Generator. - * @param max Upper bound. - * @param sampleSize Number of random values generated. - */ - private void checkNextIntegerInRange(final UniformRandomProvider rng, - final int max, - int sampleSize) { - final Callable<Integer> nextMethod = new Callable<Integer>() { - @Override - public Integer call() throws Exception { - return rng.nextInt(max); - } - }; - - checkNextInRange(max, sampleSize, nextMethod); - } - - /** - * Tests uniformity of the distribution produced by {@code nextLong(long)}. - * - * @param max Upper bound. - * @param sampleSize Number of random values generated. - */ - private void checkNextLongInRange(final long max, - int sampleSize) { - final Callable<Long> nextMethod = new Callable<Long>() { - @Override - public Long call() throws Exception { - return generator.nextLong(max); - } - }; - - checkNextInRange(max, sampleSize, nextMethod); - } - - /** - * Tests uniformity of the distribution produced by {@code nextFloat()}. - * - * @param sampleSize Number of random values generated. - */ - private void checkNextFloat(int sampleSize) { - final int max = 1234; - final Callable<Integer> nextMethod = new Callable<Integer>() { - @Override - public Integer call() throws Exception { - return (int) (max * generator.nextFloat()); - } - }; - - checkNextInRange(max, sampleSize, nextMethod); - } - - /** - * Tests uniformity of the distribution produced by {@code nextDouble()}. - * - * @param sampleSize Number of random values generated. - */ - private void checkNextDouble(int sampleSize) { - final int max = 578; - final Callable<Integer> nextMethod = new Callable<Integer>() { - @Override - public Integer call() throws Exception { - return (int) (max * generator.nextDouble()); - } - }; - - checkNextInRange(max, sampleSize, nextMethod); - } - - /** - * Tests uniformity of the distribution produced by the given - * {@code nextMethod}. - * It performs a chi-square test of homogeneity of the observed - * distribution with the expected uniform distribution. - * Tests are performed at the 1% level and an average failure rate - * higher than 2% causes the test case to fail. - * - * @param max Upper bound. - * @param nextMethod method to call. - * @param sampleSize Number of random values generated. - */ - private <T extends Number> void checkNextInRange(T max, - int sampleSize, - Callable<T> nextMethod) { - final int numTests = 500; - - // Do not change (statistical test assumes that dof = 9). - final int numBins = 10; // dof = numBins - 1 - - // Set up bins. - final long n = max.longValue(); - final long[] binUpperBounds = new long[numBins]; - final double step = n / (double) numBins; - for (int k = 0; k < numBins; k++) { - binUpperBounds[k] = (long) ((k + 1) * step); - } - - // Run the tests. - int numFailures = 0; - - final double[] expected = new double[numBins]; - long previousUpperBound = 0; - for (int k = 0; k < numBins; k++) { - final long range = binUpperBounds[k] - previousUpperBound; - expected[k] = sampleSize * (range / (double) n); - previousUpperBound = binUpperBounds[k]; - } - - final int[] observed = new int[numBins]; - // Chi-square critical value with 9 degrees of freedom - // and 1% significance level. - final double chi2CriticalValue = 21.67; - - try { - for (int i = 0; i < numTests; i++) { - Arrays.fill(observed, 0); - for (int j = 0; j < sampleSize; j++) { - final long value = nextMethod.call().longValue(); - Assert.assertTrue("Range", (value >= 0) && (value < n)); - - for (int k = 0; k < numBins; k++) { - if (value < binUpperBounds[k]) { - ++observed[k]; - break; - } - } - } - - // Compute chi-square. - double chi2 = 0; - for (int k = 0; k < numBins; k++) { - final double diff = observed[k] - expected[k]; - chi2 += diff * diff / expected[k]; - } - - // Statistics check. - if (chi2 > chi2CriticalValue) { - ++numFailures; - } - } - } catch (Exception e) { - // Should never happen. - throw new RuntimeException("Unexpected", e); - } - - if ((double) numFailures / (double) numTests > 0.02) { - Assert.fail(generator + ": Too many failures for n = " + n + - " (" + numFailures + " out of " + numTests + " tests failed)"); - } - } - - /** - * @param rng Generator. - * @param chunkSize Size of the small buffer. - * @param numChunks Number of chunks that make the large buffer. - */ - static void checkNextBytesChunks(RestorableUniformRandomProvider rng, - int chunkSize, - int numChunks) { - final byte[] b1 = new byte[chunkSize * numChunks]; - final byte[] b2 = new byte[chunkSize]; - - final RandomProviderState state = rng.saveState(); - - // Generate the chunks in a single call. - rng.nextBytes(b1); - - // Reset to previous state. - rng.restoreState(state); - - // Generate the chunks in consecutive calls. - for (int i = 0; i < numChunks; i++) { - rng.nextBytes(b2); - } - - // Store last "chunkSize" bytes 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); - } -} - -/** - * Dummy class for checking that restoring fails when an invalid state is used. - */ -class DummyGenerator extends org.apache.commons.rng.core.source32.IntProvider { - /** {@inheritDoc} */ - @Override - public int next() { - return 4; // https://www.xkcd.com/221/ - } - - /** {@inheritDoc} */ - @Override - protected byte[] getStateInternal() { - return new byte[0]; - } - - /** {@inheritDoc} */ - @Override - protected void setStateInternal(byte[] s) { - // No state. - } -} http://git-wip-us.apache.org/repos/asf/commons-rng/blob/954a8f2e/commons-rng-core/src/test/java/org/apache/commons/rng/ProvidersList.java ---------------------------------------------------------------------- diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/ProvidersList.java b/commons-rng-core/src/test/java/org/apache/commons/rng/ProvidersList.java deleted file mode 100644 index c9b520e..0000000 --- a/commons-rng-core/src/test/java/org/apache/commons/rng/ProvidersList.java +++ /dev/null @@ -1,138 +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.rng; - -import java.util.Arrays; -import java.util.List; -import java.util.ArrayList; -import java.util.Collections; - -import org.apache.commons.rng.core.source32.JDKRandom; -import org.apache.commons.rng.core.source32.Well512a; -import org.apache.commons.rng.core.source32.Well1024a; -import org.apache.commons.rng.core.source32.Well19937a; -import org.apache.commons.rng.core.source32.Well19937c; -import org.apache.commons.rng.core.source32.Well44497a; -import org.apache.commons.rng.core.source32.Well44497b; -import org.apache.commons.rng.core.source32.ISAACRandom; -import org.apache.commons.rng.core.source32.MersenneTwister; -import org.apache.commons.rng.core.source32.MultiplyWithCarry256; -import org.apache.commons.rng.core.source32.KISSRandom; -import org.apache.commons.rng.core.source64.SplitMix64; -import org.apache.commons.rng.core.source64.XorShift1024Star; -import org.apache.commons.rng.core.source64.TwoCmres; -import org.apache.commons.rng.core.source64.MersenneTwister64; - -/** - * The purpose of this class is to provide the list of all generators - * implemented in the library. - * The list must be updated with each new RNG implementation. - * - * @see #list() - * @see #list32() - * @see #list64() - */ -public class ProvidersList { - /** List of all RNGs implemented in the library. */ - private static final List<RestorableUniformRandomProvider[]> LIST = - new ArrayList<RestorableUniformRandomProvider[]>(); - /** List of 32-bits based RNGs. */ - private static final List<RestorableUniformRandomProvider[]> LIST32 = - new ArrayList<RestorableUniformRandomProvider[]>(); - /** List of 64-bits based RNGs. */ - private static final List<RestorableUniformRandomProvider[]> LIST64 = - new ArrayList<RestorableUniformRandomProvider[]>(); - - static { - try { - // "int"-based RNGs. - add(LIST32, new JDKRandom(-122333444455555L)); - add(LIST32, new MersenneTwister(new int[] { -123, -234, -345 })); - add(LIST32, new Well512a(new int[] { -23, -34, -45 })); - add(LIST32, new Well1024a(new int[] { -1234, -2345, -3456 })); - add(LIST32, new Well19937a(new int[] { -2123, -3234, -4345 })); - add(LIST32, new Well19937c(new int[] { -123, -234, -345, -456 })); - add(LIST32, new Well44497a(new int[] { -12345, -23456, -34567 })); - add(LIST32, new Well44497b(new int[] { 123, 234, 345 })); - add(LIST32, new ISAACRandom(new int[] { 123, -234, 345, -456 })); - add(LIST32, new MultiplyWithCarry256(new int[] { 12, -1234, -3456, 45679 })); - add(LIST32, new KISSRandom(new int[] { 12, 1234, 23456, 345678 })); - // ... add more here. - - // "long"-based RNGs. - add(LIST64, new SplitMix64(-98877766544333L)); - add(LIST64, new XorShift1024Star(new long[] { 123456L, 234567L, -345678L })); - add(LIST64, new TwoCmres(55443322)); - add(LIST64, new TwoCmres(-987654321, 5, 8)); - add(LIST64, new MersenneTwister64(new long[] { 1234567L, 2345678L, -3456789L })); - // ... add more here. - - // Do not modify the remaining statements. - // Complete list. - LIST.addAll(LIST32); - LIST.addAll(LIST64); - } catch (Exception e) { - System.err.println("Unexpected exception while creating the list of generators: " + e); - e.printStackTrace(System.err); - throw new RuntimeException(e); - } - } - - /** - * Class contains only static methods. - */ - private ProvidersList() {} - - /** - * Helper to statisfy Junit requirement that each parameter set contains - * the same number of objects. - */ - private static void add(List<RestorableUniformRandomProvider[]> list, - RestorableUniformRandomProvider rng) { - list.add(new RestorableUniformRandomProvider[] { rng }); - } - - /** - * Subclasses that are "parametric" tests can forward the call to - * the "@Parameters"-annotated method to this method. - * - * @return the list of all generators. - */ - public static Iterable<RestorableUniformRandomProvider[]> list() { - return Collections.unmodifiableList(LIST); - } - - /** - * Subclasses that are "parametric" tests can forward the call to - * the "@Parameters"-annotated method to this method. - * - * @return the list of 32-bits based generators. - */ - public static Iterable<RestorableUniformRandomProvider[]> list32() { - return Collections.unmodifiableList(LIST32); - } - - /** - * Subclasses that are "parametric" tests can forward the call to - * the "@Parameters"-annotated method to this method. - * - * @return the list of 64-bits based generators. - */ - public static Iterable<RestorableUniformRandomProvider[]> list64() { - return Collections.unmodifiableList(LIST64); - } -} http://git-wip-us.apache.org/repos/asf/commons-rng/blob/954a8f2e/commons-rng-core/src/test/java/org/apache/commons/rng/RandomAssert.java ---------------------------------------------------------------------- diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/RandomAssert.java b/commons-rng-core/src/test/java/org/apache/commons/rng/RandomAssert.java deleted file mode 100644 index d62f78b..0000000 --- a/commons-rng-core/src/test/java/org/apache/commons/rng/RandomAssert.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.rng; - -import java.util.Arrays; -import org.junit.Assert; - -public class RandomAssert { - - public static void assertEquals(int[] expected, UniformRandomProvider rng) { - for (int i = 0; i < expected.length; i++) { - Assert.assertEquals("Value at position " + i, expected[i], rng.nextInt()); - } - } - - public static void assertEquals(long[] expected, UniformRandomProvider rng) { - for (int i = 0; i < expected.length; i++) { - Assert.assertEquals("Value at position " + i, expected[i], rng.nextLong()); - } - } -} http://git-wip-us.apache.org/repos/asf/commons-rng/blob/954a8f2e/commons-rng-core/src/test/java/org/apache/commons/rng/core/BaseProviderTest.java ---------------------------------------------------------------------- diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/core/BaseProviderTest.java b/commons-rng-core/src/test/java/org/apache/commons/rng/core/BaseProviderTest.java index 243e3af..6fc9ed2 100644 --- a/commons-rng-core/src/test/java/org/apache/commons/rng/core/BaseProviderTest.java +++ b/commons-rng-core/src/test/java/org/apache/commons/rng/core/BaseProviderTest.java @@ -73,33 +73,33 @@ public class BaseProviderTest { Assert.assertNotEquals(0, state[i]); } } -} -/** - * Dummy class for checking the behaviour of - * <ul> - * <li>an incomplete implementation</li> - * <li>{@code fillState} methods with "protected" access</li> - * </ul> - */ -class DummyGenerator extends org.apache.commons.rng.core.source32.IntProvider { - /** {@inheritDoc} */ - @Override - public int next() { - return 4; // https://www.xkcd.com/221/ - } + /** + * Dummy class for checking the behaviour of + * <ul> + * <li>an incomplete implementation</li> + * <li>{@code fillState} methods with "protected" access</li> + * </ul> + */ + class DummyGenerator extends org.apache.commons.rng.core.source32.IntProvider { + /** {@inheritDoc} */ + @Override + public int next() { + return 4; // https://www.xkcd.com/221/ + } - // Missing overrides of "setStateInternal" and "getStateInternal". + // Missing overrides of "setStateInternal" and "getStateInternal". - /** {@inheritDoc} */ - @Override - public void fillState(int[] state, int[] seed) { - super.fillState(state, seed); - } + /** {@inheritDoc} */ + @Override + public void fillState(int[] state, int[] seed) { + super.fillState(state, seed); + } - /** {@inheritDoc} */ - @Override - public void fillState(long[] state, long[] seed) { - super.fillState(state, seed); + /** {@inheritDoc} */ + @Override + public void fillState(long[] state, long[] seed) { + super.fillState(state, seed); + } } } http://git-wip-us.apache.org/repos/asf/commons-rng/blob/954a8f2e/commons-rng-core/src/test/java/org/apache/commons/rng/core/Providers32ParametricTest.java ---------------------------------------------------------------------- diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/core/Providers32ParametricTest.java b/commons-rng-core/src/test/java/org/apache/commons/rng/core/Providers32ParametricTest.java new file mode 100644 index 0000000..726fa52 --- /dev/null +++ b/commons-rng-core/src/test/java/org/apache/commons/rng/core/Providers32ParametricTest.java @@ -0,0 +1,60 @@ +/* + * 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.rng.core; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +import org.apache.commons.rng.RestorableUniformRandomProvider; + +/** + * Tests which all 32-bits based generators must pass. + */ +@RunWith(value=Parameterized.class) +public class Providers32ParametricTest { + /** RNG under test. */ + private final RestorableUniformRandomProvider generator; + + /** + * Initializes generator instance. + * + * @param rng RNG to be tested. + */ + public Providers32ParametricTest(RestorableUniformRandomProvider rng) { + generator = rng; + } + + @Parameters(name = "{index}: data={0}") + public static Iterable<RestorableUniformRandomProvider[]> getList() { + return ProvidersList.list32(); + } + + @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) { + ProvidersCommonParametricTest.checkNextBytesChunks(generator, + chunkSize, + numChunks); + } + } + } +} http://git-wip-us.apache.org/repos/asf/commons-rng/blob/954a8f2e/commons-rng-core/src/test/java/org/apache/commons/rng/core/Providers64ParametricTest.java ---------------------------------------------------------------------- diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/core/Providers64ParametricTest.java b/commons-rng-core/src/test/java/org/apache/commons/rng/core/Providers64ParametricTest.java new file mode 100644 index 0000000..d3445de --- /dev/null +++ b/commons-rng-core/src/test/java/org/apache/commons/rng/core/Providers64ParametricTest.java @@ -0,0 +1,60 @@ +/* + * 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.rng.core; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +import org.apache.commons.rng.RestorableUniformRandomProvider; + +/** + * Tests which all 64-bits based generators must pass. + */ +@RunWith(value=Parameterized.class) +public class Providers64ParametricTest { + /** RNG under test. */ + private final RestorableUniformRandomProvider generator; + + /** + * Initializes generator instance. + * + * @param rng RNG to be tested. + */ + public Providers64ParametricTest(RestorableUniformRandomProvider rng) { + generator = rng; + } + + @Parameters(name = "{index}: data={0}") + public static Iterable<RestorableUniformRandomProvider[]> getList() { + return ProvidersList.list64(); + } + + @Test + public void testNextBytesChunks() { + final int[] chunkSizes = { 8, 16, 24 }; + final int[] chunks = { 1, 2, 3, 4, 5 }; + for (int chunkSize : chunkSizes) { + for (int numChunks : chunks) { + ProvidersCommonParametricTest.checkNextBytesChunks(generator, + chunkSize, + numChunks); + } + } + } +} http://git-wip-us.apache.org/repos/asf/commons-rng/blob/954a8f2e/commons-rng-core/src/test/java/org/apache/commons/rng/core/ProvidersCommonParametricTest.java ---------------------------------------------------------------------- diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/core/ProvidersCommonParametricTest.java b/commons-rng-core/src/test/java/org/apache/commons/rng/core/ProvidersCommonParametricTest.java new file mode 100644 index 0000000..6e27c15 --- /dev/null +++ b/commons-rng-core/src/test/java/org/apache/commons/rng/core/ProvidersCommonParametricTest.java @@ -0,0 +1,615 @@ +/* + * 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.rng.core; + +import java.util.Arrays; +import java.util.List; +import java.util.ArrayList; +import java.util.concurrent.Callable; +import java.io.IOException; +import java.io.ObjectOutputStream; +import java.io.ObjectInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ByteArrayInputStream; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.Assume; +import org.junit.Ignore; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +import org.apache.commons.rng.UniformRandomProvider; +import org.apache.commons.rng.RestorableUniformRandomProvider; +import org.apache.commons.rng.RandomProviderState; + +/** + * Tests which all generators must pass. + */ +@RunWith(value=Parameterized.class) +public class ProvidersCommonParametricTest { + /** RNG under test. */ + private final RestorableUniformRandomProvider generator; + + /** + * Initializes generator instance. + * + * @param rng RNG to be tested. + */ + public ProvidersCommonParametricTest(RestorableUniformRandomProvider rng) { + generator = rng; + } + + @Parameters(name = "{index}: data={0}") + public static Iterable<RestorableUniformRandomProvider[]> getList() { + return ProvidersList.list(); + } + + + // Precondition tests + + @Test(expected=IllegalArgumentException.class) + public void testPreconditionNextInt1() { + generator.nextInt(-1); + } + + @Test(expected=IllegalArgumentException.class) + public void testPreconditionNextInt2() { + generator.nextInt(0); + } + + @Test(expected=IllegalArgumentException.class) + public void testPreconditionNextLong1() { + generator.nextLong(-1); + } + + @Test(expected=IllegalArgumentException.class) + public void testPreconditionNextLong2() { + generator.nextLong(0); + } + + @Test(expected=IndexOutOfBoundsException.class) + public void testPreconditionNextBytes1() { + final int size = 10; + final int num = 1; + final byte[] buf = new byte[size]; + generator.nextBytes(buf, -1, num); + } + @Test(expected=IndexOutOfBoundsException.class) + public void testPreconditionNextBytes2() { + final int size = 10; + final byte[] buf = new byte[size]; + generator.nextBytes(buf, size, 0); + } + @Test(expected=IndexOutOfBoundsException.class) + public void testPreconditionNextBytes3() { + final int size = 10; + final int offset = 2; + final byte[] buf = new byte[size]; + generator.nextBytes(buf, offset, size - offset + 1); + } + @Test(expected=IndexOutOfBoundsException.class) + public void testPreconditionNextBytes4() { + final int size = 10; + final int offset = 1; + final byte[] buf = new byte[size]; + generator.nextBytes(buf, offset, -1); + } + + + // Uniformity tests + + @Test + public void testUniformNextBytesFullBuffer() { + // Value chosen to exercise all the code lines in the + // "nextBytes" methods. + final int size = 23; + final byte[] buffer = new byte[size]; + + final Runnable nextMethod = new Runnable() { + @Override + public void run() { + generator.nextBytes(buffer); + } + }; + + Assert.assertTrue(isUniformNextBytes(buffer, 0, size, nextMethod)); + } + + @Test + public void testUniformNextBytesPartialBuffer() { + final int totalSize = 1234; + final int offset = 567; + final int size = 89; + + final byte[] buffer = new byte[totalSize]; + + final Runnable nextMethod = new Runnable() { + @Override + public void run() { + generator.nextBytes(buffer, offset, size); + } + }; + + // Test should pass for the part of the buffer where values are put. + Assert.assertTrue(isUniformNextBytes(buffer, offset, offset + size, nextMethod)); + + // Test must fail for the parts of the buffer where no values are put. + Assert.assertFalse(isUniformNextBytes(buffer, 0, offset, nextMethod)); + Assert.assertFalse(isUniformNextBytes(buffer, offset + size, buffer.length, nextMethod)); + } + + @Test + public void testUniformNextIntegerInRange() { + checkNextIntegerInRange(4, 1000); + checkNextIntegerInRange(10, 1000); + checkNextIntegerInRange(12, 1000); + checkNextIntegerInRange(31, 1000); + checkNextIntegerInRange(32, 1000); + checkNextIntegerInRange(2016128993, 1000); + checkNextIntegerInRange(1834691456, 1000); + checkNextIntegerInRange(869657561, 1000); + checkNextIntegerInRange(1570504788, 1000); + } + + @Test + public void testUniformNextLongInRange() { + checkNextLongInRange(4, 1000); + checkNextLongInRange(11, 1000); + checkNextLongInRange(19, 1000); + checkNextLongInRange(31, 1000); + checkNextLongInRange(32, 1000); + + final long q = Long.MAX_VALUE / 4; + checkNextLongInRange(q, 1000); + checkNextLongInRange(2 * q, 1000); + checkNextLongInRange(3 * q, 1000); + } + + @Test + public void testUniformNextFloat() { + checkNextFloat(1000); + } + + @Test + public void testUniformNextDouble() { + checkNextDouble(1000); + } + + @Test + public void testUniformNextIntRandomWalk() { + final Callable<Boolean> nextMethod = new Callable<Boolean>() { + @Override + public Boolean call() throws Exception { + return generator.nextInt() >= 0; + } + }; + + checkRandomWalk(1000, nextMethod); + } + + @Test + public void testUniformNextLongRandomWalk() { + final Callable<Boolean> nextMethod = new Callable<Boolean>() { + @Override + public Boolean call() throws Exception { + return generator.nextLong() >= 0; + } + }; + + checkRandomWalk(1000, nextMethod); + } + + @Test + public void testUniformNextBooleanRandomWalk() { + final Callable<Boolean> nextMethod = new Callable<Boolean>() { + @Override + public Boolean call() throws Exception { + return generator.nextBoolean(); + } + }; + + checkRandomWalk(1000, nextMethod); + } + + // State save and restore tests. + + @Test + public void testStateSettable() { + // Should be fairly large in order to ensure that all the internal + // state is away from its initial settings. + final int n = 10000; + + // Save. + final RandomProviderState state = generator.saveState(); + // Store some values. + final List<Number> listOrig = makeList(n); + // Discard a few more. + final List<Number> listDiscard = makeList(n); + Assert.assertTrue(listDiscard.size() != 0); + Assert.assertFalse(listOrig.equals(listDiscard)); + // Reset. + generator.restoreState(state); + // Replay. + final List<Number> listReplay = makeList(n); + Assert.assertFalse(listOrig == listReplay); + // Check that the restored state is the same as the orginal. + Assert.assertTrue(listOrig.equals(listReplay)); + } + + @Test(expected=IllegalArgumentException.class) + public void testStateWrongSize() { + // We don't know what is the state of "java.lang.Random": skipping. + Assume.assumeTrue(generator.toString().indexOf("JDKRandom") == -1); + + final RandomProviderState state = new DummyGenerator().saveState(); + // Try to restore with an invalid state (wrong size). + generator.restoreState(state); + } + + @Test(expected=IllegalArgumentException.class) + public void testRestoreForeignState() { + generator.restoreState(new RandomProviderState() {}); + } + + + ///// Support methods below. + + /** + * Populates a list with random numbers. + * + * @param n Loop counter. + * @return a list containing {@code 11 * n} random numbers. + */ + private List<Number> makeList(int n) { + final List<Number> list = new ArrayList<Number>(); + + for (int i = 0; i < n; i++) { + // Append 11 values. + list.add(generator.nextInt()); + list.add(generator.nextInt(21)); + list.add(generator.nextInt(436)); + list.add(generator.nextLong()); + list.add(generator.nextLong(157894)); + list.add(generator.nextLong(5745833)); + list.add(generator.nextFloat()); + list.add(generator.nextFloat()); + list.add(generator.nextDouble()); + list.add(generator.nextDouble()); + list.add(generator.nextDouble()); + } + + return list; + } + + /** + * Checks that the generator values can be placed into 256 bins with + * approximately equal number of counts. + * Test allows to select only part of the buffer for performing the + * statistics. + * + * @param buffer Buffer to be filled. + * @param first First element (included) of {@code buffer} range for + * which statistics must be taken into account. + * @param last Last element (excluded) of {@code buffer} range for + * which statistics must be taken into account. + * @param nextMethod Method that fills the given {@code buffer}. + * @return {@code true} if the distribution is uniform. + */ + private boolean isUniformNextBytes(byte[] buffer, + int first, + int last, + Runnable nextMethod) { + final int sampleSize = 10000; + + // Number of possible values (do not change). + final int byteRange = 256; + // Chi-square critical value with 256 degrees of freedom + // and 1% significance level. + final double chi2CriticalValue = 311.560343; + // To transform a byte value into its bin index. + final int byteRangeOffset = 128; + + // Bins. + final long[] observed = new long[byteRange]; + final double[] expected = new double[byteRange]; + + for (int i = 0; i < byteRange; i++) { + expected[i] = sampleSize * (last - first) / (double) byteRange; + } + + try { + for (int k = 0; k < sampleSize; k++) { + nextMethod.run(); + + for (int i = first; i < last; i++) { + final byte b = buffer[i]; + ++observed[b + byteRangeOffset]; + } + } + } catch (Exception e) { + // Should never happen. + throw new RuntimeException("Unexpected"); + } + + // Compute chi-square. + double chi2 = 0; + for (int k = 0; k < byteRange; k++) { + final double diff = observed[k] - expected[k]; + chi2 += diff * diff / expected[k]; + } + + // Statistics check. + return chi2 < chi2CriticalValue; + } + + /** + * Checks that the generator values can be placed into 2 bins with + * approximately equal number of counts. + * The test uses the expectation from a fixed-step "random walk". + * + * @param nextMethod Method that returns {@code true} if the generated + * values are to be placed in the first bin, {@code false} if it must + * go to the second bin. + */ + private void checkRandomWalk(int sampleSize, + Callable<Boolean> nextMethod) { + int walk = 0; + + try { + for (int k = 0; k < sampleSize; ++k) { + if (nextMethod.call()) { + ++walk; + } else { + --walk; + } + } + } catch (Exception e) { + // Should never happen. + throw new RuntimeException("Unexpected"); + } + + final double actual = Math.abs(walk); + final double max = Math.sqrt(sampleSize) * 2.576; + Assert.assertTrue(generator + ": Walked too far astray: " + actual + + " > " + max + + " (test will fail randomly about 1 in 100 times)", + actual < max); + } + + /** + * Tests uniformity of the distribution produced by {@code nextInt(int)}. + * + * @param max Upper bound. + * @param sampleSize Number of random values generated. + */ + private void checkNextIntegerInRange(final int max, + int sampleSize) { + checkNextIntegerInRange(generator, max, sampleSize); + } + + /** + * Tests uniformity of the distribution produced by {@code nextInt(int)}. + * + * @param rng Generator. + * @param max Upper bound. + * @param sampleSize Number of random values generated. + */ + private void checkNextIntegerInRange(final UniformRandomProvider rng, + final int max, + int sampleSize) { + final Callable<Integer> nextMethod = new Callable<Integer>() { + @Override + public Integer call() throws Exception { + return rng.nextInt(max); + } + }; + + checkNextInRange(max, sampleSize, nextMethod); + } + + /** + * Tests uniformity of the distribution produced by {@code nextLong(long)}. + * + * @param max Upper bound. + * @param sampleSize Number of random values generated. + */ + private void checkNextLongInRange(final long max, + int sampleSize) { + final Callable<Long> nextMethod = new Callable<Long>() { + @Override + public Long call() throws Exception { + return generator.nextLong(max); + } + }; + + checkNextInRange(max, sampleSize, nextMethod); + } + + /** + * Tests uniformity of the distribution produced by {@code nextFloat()}. + * + * @param sampleSize Number of random values generated. + */ + private void checkNextFloat(int sampleSize) { + final int max = 1234; + final Callable<Integer> nextMethod = new Callable<Integer>() { + @Override + public Integer call() throws Exception { + return (int) (max * generator.nextFloat()); + } + }; + + checkNextInRange(max, sampleSize, nextMethod); + } + + /** + * Tests uniformity of the distribution produced by {@code nextDouble()}. + * + * @param sampleSize Number of random values generated. + */ + private void checkNextDouble(int sampleSize) { + final int max = 578; + final Callable<Integer> nextMethod = new Callable<Integer>() { + @Override + public Integer call() throws Exception { + return (int) (max * generator.nextDouble()); + } + }; + + checkNextInRange(max, sampleSize, nextMethod); + } + + /** + * Tests uniformity of the distribution produced by the given + * {@code nextMethod}. + * It performs a chi-square test of homogeneity of the observed + * distribution with the expected uniform distribution. + * Tests are performed at the 1% level and an average failure rate + * higher than 2% causes the test case to fail. + * + * @param max Upper bound. + * @param nextMethod method to call. + * @param sampleSize Number of random values generated. + */ + private <T extends Number> void checkNextInRange(T max, + int sampleSize, + Callable<T> nextMethod) { + final int numTests = 500; + + // Do not change (statistical test assumes that dof = 9). + final int numBins = 10; // dof = numBins - 1 + + // Set up bins. + final long n = max.longValue(); + final long[] binUpperBounds = new long[numBins]; + final double step = n / (double) numBins; + for (int k = 0; k < numBins; k++) { + binUpperBounds[k] = (long) ((k + 1) * step); + } + + // Run the tests. + int numFailures = 0; + + final double[] expected = new double[numBins]; + long previousUpperBound = 0; + for (int k = 0; k < numBins; k++) { + final long range = binUpperBounds[k] - previousUpperBound; + expected[k] = sampleSize * (range / (double) n); + previousUpperBound = binUpperBounds[k]; + } + + final int[] observed = new int[numBins]; + // Chi-square critical value with 9 degrees of freedom + // and 1% significance level. + final double chi2CriticalValue = 21.67; + + try { + for (int i = 0; i < numTests; i++) { + Arrays.fill(observed, 0); + for (int j = 0; j < sampleSize; j++) { + final long value = nextMethod.call().longValue(); + Assert.assertTrue("Range", (value >= 0) && (value < n)); + + for (int k = 0; k < numBins; k++) { + if (value < binUpperBounds[k]) { + ++observed[k]; + break; + } + } + } + + // Compute chi-square. + double chi2 = 0; + for (int k = 0; k < numBins; k++) { + final double diff = observed[k] - expected[k]; + chi2 += diff * diff / expected[k]; + } + + // Statistics check. + if (chi2 > chi2CriticalValue) { + ++numFailures; + } + } + } catch (Exception e) { + // Should never happen. + throw new RuntimeException("Unexpected", e); + } + + if ((double) numFailures / (double) numTests > 0.02) { + Assert.fail(generator + ": Too many failures for n = " + n + + " (" + numFailures + " out of " + numTests + " tests failed)"); + } + } + + /** + * @param rng Generator. + * @param chunkSize Size of the small buffer. + * @param numChunks Number of chunks that make the large buffer. + */ + static void checkNextBytesChunks(RestorableUniformRandomProvider rng, + int chunkSize, + int numChunks) { + final byte[] b1 = new byte[chunkSize * numChunks]; + final byte[] b2 = new byte[chunkSize]; + + final RandomProviderState state = rng.saveState(); + + // Generate the chunks in a single call. + rng.nextBytes(b1); + + // Reset to previous state. + rng.restoreState(state); + + // Generate the chunks in consecutive calls. + for (int i = 0; i < numChunks; i++) { + rng.nextBytes(b2); + } + + // Store last "chunkSize" bytes 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); + } + + /** + * Dummy class for checking that restoring fails when an invalid state is used. + */ + class DummyGenerator extends org.apache.commons.rng.core.source32.IntProvider { + /** {@inheritDoc} */ + @Override + public int next() { + return 4; // https://www.xkcd.com/221/ + } + + /** {@inheritDoc} */ + @Override + protected byte[] getStateInternal() { + return new byte[0]; + } + + /** {@inheritDoc} */ + @Override + protected void setStateInternal(byte[] s) { + // No state. + } + } +} http://git-wip-us.apache.org/repos/asf/commons-rng/blob/954a8f2e/commons-rng-core/src/test/java/org/apache/commons/rng/core/ProvidersList.java ---------------------------------------------------------------------- diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/core/ProvidersList.java b/commons-rng-core/src/test/java/org/apache/commons/rng/core/ProvidersList.java new file mode 100644 index 0000000..7831940 --- /dev/null +++ b/commons-rng-core/src/test/java/org/apache/commons/rng/core/ProvidersList.java @@ -0,0 +1,139 @@ +/* + * 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.rng.core; + +import java.util.Arrays; +import java.util.List; +import java.util.ArrayList; +import java.util.Collections; + +import org.apache.commons.rng.core.source32.JDKRandom; +import org.apache.commons.rng.core.source32.Well512a; +import org.apache.commons.rng.core.source32.Well1024a; +import org.apache.commons.rng.core.source32.Well19937a; +import org.apache.commons.rng.core.source32.Well19937c; +import org.apache.commons.rng.core.source32.Well44497a; +import org.apache.commons.rng.core.source32.Well44497b; +import org.apache.commons.rng.core.source32.ISAACRandom; +import org.apache.commons.rng.core.source32.MersenneTwister; +import org.apache.commons.rng.core.source32.MultiplyWithCarry256; +import org.apache.commons.rng.core.source32.KISSRandom; +import org.apache.commons.rng.core.source64.SplitMix64; +import org.apache.commons.rng.core.source64.XorShift1024Star; +import org.apache.commons.rng.core.source64.TwoCmres; +import org.apache.commons.rng.core.source64.MersenneTwister64; +import org.apache.commons.rng.RestorableUniformRandomProvider; + +/** + * The purpose of this class is to provide the list of all generators + * implemented in the library. + * The list must be updated with each new RNG implementation. + * + * @see #list() + * @see #list32() + * @see #list64() + */ +public class ProvidersList { + /** List of all RNGs implemented in the library. */ + private static final List<RestorableUniformRandomProvider[]> LIST = + new ArrayList<RestorableUniformRandomProvider[]>(); + /** List of 32-bits based RNGs. */ + private static final List<RestorableUniformRandomProvider[]> LIST32 = + new ArrayList<RestorableUniformRandomProvider[]>(); + /** List of 64-bits based RNGs. */ + private static final List<RestorableUniformRandomProvider[]> LIST64 = + new ArrayList<RestorableUniformRandomProvider[]>(); + + static { + try { + // "int"-based RNGs. + add(LIST32, new JDKRandom(-122333444455555L)); + add(LIST32, new MersenneTwister(new int[] { -123, -234, -345 })); + add(LIST32, new Well512a(new int[] { -23, -34, -45 })); + add(LIST32, new Well1024a(new int[] { -1234, -2345, -3456 })); + add(LIST32, new Well19937a(new int[] { -2123, -3234, -4345 })); + add(LIST32, new Well19937c(new int[] { -123, -234, -345, -456 })); + add(LIST32, new Well44497a(new int[] { -12345, -23456, -34567 })); + add(LIST32, new Well44497b(new int[] { 123, 234, 345 })); + add(LIST32, new ISAACRandom(new int[] { 123, -234, 345, -456 })); + add(LIST32, new MultiplyWithCarry256(new int[] { 12, -1234, -3456, 45679 })); + add(LIST32, new KISSRandom(new int[] { 12, 1234, 23456, 345678 })); + // ... add more here. + + // "long"-based RNGs. + add(LIST64, new SplitMix64(-98877766544333L)); + add(LIST64, new XorShift1024Star(new long[] { 123456L, 234567L, -345678L })); + add(LIST64, new TwoCmres(55443322)); + add(LIST64, new TwoCmres(-987654321, 5, 8)); + add(LIST64, new MersenneTwister64(new long[] { 1234567L, 2345678L, -3456789L })); + // ... add more here. + + // Do not modify the remaining statements. + // Complete list. + LIST.addAll(LIST32); + LIST.addAll(LIST64); + } catch (Exception e) { + System.err.println("Unexpected exception while creating the list of generators: " + e); + e.printStackTrace(System.err); + throw new RuntimeException(e); + } + } + + /** + * Class contains only static methods. + */ + private ProvidersList() {} + + /** + * Helper to statisfy Junit requirement that each parameter set contains + * the same number of objects. + */ + private static void add(List<RestorableUniformRandomProvider[]> list, + RestorableUniformRandomProvider rng) { + list.add(new RestorableUniformRandomProvider[] { rng }); + } + + /** + * Subclasses that are "parametric" tests can forward the call to + * the "@Parameters"-annotated method to this method. + * + * @return the list of all generators. + */ + public static Iterable<RestorableUniformRandomProvider[]> list() { + return Collections.unmodifiableList(LIST); + } + + /** + * Subclasses that are "parametric" tests can forward the call to + * the "@Parameters"-annotated method to this method. + * + * @return the list of 32-bits based generators. + */ + public static Iterable<RestorableUniformRandomProvider[]> list32() { + return Collections.unmodifiableList(LIST32); + } + + /** + * Subclasses that are "parametric" tests can forward the call to + * the "@Parameters"-annotated method to this method. + * + * @return the list of 64-bits based generators. + */ + public static Iterable<RestorableUniformRandomProvider[]> list64() { + return Collections.unmodifiableList(LIST64); + } +} http://git-wip-us.apache.org/repos/asf/commons-rng/blob/954a8f2e/commons-rng-core/src/test/java/org/apache/commons/rng/core/RandomAssert.java ---------------------------------------------------------------------- diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/core/RandomAssert.java b/commons-rng-core/src/test/java/org/apache/commons/rng/core/RandomAssert.java new file mode 100644 index 0000000..0d6e5fd --- /dev/null +++ b/commons-rng-core/src/test/java/org/apache/commons/rng/core/RandomAssert.java @@ -0,0 +1,38 @@ +/* + * 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.rng.core; + +import java.util.Arrays; +import org.junit.Assert; + +import org.apache.commons.rng.UniformRandomProvider; + +public class RandomAssert { + + public static void assertEquals(int[] expected, UniformRandomProvider rng) { + for (int i = 0; i < expected.length; i++) { + Assert.assertEquals("Value at position " + i, expected[i], rng.nextInt()); + } + } + + public static void assertEquals(long[] expected, UniformRandomProvider rng) { + for (int i = 0; i < expected.length; i++) { + Assert.assertEquals("Value at position " + i, expected[i], rng.nextLong()); + } + } +} http://git-wip-us.apache.org/repos/asf/commons-rng/blob/954a8f2e/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/ISAACRandomTest.java ---------------------------------------------------------------------- diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/ISAACRandomTest.java b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/ISAACRandomTest.java index 737c356..766f6a4 100644 --- a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/ISAACRandomTest.java +++ b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/ISAACRandomTest.java @@ -17,7 +17,7 @@ package org.apache.commons.rng.core.source32; -import org.apache.commons.rng.RandomAssert; +import org.apache.commons.rng.core.RandomAssert; import org.junit.Test; public final class ISAACRandomTest { http://git-wip-us.apache.org/repos/asf/commons-rng/blob/954a8f2e/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/KISSRandomTest.java ---------------------------------------------------------------------- diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/KISSRandomTest.java b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/KISSRandomTest.java index 3efe25a..937f991 100644 --- a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/KISSRandomTest.java +++ b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/KISSRandomTest.java @@ -16,7 +16,7 @@ */ package org.apache.commons.rng.core.source32; -import org.apache.commons.rng.RandomAssert; +import org.apache.commons.rng.core.RandomAssert; import org.junit.Test; public class KISSRandomTest { http://git-wip-us.apache.org/repos/asf/commons-rng/blob/954a8f2e/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/MersenneTwisterTest.java ---------------------------------------------------------------------- diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/MersenneTwisterTest.java b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/MersenneTwisterTest.java index d146a8f..c32b099 100644 --- a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/MersenneTwisterTest.java +++ b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/MersenneTwisterTest.java @@ -16,7 +16,7 @@ */ package org.apache.commons.rng.core.source32; -import org.apache.commons.rng.RandomAssert; +import org.apache.commons.rng.core.RandomAssert; import org.junit.Test; public class MersenneTwisterTest { http://git-wip-us.apache.org/repos/asf/commons-rng/blob/954a8f2e/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/MultiplyWithCarry256Test.java ---------------------------------------------------------------------- diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/MultiplyWithCarry256Test.java b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/MultiplyWithCarry256Test.java index fcedfe9..e8f85a6 100644 --- a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/MultiplyWithCarry256Test.java +++ b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/MultiplyWithCarry256Test.java @@ -16,7 +16,7 @@ */ package org.apache.commons.rng.core.source32; -import org.apache.commons.rng.RandomAssert; +import org.apache.commons.rng.core.RandomAssert; import org.junit.Test; public class MultiplyWithCarry256Test { http://git-wip-us.apache.org/repos/asf/commons-rng/blob/954a8f2e/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/Well1024aTest.java ---------------------------------------------------------------------- diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/Well1024aTest.java b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/Well1024aTest.java index df7961b..a44fccb 100644 --- a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/Well1024aTest.java +++ b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/Well1024aTest.java @@ -16,7 +16,7 @@ */ package org.apache.commons.rng.core.source32; -import org.apache.commons.rng.RandomAssert; +import org.apache.commons.rng.core.RandomAssert; import org.junit.Test; public class Well1024aTest { http://git-wip-us.apache.org/repos/asf/commons-rng/blob/954a8f2e/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/Well19937aTest.java ---------------------------------------------------------------------- diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/Well19937aTest.java b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/Well19937aTest.java index 1e7572c..cbda07e 100644 --- a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/Well19937aTest.java +++ b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/Well19937aTest.java @@ -16,7 +16,7 @@ */ package org.apache.commons.rng.core.source32; -import org.apache.commons.rng.RandomAssert; +import org.apache.commons.rng.core.RandomAssert; import org.junit.Test; public class Well19937aTest { http://git-wip-us.apache.org/repos/asf/commons-rng/blob/954a8f2e/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/Well19937cTest.java ---------------------------------------------------------------------- diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/Well19937cTest.java b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/Well19937cTest.java index b5a83d9..a6625e1 100644 --- a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/Well19937cTest.java +++ b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/Well19937cTest.java @@ -16,7 +16,7 @@ */ package org.apache.commons.rng.core.source32; -import org.apache.commons.rng.RandomAssert; +import org.apache.commons.rng.core.RandomAssert; import org.junit.Test; public class Well19937cTest { http://git-wip-us.apache.org/repos/asf/commons-rng/blob/954a8f2e/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/Well44497aTest.java ---------------------------------------------------------------------- diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/Well44497aTest.java b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/Well44497aTest.java index 5a5a20c..1f8177f 100644 --- a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/Well44497aTest.java +++ b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/Well44497aTest.java @@ -16,7 +16,7 @@ */ package org.apache.commons.rng.core.source32; -import org.apache.commons.rng.RandomAssert; +import org.apache.commons.rng.core.RandomAssert; import org.junit.Test; public class Well44497aTest { http://git-wip-us.apache.org/repos/asf/commons-rng/blob/954a8f2e/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/Well44497bTest.java ---------------------------------------------------------------------- diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/Well44497bTest.java b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/Well44497bTest.java index 2cc29c5..de50a40 100644 --- a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/Well44497bTest.java +++ b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/Well44497bTest.java @@ -16,7 +16,7 @@ */ package org.apache.commons.rng.core.source32; -import org.apache.commons.rng.RandomAssert; +import org.apache.commons.rng.core.RandomAssert; import org.junit.Test; public class Well44497bTest { http://git-wip-us.apache.org/repos/asf/commons-rng/blob/954a8f2e/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/Well512aTest.java ---------------------------------------------------------------------- diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/Well512aTest.java b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/Well512aTest.java index 7300832..dac7bab 100644 --- a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/Well512aTest.java +++ b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/Well512aTest.java @@ -16,7 +16,7 @@ */ package org.apache.commons.rng.core.source32; -import org.apache.commons.rng.RandomAssert; +import org.apache.commons.rng.core.RandomAssert; import org.junit.Test; public class Well512aTest { http://git-wip-us.apache.org/repos/asf/commons-rng/blob/954a8f2e/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/MersenneTwister64Test.java ---------------------------------------------------------------------- diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/MersenneTwister64Test.java b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/MersenneTwister64Test.java index 5421550..cc2d4e5 100644 --- a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/MersenneTwister64Test.java +++ b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/MersenneTwister64Test.java @@ -16,7 +16,7 @@ */ package org.apache.commons.rng.core.source64; -import org.apache.commons.rng.RandomAssert; +import org.apache.commons.rng.core.RandomAssert; import org.junit.Test; public class MersenneTwister64Test { http://git-wip-us.apache.org/repos/asf/commons-rng/blob/954a8f2e/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/SplitMix64Test.java ---------------------------------------------------------------------- diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/SplitMix64Test.java b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/SplitMix64Test.java index 87aa1b8..affa81f 100644 --- a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/SplitMix64Test.java +++ b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/SplitMix64Test.java @@ -16,7 +16,7 @@ */ package org.apache.commons.rng.core.source64; -import org.apache.commons.rng.RandomAssert; +import org.apache.commons.rng.core.RandomAssert; import org.junit.Test; public class SplitMix64Test { http://git-wip-us.apache.org/repos/asf/commons-rng/blob/954a8f2e/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/XorShift1024StarTest.java ---------------------------------------------------------------------- diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/XorShift1024StarTest.java b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/XorShift1024StarTest.java index 67717d2..e158393 100644 --- a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/XorShift1024StarTest.java +++ b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/XorShift1024StarTest.java @@ -16,7 +16,7 @@ */ package org.apache.commons.rng.core.source64; -import org.apache.commons.rng.RandomAssert; +import org.apache.commons.rng.core.RandomAssert; import org.junit.Test; public class XorShift1024StarTest {