commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject svn commit: r1037372 - /commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/univariate/MultiStartUnivariateRealOptimizerTest.java
Date Sun, 21 Nov 2010 02:36:15 GMT
Author: erans
Date: Sun Nov 21 02:36:14 2010
New Revision: 1037372

URL: http://svn.apache.org/viewvc?rev=1037372&view=rev
Log:
Refined test (follow-up of MATH-441).

Modified:
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/univariate/MultiStartUnivariateRealOptimizerTest.java

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/univariate/MultiStartUnivariateRealOptimizerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/univariate/MultiStartUnivariateRealOptimizerTest.java?rev=1037372&r1=1037371&r2=1037372&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/univariate/MultiStartUnivariateRealOptimizerTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/univariate/MultiStartUnivariateRealOptimizerTest.java
Sun Nov 21 02:36:14 2010
@@ -28,11 +28,12 @@ import org.apache.commons.math.optimizat
 import org.apache.commons.math.random.JDKRandomGenerator;
 import org.apache.commons.math.util.FastMath;
 import org.junit.Test;
+import org.junit.Assert;
 
 public class MultiStartUnivariateRealOptimizerTest {
 
     @Test
-    public void testSinMin() throws MathUserException {
+    public void testSinMin() {
         UnivariateRealFunction f = new SinFunction();
         UnivariateRealOptimizer underlying = new BrentOptimizer(1e-10, 1e-14);
         underlying.setMaxEvaluations(300);
@@ -53,7 +54,7 @@ public class MultiStartUnivariateRealOpt
     }
 
     @Test
-    public void testQuinticMin() throws MathUserException {
+    public void testQuinticMin() {
         // 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();
@@ -77,10 +78,10 @@ public class MultiStartUnivariateRealOpt
         assertTrue(optimizer.getEvaluations() <= 100);
     }
 
-    @Test(expected=MathUserException.class)
-    public void testBadFunction() throws MathUserException {
+    @Test
+    public void testBadFunction() {
         UnivariateRealFunction f = new UnivariateRealFunction() {
-                public double value(double x) throws MathUserException {
+                public double value(double x) {
                     if (x < 0) {
                         throw new MathUserException();
                     }
@@ -93,7 +94,16 @@ public class MultiStartUnivariateRealOpt
         g.setSeed(4312000053L);
         MultiStartUnivariateRealOptimizer<UnivariateRealFunction> optimizer =
             new MultiStartUnivariateRealOptimizer<UnivariateRealFunction>(underlying,
5, g);
+ 
+        try {
+            UnivariateRealPointValuePair optimum
+                = optimizer.optimize(f, GoalType.MINIMIZE, -0.3, -0.2);
+            Assert.fail();
+        } catch (MathUserException e) {
+            // Expected.
+        }
 
-        optimizer.optimize(f, GoalType.MINIMIZE, -0.3, -0.2);
+        // Ensure that the exception was thrown because no optimum was found.
+        Assert.assertTrue(optimizer.getOptima()[0] == null);
     }
 }



Mime
View raw message