You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2009/07/25 18:21:53 UTC

svn commit: r797790 - /commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/univariate/BrentMinimizerTest.java

Author: luc
Date: Sat Jul 25 16:21:52 2009
New Revision: 797790

URL: http://svn.apache.org/viewvc?rev=797790&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=797790&r1=797789&r2=797790&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:21:52 2009
@@ -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,32 +26,33 @@
 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);
     }
 
-   public void testQuinticMin() throws MathException {
+    @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,
         UnivariateRealFunction f = new QuinticFunction();
@@ -64,12 +65,13 @@
         assertEquals(-0.27195613, minimizer.optimize(f, GoalType.MINIMIZE, -1.0, 0.2), 1.0e-8);
         assertTrue(minimizer.getIterationCount() <= 50);
 
-   }
-    
+    }
+
+    @Test
     public void testMinEndpoints() throws Exception {
         UnivariateRealFunction f = new SinFunction();
         UnivariateRealOptimizer solver = new BrentOptimizer();
-        
+
         // endpoint is minimum
         double result = solver.optimize(f, GoalType.MINIMIZE, 3 * Math.PI / 2, 5);
         assertEquals(3 * Math.PI / 2, result, 70 * solver.getAbsoluteAccuracy());
@@ -78,5 +80,5 @@
         assertEquals(3 * Math.PI / 2, result, 70 * solver.getAbsoluteAccuracy());
 
     }
-    
+
 }