Unit tests added. Checks that empty array seeds are accepted and that the resulting state (as computed by the default seeding procedure) still produces uniform sequences.
Project: http://git-wip-us.apache.org/repos/asf/commons-rng/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-rng/commit/e15604b5 Tree: http://git-wip-us.apache.org/repos/asf/commons-rng/tree/e15604b5 Diff: http://git-wip-us.apache.org/repos/asf/commons-rng/diff/e15604b5 Branch: refs/heads/master Commit: e15604b51cf21eaf1f2abd11ba027a3b8d6194bd Parents: b42e97d Author: Gilles <[email protected]> Authored: Fri Aug 26 17:59:11 2016 +0200 Committer: Gilles <[email protected]> Committed: Fri Aug 26 17:59:11 2016 +0200 ---------------------------------------------------------------------- .../rng/ProvidersCommonParametricTest.java | 35 +++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-rng/blob/e15604b5/src/test/java/org/apache/commons/rng/ProvidersCommonParametricTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/rng/ProvidersCommonParametricTest.java b/src/test/java/org/apache/commons/rng/ProvidersCommonParametricTest.java index 6ea361a..a7b3fca 100644 --- a/src/test/java/org/apache/commons/rng/ProvidersCommonParametricTest.java +++ b/src/test/java/org/apache/commons/rng/ProvidersCommonParametricTest.java @@ -266,6 +266,26 @@ public class ProvidersCommonParametricTest { Assert.assertEquals(3, nonNativeSeedCount); } + @Test + public void testEmptyIntArraySeed() { + final int[] empty = new int[0]; + Assume.assumeTrue(originalSource.isNativeSeed(empty)); + + // Exercise the default seeding procedure. + final UniformRandomProvider rng = RandomSource.create(originalSource, empty, originalArgs); + checkNextIntegerInRange(rng, 10, 10000); + } + + @Test + public void testEmptyLongArraySeed() { + final long[] empty = new long[0]; + Assume.assumeTrue(originalSource.isNativeSeed(empty)); + + // Exercise the default seeding procedure. + final UniformRandomProvider rng = RandomSource.create(originalSource, empty, originalArgs); + checkNextIntegerInRange(rng, 10, 10000); + } + // State save and restore tests. @Test @@ -472,10 +492,23 @@ public class ProvidersCommonParametricTest { */ 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 generator.nextInt(max); + return rng.nextInt(max); } };
