You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2015/12/21 01:29:09 UTC
[1/3] [math] Separate test cases.
Repository: commons-math
Updated Branches:
refs/heads/master a4a62ed7c -> 813aa11d5
Separate test cases.
Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/b3a68ca8
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/b3a68ca8
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/b3a68ca8
Branch: refs/heads/master
Commit: b3a68ca842841c4b9713462d5f01742cf71a6b4a
Parents: a4a62ed
Author: Gilles <er...@apache.org>
Authored: Sun Dec 20 17:21:41 2015 +0100
Committer: Gilles <er...@apache.org>
Committed: Sun Dec 20 17:21:41 2015 +0100
----------------------------------------------------------------------
.../random/RandomGeneratorAbstractTest.java | 19 +++++++------------
1 file changed, 7 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b3a68ca8/src/test/java/org/apache/commons/math4/random/RandomGeneratorAbstractTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/random/RandomGeneratorAbstractTest.java b/src/test/java/org/apache/commons/math4/random/RandomGeneratorAbstractTest.java
index 0daa3ab..f9fd26b 100644
--- a/src/test/java/org/apache/commons/math4/random/RandomGeneratorAbstractTest.java
+++ b/src/test/java/org/apache/commons/math4/random/RandomGeneratorAbstractTest.java
@@ -162,19 +162,14 @@ public abstract class RandomGeneratorAbstractTest extends RandomDataGeneratorTes
}
}
- @Test
+ @Test(expected=MathIllegalArgumentException.class)
public void testNextIntIAE2() {
- try {
- generator.nextInt(-1);
- Assert.fail("MathIllegalArgumentException expected");
- } catch (MathIllegalArgumentException ex) {
- // ignored
- }
- try {
- generator.nextInt(0);
- } catch (MathIllegalArgumentException ex) {
- // ignored
- }
+ generator.nextInt(-1);
+ }
+
+ @Test(expected=MathIllegalArgumentException.class)
+ public void testNextIntIAE3() {
+ generator.nextInt(0);
}
@Test
[2/3] [math] Redundant unit test removed.
Posted by er...@apache.org.
Redundant unit test removed.
Renamed two methods to be clearer about what is being tested.
Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/2d868410
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/2d868410
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/2d868410
Branch: refs/heads/master
Commit: 2d868410eead061d59de524bada4de9e3d2bb442
Parents: b3a68ca
Author: Gilles <er...@apache.org>
Authored: Sun Dec 20 22:42:10 2015 +0100
Committer: Gilles <er...@apache.org>
Committed: Sun Dec 20 22:42:10 2015 +0100
----------------------------------------------------------------------
.../math4/random/RandomGeneratorAbstractTest.java | 17 ++++++-----------
1 file changed, 6 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-math/blob/2d868410/src/test/java/org/apache/commons/math4/random/RandomGeneratorAbstractTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/random/RandomGeneratorAbstractTest.java b/src/test/java/org/apache/commons/math4/random/RandomGeneratorAbstractTest.java
index f9fd26b..26d4dfd 100644
--- a/src/test/java/org/apache/commons/math4/random/RandomGeneratorAbstractTest.java
+++ b/src/test/java/org/apache/commons/math4/random/RandomGeneratorAbstractTest.java
@@ -162,16 +162,6 @@ public abstract class RandomGeneratorAbstractTest extends RandomDataGeneratorTes
}
}
- @Test(expected=MathIllegalArgumentException.class)
- public void testNextIntIAE2() {
- generator.nextInt(-1);
- }
-
- @Test(expected=MathIllegalArgumentException.class)
- public void testNextIntIAE3() {
- generator.nextInt(0);
- }
-
@Test
public void testNextLongDirect() {
long q1 = Long.MAX_VALUE/4;
@@ -283,10 +273,15 @@ public abstract class RandomGeneratorAbstractTest extends RandomDataGeneratorTes
}
@Test(expected=MathIllegalArgumentException.class)
- public void testNextIntNeg() {
+ public void testNextIntPrecondition1() {
generator.nextInt(-1);
}
+ @Test(expected=MathIllegalArgumentException.class)
+ public void testNextIntPrecondition2() {
+ generator.nextInt(0);
+ }
+
@Test
public void testNextInt2() {
int walk = 0;
[3/3] [math] MATH-1304
Posted by er...@apache.org.
MATH-1304
Replaced implementation of "nextBytes" by copying the code from "BitsStreamGenerator" class
(and then replacing the call to "next(32)" by "nextInt()").
Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/813aa11d
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/813aa11d
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/813aa11d
Branch: refs/heads/master
Commit: 813aa11d505b9507b6795d36070806cb2d96e5c2
Parents: 2d86841
Author: Gilles <er...@apache.org>
Authored: Mon Dec 21 01:26:18 2015 +0100
Committer: Gilles <er...@apache.org>
Committed: Mon Dec 21 01:26:18 2015 +0100
----------------------------------------------------------------------
.../math4/random/AbstractRandomGenerator.java | 30 +++++++++++---------
1 file changed, 16 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-math/blob/813aa11d/src/main/java/org/apache/commons/math4/random/AbstractRandomGenerator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/random/AbstractRandomGenerator.java b/src/main/java/org/apache/commons/math4/random/AbstractRandomGenerator.java
index 173f4ee..c31dc68 100644
--- a/src/main/java/org/apache/commons/math4/random/AbstractRandomGenerator.java
+++ b/src/main/java/org/apache/commons/math4/random/AbstractRandomGenerator.java
@@ -107,24 +107,26 @@ public abstract class AbstractRandomGenerator implements RandomGenerator {
*/
@Override
public void nextBytes(byte[] bytes) {
- int bytesOut = 0;
- while (bytesOut < bytes.length) {
- int randInt = nextInt();
- for (int i = 0; i < 3; i++) {
- if (i > 0) {
- randInt >>= 8;
- }
- }
- if (bytesOut < bytes.length) {
- bytes[bytesOut++] = (byte) randInt;
- if (bytesOut == bytes.length) {
- return;
- }
+ int i = 0;
+ final int iEnd = bytes.length - 3;
+ while (i < iEnd) {
+ final int random = nextInt();
+ bytes[i] = (byte) (random & 0xff);
+ bytes[i + 1] = (byte) ((random >> 8) & 0xff);
+ bytes[i + 2] = (byte) ((random >> 16) & 0xff);
+ bytes[i + 3] = (byte) ((random >> 24) & 0xff);
+ i += 4;
+ }
+ if (i < bytes.length) {
+ int random = nextInt();
+ while (i < bytes.length) {
+ bytes[i++] = (byte) (random & 0xff);
+ random >>= 8;
}
}
}
- /**
+ /**
* Returns the next pseudorandom, uniformly distributed {@code int}
* value from this random number generator's sequence.
* All 2<font size="-1"><sup>32</sup></font> possible {@code int} values