commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject [04/25] [math] MATH-1335
Date Tue, 17 May 2016 15:49:37 GMT
MATH-1335

Use new RNG API.

Unit tests rewritten to avoid unnecessary usage of "RandomDataGenerator" (cf. MATH-1341).


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/0484bdb3
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/0484bdb3
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/0484bdb3

Branch: refs/heads/develop
Commit: 0484bdb3f61d309ff62da4df4be92cf139d19f6b
Parents: 11a7e62
Author: Gilles <erans@apache.org>
Authored: Wed May 11 17:26:37 2016 +0200
Committer: Gilles <erans@apache.org>
Committed: Tue May 17 15:30:23 2016 +0200

----------------------------------------------------------------------
 .../commons/math4/util/ArithmeticUtilsTest.java   | 18 ++++++------------
 .../apache/commons/math4/util/MathUtilsTest.java  | 15 ++++++++-------
 2 files changed, 14 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/0484bdb3/src/test/java/org/apache/commons/math4/util/ArithmeticUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/util/ArithmeticUtilsTest.java b/src/test/java/org/apache/commons/math4/util/ArithmeticUtilsTest.java
index fece225..2de8ee1 100644
--- a/src/test/java/org/apache/commons/math4/util/ArithmeticUtilsTest.java
+++ b/src/test/java/org/apache/commons/math4/util/ArithmeticUtilsTest.java
@@ -22,8 +22,6 @@ import java.math.BigInteger;
 
 import org.apache.commons.math4.exception.MathArithmeticException;
 import org.apache.commons.math4.exception.MathIllegalArgumentException;
-import org.apache.commons.math4.random.RandomDataGenerator;
-import org.apache.commons.math4.util.ArithmeticUtils;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -125,17 +123,13 @@ public class ArithmeticUtilsTest {
     @Test
     public void testGcdConsistency() {
         int[] primeList = {19, 23, 53, 67, 73, 79, 101, 103, 111, 131};
-        ArrayList<Integer> primes = new ArrayList<Integer>();
-        for (int i = 0; i < primeList.length; i++) {
-            primes.add(Integer.valueOf(primeList[i]));
-        }
-        RandomDataGenerator randomData = new RandomDataGenerator();
+
         for (int i = 0; i < 20; i++) {
-            Object[] sample = randomData.nextSample(primes, 4);
-            int p1 = ((Integer) sample[0]).intValue();
-            int p2 = ((Integer) sample[1]).intValue();
-            int p3 = ((Integer) sample[2]).intValue();
-            int p4 = ((Integer) sample[3]).intValue();
+            MathArrays.shuffle(primeList);
+            int p1 = primeList[0];
+            int p2 = primeList[1];
+            int p3 = primeList[2];
+            int p4 = primeList[3];
             int i1 = p1 * p2 * p3;
             int i2 = p1 * p2 * p4;
             int gcd = p1 * p2;

http://git-wip-us.apache.org/repos/asf/commons-math/blob/0484bdb3/src/test/java/org/apache/commons/math4/util/MathUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/util/MathUtilsTest.java b/src/test/java/org/apache/commons/math4/util/MathUtilsTest.java
index 8ce9a2d..f83476f 100644
--- a/src/test/java/org/apache/commons/math4/util/MathUtilsTest.java
+++ b/src/test/java/org/apache/commons/math4/util/MathUtilsTest.java
@@ -19,10 +19,8 @@ import org.apache.commons.math4.exception.MathArithmeticException;
 import org.apache.commons.math4.exception.NotFiniteNumberException;
 import org.apache.commons.math4.exception.NullArgumentException;
 import org.apache.commons.math4.exception.util.LocalizedFormats;
-import org.apache.commons.math4.random.RandomDataGenerator;
+import org.apache.commons.math4.rng.UniformRandomProvider;
 import org.apache.commons.math4.rng.RandomSource;
-import org.apache.commons.math4.util.FastMath;
-import org.apache.commons.math4.util.MathUtils;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -97,23 +95,26 @@ public final class MathUtilsTest {
     public void testPermutedArrayHash() {
         double[] original = new double[10];
         double[] permuted = new double[10];
-        RandomDataGenerator random = new RandomDataGenerator();
+
+        final UniformRandomProvider random = RandomSource.create(RandomSource.WELL_512_A,
+                                                                 64925784252L);
 
         // Generate 10 distinct random values
         for (int i = 0; i < 10; i++) {
             final RealDistribution.Sampler u
-                = new UniformRealDistribution(i + 0.5, i + 0.75).createSampler(RandomSource.create(RandomSource.WELL_512_A,
-                                                                                        
          64925784252L));
+                = new UniformRealDistribution(i + 0.5, i + 0.75).createSampler(random);
             original[i] = u.sample();
         }
 
         // Generate a random permutation, making sure it is not the identity
         boolean isIdentity = true;
         do {
-            int[] permutation = random.nextPermutation(10, 10);
+            int[] permutation = MathArrays.natural(10);
+            MathArrays.shuffle(permutation, random);
             for (int i = 0; i < 10; i++) {
                 if (i != permutation[i]) {
                     isIdentity = false;
+                    break;
                 }
                 permuted[i] = original[permutation[i]];
             }


Mime
View raw message