improved test coverage
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@797790 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1a7da0d08a
commit
afb42aaf58
|
@ -16,9 +16,9 @@
|
|||
*/
|
||||
package org.apache.commons.math.optimization.univariate;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.apache.commons.math.MathException;
|
||||
import org.apache.commons.math.analysis.QuinticFunction;
|
||||
|
@ -26,31 +26,32 @@ import org.apache.commons.math.analysis.SinFunction;
|
|||
import org.apache.commons.math.analysis.UnivariateRealFunction;
|
||||
import org.apache.commons.math.optimization.GoalType;
|
||||
import org.apache.commons.math.optimization.UnivariateRealOptimizer;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @version $Revision$ $Date$
|
||||
*/
|
||||
public final class BrentMinimizerTest extends TestCase {
|
||||
|
||||
public BrentMinimizerTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
TestSuite suite = new TestSuite(BrentMinimizerTest.class);
|
||||
suite.setName("BrentOptimizer Tests");
|
||||
return suite;
|
||||
}
|
||||
public final class BrentMinimizerTest {
|
||||
|
||||
@Test
|
||||
public void testSinMin() throws MathException {
|
||||
UnivariateRealFunction f = new SinFunction();
|
||||
UnivariateRealOptimizer minimizer = new BrentOptimizer();
|
||||
try {
|
||||
minimizer.getResult();
|
||||
fail("an exception should have been thrown");
|
||||
} catch (IllegalStateException ise) {
|
||||
// expected
|
||||
} catch (Exception e) {
|
||||
fail("wrong exception caught");
|
||||
}
|
||||
assertEquals(3 * Math.PI / 2, minimizer.optimize(f, GoalType.MINIMIZE, 4, 5), 70 * minimizer.getAbsoluteAccuracy());
|
||||
assertTrue(minimizer.getIterationCount() <= 50);
|
||||
assertEquals(3 * Math.PI / 2, minimizer.optimize(f, GoalType.MINIMIZE, 1, 5), 70 * minimizer.getAbsoluteAccuracy());
|
||||
assertTrue(minimizer.getIterationCount() <= 50);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQuinticMin() 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,
|
||||
|
@ -66,6 +67,7 @@ public final class BrentMinimizerTest extends TestCase {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinEndpoints() throws Exception {
|
||||
UnivariateRealFunction f = new SinFunction();
|
||||
UnivariateRealOptimizer solver = new BrentOptimizer();
|
||||
|
|
Loading…
Reference in New Issue