MATH-1256

Enforce order of bounds.
This commit is contained in:
Gilles 2015-08-17 13:20:22 +02:00
parent 4f548acfd1
commit 41f2978099
3 changed files with 15 additions and 0 deletions

View File

@ -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>

View File

@ -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;
}

View File

@ -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);
}
}