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


The following commit(s) were added to refs/heads/master by this push:
     new a7ec057  Moved test for a different RNG output to RandomAssert.
a7ec057 is described below

commit a7ec057d64aab6eaebdabcee83e7aeff5d8353d9
Author: aherbert <aherb...@apache.org>
AuthorDate: Mon Oct 21 17:54:51 2019 +0100

    Moved test for a different RNG output to RandomAssert.
---
 .../org/apache/commons/rng/core/RandomAssert.java  | 28 ++++++++++++++++++----
 .../commons/rng/core/source64/TwoCmresTest.java    |  7 ++----
 2 files changed, 26 insertions(+), 9 deletions(-)

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
index 8bb388c..7344455 100644
--- 
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
@@ -36,7 +36,8 @@ public final class RandomAssert {
     private RandomAssert() {}
 
     /**
-     * Assert that the random generator produces the expected output.
+     * Assert that the random generator produces the expected output using
+     * {@link UniformRandomProvider#nextInt()}.
      *
      * @param expected Expected output.
      * @param rng Random generator.
@@ -46,7 +47,8 @@ public final class RandomAssert {
     }
 
     /**
-     * Assert that the random generator produces the expected output.
+     * Assert that the random generator produces the expected output using
+     * {@link UniformRandomProvider#nextLong()}.
      *
      * @param expected Expected output.
      * @param rng Random generator.
@@ -56,7 +58,8 @@ public final class RandomAssert {
     }
 
     /**
-     * Assert that the random generator produces the expected output.
+     * Assert that the random generator produces the expected output using
+     * {@link UniformRandomProvider#nextInt()}.
      * The message prefix is prepended to the array index for the assertion 
message.
      *
      * @param messagePrefix Message prefix.
@@ -70,7 +73,8 @@ public final class RandomAssert {
     }
 
     /**
-     * Assert that the random generator produces the expected output.
+     * Assert that the random generator produces the expected output using
+     * {@link UniformRandomProvider#nextLong()}.
      * The message prefix is prepended to the array index for the assertion 
message.
      *
      * @param messagePrefix Message prefix.
@@ -84,6 +88,22 @@ public final class RandomAssert {
     }
 
     /**
+     * Assert that the random generator produces a <strong>different</strong> 
output using
+     * {@link UniformRandomProvider#nextLong()} to the expected output.
+     *
+     * @param expected Expected output.
+     * @param rng Random generator.
+     */
+    public static void assertNotEquals(long[] expected, UniformRandomProvider 
rng) {
+        for (int i = 0; i < expected.length; i++) {
+            if (expected[i] != rng.nextLong()) {
+                return;
+            }
+        }
+        Assert.fail("Expected a different nextLong output");
+    }
+
+    /**
      * Assert that the random generator satisfies the contract of the
      * {@link JumpableUniformRandomProvider#jump()} function.
      *
diff --git 
a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/TwoCmresTest.java
 
b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/TwoCmresTest.java
index f1d2ed5..f14d8d2 100644
--- 
a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/TwoCmresTest.java
+++ 
b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/TwoCmresTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.commons.rng.core.source64;
 
+import org.apache.commons.rng.core.RandomAssert;
 import org.apache.commons.rng.core.source64.TwoCmres.Cmres;
 import org.junit.Assert;
 import org.junit.Test;
@@ -59,11 +60,7 @@ public class TwoCmresTest {
         // Seed with a single bit
         for (int bit = 0; bit < 32; bit++) {
             final int seed = 1 << bit;
-
-            final TwoCmres rng1 = new TwoCmres(seed);
-            for (int i = 0; i < n; i++) {
-                Assert.assertNotEquals(values[i], rng1.nextLong());
-            }
+            RandomAssert.assertNotEquals(values, new TwoCmres(seed));
         }
     }
 

Reply via email to