commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject [1/2] [math] MATH-1256
Date Mon, 17 Aug 2015 11:30:16 GMT
Repository: commons-math
Updated Branches:
  refs/heads/master afd3f9005 -> e7e8c3f71


MATH-1256

Enforce order of bounds.


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

Branch: refs/heads/master
Commit: 41f297809965523fcd021bef20b304b3584d9b4f
Parents: 4f548ac
Author: Gilles <erans@apache.org>
Authored: Mon Aug 17 13:20:22 2015 +0200
Committer: Gilles <erans@apache.org>
Committed: Mon Aug 17 13:20:22 2015 +0200

----------------------------------------------------------------------
 src/changes/changes.xml                                        | 3 +++
 .../apache/commons/math4/geometry/euclidean/oned/Interval.java | 6 ++++++
 .../commons/math4/geometry/euclidean/oned/IntervalTest.java    | 6 ++++++
 3 files changed, 15 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/41f29780/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 8c71506..65d428e 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -54,6 +54,9 @@ If the output is not quite correct, check for invisible trailing spaces!
     </release>
 
     <release version="4.0" date="XXXX-XX-XX" description="">
+      <action dev="erans" type="fix" issue="MATH-1256"> <!-- backported to 3.6 -->
+        Boundary check to construct an "Interval" (package "o.a.c.m.geometry.euclidean.oned").
+      </action>
       <action dev="erans" type="fix" issue="MATH-1255"> <!-- backported to 3.6 -->
         Wrong neighbourhood size in class "KohonenUpdateAction" (package "o.a.c.m.ml.neuralnet.sofm").
       </action>

http://git-wip-us.apache.org/repos/asf/commons-math/blob/41f29780/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Interval.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Interval.java
b/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Interval.java
index 9785776..87dbba1 100644
--- a/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Interval.java
+++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Interval.java
@@ -17,6 +17,8 @@
 package org.apache.commons.math4.geometry.euclidean.oned;
 
 import org.apache.commons.math4.geometry.partitioning.Region.Location;
+import org.apache.commons.math4.exception.NumberIsTooSmallException;
+import org.apache.commons.math4.exception.util.LocalizedFormats;
 
 
 /** This class represents a 1D interval.
@@ -36,6 +38,10 @@ public class Interval {
      * @param upper upper bound of the interval
      */
     public Interval(final double lower, final double upper) {
+        if (upper < lower) {
+            throw new NumberIsTooSmallException(LocalizedFormats.ENDPOINTS_NOT_AN_INTERVAL,
+                                                upper, lower, true);
+        }
         this.lower = lower;
         this.upper = upper;
     }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/41f29780/src/test/java/org/apache/commons/math4/geometry/euclidean/oned/IntervalTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/oned/IntervalTest.java
b/src/test/java/org/apache/commons/math4/geometry/euclidean/oned/IntervalTest.java
index 2ebd847..3c85434 100644
--- a/src/test/java/org/apache/commons/math4/geometry/euclidean/oned/IntervalTest.java
+++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/oned/IntervalTest.java
@@ -20,6 +20,7 @@ import org.apache.commons.math4.geometry.euclidean.oned.Interval;
 import org.apache.commons.math4.geometry.partitioning.Region;
 import org.apache.commons.math4.util.FastMath;
 import org.apache.commons.math4.util.Precision;
+import org.apache.commons.math4.exception.NumberIsTooSmallException;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -72,4 +73,9 @@ public class IntervalTest {
         Assert.assertEquals(1.0, interval.getBarycenter(), Precision.EPSILON);
     }
 
+    // MATH-1256
+    @Test(expected=NumberIsTooSmallException.class)
+    public void testStrictOrdering() {
+        new Interval(0, -1);
+    }
 }


Mime
View raw message