This is an automated email from the ASF dual-hosted git repository. aherbert pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-rng.git
commit 5f595c2efba368f5da74215628cf065f1742c3ea Author: Alex Herbert <aherb...@apache.org> AuthorDate: Sat Sep 14 20:50:13 2019 +0100 Reinstate ignored tests for all zero seeds. The test now checks the generator is functional (produces non-zero output). If true it is tested statistically. If false the generator is assumed to be non-functional and the test is skipped. This allows the test to ignore xor-shift based generators that require some bits in the state pool. --- .../rng/simple/ProvidersCommonParametricTest.java | 28 +++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/ProvidersCommonParametricTest.java b/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/ProvidersCommonParametricTest.java index ff12153..882f0b0 100644 --- a/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/ProvidersCommonParametricTest.java +++ b/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/ProvidersCommonParametricTest.java @@ -29,7 +29,6 @@ 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; @@ -134,19 +133,23 @@ public class ProvidersCommonParametricTest { checkNextIntegerInRange(rng, 10, 10000); } - @Ignore@Test + @Test public void testZeroIntArraySeed() { // Exercise capacity to escape all "zero" state. final int[] zero = new int[2000]; // Large enough to fill the entire state with zeroes. final UniformRandomProvider rng = RandomSource.create(originalSource, zero, originalArgs); + Assume.assumeTrue("RNG is non-functional with an all zero seed: " + originalSource, + createsNonZeroLongOutput(rng, 2000)); checkNextIntegerInRange(rng, 10, 10000); } - @Ignore@Test + @Test public void testZeroLongArraySeed() { // Exercise capacity to escape all "zero" state. final long[] zero = new long[2000]; // Large enough to fill the entire state with zeroes. final UniformRandomProvider rng = RandomSource.create(originalSource, zero, originalArgs); + Assume.assumeTrue("RNG is non-functional with an all zero seed: " + originalSource, + createsNonZeroLongOutput(rng, 2000)); checkNextIntegerInRange(rng, 10, 10000); } @@ -359,4 +362,23 @@ public class ProvidersCommonParametricTest { " (" + numFailures + " out of " + numTests + " tests failed)"); } } + + /** + * Return true if the generator creates non-zero output from + * {@link UniformRandomProvider#nextLong()} within the given number of cycles. + * + * @param rng Random generator. + * @param cycles Number of cycles. + * @return true if non-zero output + */ + private static boolean createsNonZeroLongOutput(UniformRandomProvider rng, + int cycles) { + boolean nonZero = false; + for (int i = 0; i < cycles; i++) { + if (rng.nextLong() != 0) { + nonZero = true; + } + } + return nonZero; + } }