Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 0E98B2009A8 for ; Tue, 17 May 2016 17:49:37 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 0B589160A22; Tue, 17 May 2016 15:49:37 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 52C7B1607A8 for ; Tue, 17 May 2016 17:49:36 +0200 (CEST) Received: (qmail 76611 invoked by uid 500); 17 May 2016 15:49:34 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 76253 invoked by uid 99); 17 May 2016 15:49:34 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 17 May 2016 15:49:34 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 1C004E0537; Tue, 17 May 2016 15:49:34 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: erans@apache.org To: commits@commons.apache.org Date: Tue, 17 May 2016 15:49:37 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [04/25] [math] MATH-1335 archived-at: Tue, 17 May 2016 15:49:37 -0000 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 Authored: Wed May 11 17:26:37 2016 +0200 Committer: Gilles 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 primes = new ArrayList(); - 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]]; }