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 f0430b5c165748ce808a8644b720b3a461010374
Author: aherbert <[email protected]>
AuthorDate: Wed Feb 13 17:08:38 2019 +0000

    Fixed test coverage in TwoCmresTest
---
 .../apache/commons/rng/core/source64/TwoCmres.java | 17 ++++++++++++---
 .../commons/rng/core/source64/TwoCmresTest.java    | 24 ++++++++++++++++++++++
 2 files changed, 38 insertions(+), 3 deletions(-)

diff --git 
a/commons-rng-core/src/main/java/org/apache/commons/rng/core/source64/TwoCmres.java
 
b/commons-rng-core/src/main/java/org/apache/commons/rng/core/source64/TwoCmres.java
index 11850c2..981b80f 100644
--- 
a/commons-rng-core/src/main/java/org/apache/commons/rng/core/source64/TwoCmres.java
+++ 
b/commons-rng-core/src/main/java/org/apache/commons/rng/core/source64/TwoCmres.java
@@ -299,13 +299,24 @@ public class TwoCmres extends LongProvider {
                                     int start) {
                 // Sanity check: if there are duplicates, the class 
initialization
                 // will fail (and the JVM will report "NoClassDefFoundError").
-                for (Cmres sg : TABLE) {
+                checkUnique(TABLE, multiply);
+
+                TABLE.add(new Cmres(multiply, rotate, start));
+            }
+
+            /**
+             * Check the multiply parameter is unique (not contained in any 
entry in the provided
+             * table).
+             *
+             * @param table the table
+             * @param multiply the multiply parameter
+             */
+            static void checkUnique(List<Cmres> table, long multiply) {
+                for (Cmres sg : table) {
                     if (multiply == sg.getMultiply()) {
                         throw new IllegalStateException(INTERNAL_ERROR_MSG);
                     }
                 }
-
-                TABLE.add(new Cmres(multiply, rotate, start));
             }
         }
     }
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 2b921ce..4c8e6d6 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,9 +16,12 @@
  */
 package org.apache.commons.rng.core.source64;
 
+import org.apache.commons.rng.core.source64.TwoCmres.Cmres;
 import org.junit.Assert;
 import org.junit.Test;
 
+import java.util.ArrayList;
+
 
 public class TwoCmresTest {
     @Test
@@ -82,4 +85,25 @@ public class TwoCmresTest {
             }
         }
     }
+
+    @Test(expected=IllegalStateException.class)
+    public void testCmresFactoryThrowsWithDuplicateMultiplier() {
+        ArrayList<Cmres> list = new ArrayList<Cmres>();
+        final long multiply = 0;
+        final int rotate = 3;
+        final int start = 5;
+
+        list.add(new Cmres(multiply, rotate, start));
+
+        long nextMultiply = multiply + 1;
+        try {
+            Cmres.Factory.checkUnique(list, nextMultiply);
+        } catch (IllegalStateException ex) {
+            Assert.fail("The next multiply should be unique: " + nextMultiply);
+        }
+
+        list.add(new Cmres(nextMultiply, rotate, start));
+        // This should throw as the list now contains the multiply value
+        Cmres.Factory.checkUnique(list, nextMultiply);
+    }
 }

Reply via email to