commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r797792 - /commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/univariate/BrentMinimizerTest.java
Date Sat, 25 Jul 2009 16:41:58 GMT
Author: luc
Date: Sat Jul 25 16:41:58 2009
New Revision: 797792

URL: http://svn.apache.org/viewvc?rev=797792&view=rev
Log:
improved test coverage

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

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/univariate/BrentMinimizerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/univariate/BrentMinimizerTest.java?rev=797792&r1=797791&r2=797792&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/univariate/BrentMinimizerTest.java
(original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/univariate/BrentMinimizerTest.java
Sat Jul 25 16:41:58 2009
@@ -22,6 +22,7 @@
 
 import org.apache.commons.math.FunctionEvaluationException;
 import org.apache.commons.math.MathException;
+import org.apache.commons.math.MaxIterationsExceededException;
 import org.apache.commons.math.analysis.QuinticFunction;
 import org.apache.commons.math.analysis.SinFunction;
 import org.apache.commons.math.analysis.UnivariateRealFunction;
@@ -82,6 +83,24 @@
     }
 
     @Test
+    public void testQuinticMax() throws MathException {
+        // The quintic function has zeros at 0, +-0.5 and +-1.
+        // The function has extrema (first derivative is zero) at 0.27195613 and 0.82221643,
+        UnivariateRealFunction f = new QuinticFunction();
+        UnivariateRealOptimizer minimizer = new BrentOptimizer();
+        assertEquals(0.27195613, minimizer.optimize(f, GoalType.MAXIMIZE, 0.2, 0.3), 1.0e-8);
+        minimizer.setMaximalIterationCount(30);
+        try {
+            minimizer.optimize(f, GoalType.MAXIMIZE, 0.2, 0.3);
+            fail("an exception should have been thrown");
+        } catch (MaxIterationsExceededException miee) {
+            // expected
+        } catch (Exception e) {
+            fail("wrong exception caught");
+        }
+    }
+
+    @Test
     public void testMinEndpoints() throws Exception {
         UnivariateRealFunction f = new SinFunction();
         UnivariateRealOptimizer solver = new BrentOptimizer();



Mime
View raw message