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 2014/08/04 23:00:48 UTC

svn commit: r1615790 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math3/distribution/UniformIntegerDistribution.java test/java/org/apache/commons/math3/distribution/UniformIntegerDistributionTest.java

Author: erans
Date: Mon Aug  4 21:00:48 2014
New Revision: 1615790

URL: http://svn.apache.org/r1615790
Log:
MATH-1141
Allow same value for lower and upper bounds.

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/UniformIntegerDistribution.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/UniformIntegerDistributionTest.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/UniformIntegerDistribution.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/UniformIntegerDistribution.java?rev=1615790&r1=1615789&r2=1615790&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/UniformIntegerDistribution.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/UniformIntegerDistribution.java Mon Aug  4 21:00:48 2014
@@ -59,7 +59,7 @@ public class UniformIntegerDistribution 
      * @param rng Random number generator.
      * @param lower Lower bound (inclusive) of this distribution.
      * @param upper Upper bound (inclusive) of this distribution.
-     * @throws NumberIsTooLargeException if {@code lower >= upper}.
+     * @throws NumberIsTooLargeException if {@code lower > upper}.
      * @since 3.1
      */
     public UniformIntegerDistribution(RandomGenerator rng,
@@ -68,10 +68,10 @@ public class UniformIntegerDistribution 
         throws NumberIsTooLargeException {
         super(rng);
 
-        if (lower >= upper) {
+        if (lower > upper) {
             throw new NumberIsTooLargeException(
                             LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
-                            lower, upper, false);
+                            lower, upper, true);
         }
         this.lower = lower;
         this.upper = upper;

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/UniformIntegerDistributionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/UniformIntegerDistributionTest.java?rev=1615790&r1=1615789&r2=1615790&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/UniformIntegerDistributionTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/UniformIntegerDistributionTest.java Mon Aug  4 21:00:48 2014
@@ -19,6 +19,7 @@ package org.apache.commons.math3.distrib
 
 import org.junit.Assert;
 import org.junit.Test;
+import org.apache.commons.math3.exception.NumberIsTooLargeException;
 
 /**
  * Test cases for UniformIntegerDistribution. See class javadoc for
@@ -96,4 +97,17 @@ public class UniformIntegerDistributionT
         Assert.assertEquals(dist.getNumericalMean(), 0.5, 0);
         Assert.assertEquals(dist.getNumericalVariance(), 3 / 12.0, 0);
     }
+
+    // MATH-1141
+    @Test
+    public void testPreconditionUpperBoundInclusive() {
+        try {
+            new UniformIntegerDistribution(1, 0);
+        } catch (NumberIsTooLargeException e) {
+            // Expected.
+        }
+
+        // Degenerate case is allowed.
+        new UniformIntegerDistribution(0, 0);
+    }
 }