Moved test for a different RNG output to RandomAssert.
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 @@
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 @@
}
/**
- * 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 @@
}
/**
- * 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 @@
}
/**
- * 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 @@
}
/**
+ * 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 @@
// 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));
}
}