Skip to content

Commit

Permalink
improved test coverage
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@797792 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Luc Maisonobe committed Jul 25, 2009
1 parent cfd7b30 commit 2194603
Showing 1 changed file with 19 additions and 0 deletions.
Expand Up @@ -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;
Expand Down Expand Up @@ -81,6 +82,24 @@ public void testQuinticMin() throws MathException {

}

@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();
Expand Down

0 comments on commit 2194603

Please sign in to comment.