improved test coverage

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@797792 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Luc Maisonobe 2009-07-25 16:41:58 +00:00
parent cfd7b30418
commit 2194603459
1 changed files with 19 additions and 0 deletions

View File

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