From 219460345959ab287a7cfd749432687d831bbd15 Mon Sep 17 00:00:00 2001 From: Luc Maisonobe Date: Sat, 25 Jul 2009 16:41:58 +0000 Subject: [PATCH] improved test coverage git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@797792 13f79535-47bb-0310-9956-ffa450edef68 --- .../univariate/BrentMinimizerTest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/test/org/apache/commons/math/optimization/univariate/BrentMinimizerTest.java b/src/test/org/apache/commons/math/optimization/univariate/BrentMinimizerTest.java index 5fc9ae767..7ae5ed093 100644 --- a/src/test/org/apache/commons/math/optimization/univariate/BrentMinimizerTest.java +++ b/src/test/org/apache/commons/math/optimization/univariate/BrentMinimizerTest.java @@ -22,6 +22,7 @@ import static org.junit.Assert.fail; 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; @@ -81,6 +82,24 @@ public final class BrentMinimizerTest { } + @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();