commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r1294680 - /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/univariate/BrentOptimizerTest.java
Date Tue, 28 Feb 2012 14:56:26 GMT
Author: luc
Date: Tue Feb 28 14:56:26 2012
New Revision: 1294680

URL: http://svn.apache.org/viewvc?rev=1294680&view=rev
Log:
Added a test.

Modified:
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/univariate/BrentOptimizerTest.java

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/univariate/BrentOptimizerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/univariate/BrentOptimizerTest.java?rev=1294680&r1=1294679&r2=1294680&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/univariate/BrentOptimizerTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/univariate/BrentOptimizerTest.java
Tue Feb 28 14:56:26 2012
@@ -17,6 +17,8 @@
 package org.apache.commons.math3.optimization.univariate;
 
 
+import org.apache.commons.math3.exception.NumberIsTooLargeException;
+import org.apache.commons.math3.exception.NumberIsTooSmallException;
 import org.apache.commons.math3.exception.TooManyEvaluationsException;
 import org.apache.commons.math3.analysis.QuinticFunction;
 import org.apache.commons.math3.analysis.SinFunction;
@@ -50,6 +52,30 @@ public final class BrentOptimizerTest {
     }
 
     @Test
+    public void testBoundaries() {
+        final double lower = -1.0;
+        final double upper = +1.0;
+        UnivariateFunction f = new UnivariateFunction() {            
+            public double value(double x) {
+                if (x < lower) {
+                    throw new NumberIsTooSmallException(x, lower, true);
+                } else if (x > upper) {
+                    throw new NumberIsTooLargeException(x, upper, true);
+                } else {
+                    return x;
+                }
+            }
+        };
+        UnivariateOptimizer optimizer = new BrentOptimizer(1e-10, 1e-14);
+        Assert.assertEquals(lower,
+                            optimizer.optimize(100, f, GoalType.MINIMIZE, lower, upper).getPoint(),
+                            1.0e-8);
+        Assert.assertEquals(upper,
+                            optimizer.optimize(100, f, GoalType.MAXIMIZE, lower, upper).getPoint(),
+                            1.0e-8);
+    }
+
+    @Test
     public void testQuinticMin() {
         // The function has local minima at -0.27195613 and 0.82221643.
         UnivariateFunction f = new QuinticFunction();



Mime
View raw message