Skip to content

Commit 0596e31

Browse files
committed
Fixed parameter test in RandomDataImpl#nextExponential. JIRA: MATH-309.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@831510 13f79535-47bb-0310-9956-ffa450edef68
1 parent 90f6eba commit 0596e31

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

src/main/java/org/apache/commons/math/random/RandomDataImpl.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,12 +457,11 @@ public double nextGaussian(double mu, double sigma) {
457457
* uniform deviates.
458458
* </p>
459459
*
460-
* @param mean
461-
* the mean of the distribution
460+
* @param mean the mean of the distribution
462461
* @return the random Exponential value
463462
*/
464463
public double nextExponential(double mean) {
465-
if (mean < 0.0) {
464+
if (mean <= 0.0) {
466465
throw MathRuntimeException.createIllegalArgumentException(
467466
"mean must be positive ({0})", mean);
468467
}

src/site/xdoc/changes.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ The <action> type attribute can be add,update,fix,remove.
3939
</properties>
4040
<body>
4141
<release version="2.1" date="TBD" description="TBD">
42+
<action dev="psteitz" type="fix" issue="MATH-309" due-to="Mikkel Meyer Andersen">
43+
Fixed parameter test in RandomDataImpl#nextExponential. The method now throws
44+
IllegalArgumentException for mean = 0.
45+
</action>
4246
<action dev="brentworden" type="update" issue="MATH-311" due-to="Nipun Jawalkar">
4347
Changed probability calculations for Binomial, Poisson, and Hypergeometric
4448
distributions to use Catherine Loader's saddle point approximations.

src/test/java/org/apache/commons/math/random/RandomDataTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,12 @@ public void testNextExponential() {
563563
} catch (IllegalArgumentException ex) {
564564
// ignored
565565
}
566-
assertEquals("0 mean", 0, randomData.nextExponential(0), 10E-8);
566+
try {
567+
randomData.nextExponential(0);
568+
fail("zero mean -- expecting IllegalArgumentException");
569+
} catch (IllegalArgumentException ex) {
570+
// ignored
571+
}
567572
long cumFreq = 0;
568573
double v = 0;
569574
for (int i = 0; i < largeSampleSize; i++) {

0 commit comments

Comments
 (0)