From 41f297809965523fcd021bef20b304b3584d9b4f Mon Sep 17 00:00:00 2001 From: Gilles Date: Mon, 17 Aug 2015 13:20:22 +0200 Subject: [PATCH] MATH-1256 Enforce order of bounds. --- src/changes/changes.xml | 3 +++ .../commons/math4/geometry/euclidean/oned/Interval.java | 6 ++++++ .../commons/math4/geometry/euclidean/oned/IntervalTest.java | 6 ++++++ 3 files changed, 15 insertions(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 8c7150637..65d428e15 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! + + Boundary check to construct an "Interval" (package "o.a.c.m.geometry.euclidean.oned"). + Wrong neighbourhood size in class "KohonenUpdateAction" (package "o.a.c.m.ml.neuralnet.sofm"). 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 97857761b..87dbba16c 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; } 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 2ebd847f2..3c854348d 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); + } }