You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2021/08/27 17:17:07 UTC

[commons-math] branch master updated (6f33d5f -> bf1c2c2)

This is an automated email from the ASF dual-hosted git repository.

erans pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-math.git.


    from 6f33d5f  Fix incorrect usage of "ROSENBROCK" test function (unit tests).
     new dd0acaa  Relax expectations (unit test).
     new bf1c2c2  Remove obsolete helper class for unit testing.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../apache/commons/math4/legacy/RetryRunner.java   | 81 ----------------------
 .../commons/math4/legacy/RetryRunnerTest.java      | 54 ---------------
 .../scalar/noderiv/CMAESOptimizerTest.java         |  5 --
 .../std_test_func.simplex.multidirectional.csv     |  4 +-
 4 files changed, 2 insertions(+), 142 deletions(-)
 delete mode 100644 commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/RetryRunner.java
 delete mode 100644 commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/RetryRunnerTest.java

[commons-math] 02/02: Remove obsolete helper class for unit testing.

Posted by er...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

erans pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-math.git

commit bf1c2c214c67fb3ce513fc8241d711e91cc81be9
Author: Gilles Sadowski <gi...@gmail.com>
AuthorDate: Fri Aug 27 19:16:03 2021 +0200

    Remove obsolete helper class for unit testing.
    
    Retries are handled by the "surefire" plugin.
---
 .../apache/commons/math4/legacy/RetryRunner.java   | 81 ----------------------
 .../commons/math4/legacy/RetryRunnerTest.java      | 54 ---------------
 .../scalar/noderiv/CMAESOptimizerTest.java         |  5 --
 3 files changed, 140 deletions(-)

diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/RetryRunner.java b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/RetryRunner.java
deleted file mode 100644
index 7505c9f..0000000
--- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/RetryRunner.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.math4.legacy;
-
-import org.junit.runners.BlockJUnit4ClassRunner;
-import org.junit.runners.model.FrameworkMethod;
-import org.junit.runners.model.InitializationError;
-import org.junit.runners.model.Statement;
-
-
-/**
- * A test runner that retries tests when assertions fail.
- */
-public class RetryRunner extends BlockJUnit4ClassRunner {
-    /**
-     * Simple constructor.
-     *
-     * @param testClass Class to test.
-     * @throws InitializationError if default runner cannot be built.
-     */
-    public RetryRunner(final Class<?> testClass)
-        throws InitializationError {
-        super(testClass);
-    }
-
-    @Override
-    public Statement methodInvoker(final FrameworkMethod method,
-                                   Object test) {
-        final Statement singleTryStatement = super.methodInvoker(method, test);
-        return new Statement() {
-            /**
-             * Evaluate the statement.
-             * We attempt several runs for the test, at most MAX_ATTEMPTS.
-             * if one attempt succeeds, we succeed, if all attempts fail, we
-             * fail with the reason corresponding to the last attempt
-             */
-            @Override
-            public void evaluate() throws Throwable {
-                Throwable failureReason = null;
-
-                final Retry retry = method.getAnnotation(Retry.class);
-                if (retry == null) {
-                    // Do a single test run attempt.
-                    singleTryStatement.evaluate();
-                } else {
-                    final int numRetries = retry.value();
-
-                    for (int i = 0; i < numRetries; ++i) {
-                        try {
-                            // Do a single test run attempt.
-                            singleTryStatement.evaluate();
-                            // Attempt succeeded, stop evaluation here.
-                            return;
-                        } catch (Throwable t) {
-                            // Attempt failed, store the reason.
-                            failureReason = t;
-                        }
-                    }
-
-                    // All attempts failed.
-                    throw failureReason;
-                }
-            }
-        };
-    }
-}
diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/RetryRunnerTest.java b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/RetryRunnerTest.java
deleted file mode 100644
index 51718e4..0000000
--- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/RetryRunnerTest.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.math4.legacy;
-
-import java.util.Random;
-
-import org.apache.commons.math4.legacy.exception.MathIllegalStateException;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-/**
- * Test for the "Retry" functionality (retrying Junit test methods).
- */
-@RunWith(RetryRunner.class)
-public class RetryRunnerTest {
-    private final Random rng = new Random();
-
-    /**
-     * Shows that an always failing test will fail even if it is retried.
-     */
-    @Test(expected=MathIllegalStateException.class)
-    @Retry
-    public void testRetryFailAlways() {
-        throw new MathIllegalStateException();
-    }
-
-    /**
-     * Shows that a test that sometimes fail might succeed if it is retried.
-     * In this case the high number of retries makes it quite unlikely that
-     * the exception will be thrown by all of the calls.
-     */
-    @Test
-    @Retry(100)
-    public void testRetryFailSometimes() {
-        if (rng.nextBoolean()) {
-            throw new MathIllegalStateException();
-        }
-    }
-}
diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/CMAESOptimizerTest.java b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/CMAESOptimizerTest.java
index c0f356b..3c23414 100644
--- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/CMAESOptimizerTest.java
+++ b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/CMAESOptimizerTest.java
@@ -16,8 +16,6 @@
  */
 package org.apache.commons.math4.legacy.optim.nonlinear.scalar.noderiv;
 
-import org.apache.commons.math4.legacy.Retry;
-import org.apache.commons.math4.legacy.RetryRunner;
 import org.apache.commons.math4.legacy.analysis.MultivariateFunction;
 import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
 import org.apache.commons.math4.legacy.exception.NotPositiveException;
@@ -41,7 +39,6 @@ import org.junit.runner.RunWith;
 /**
  * Test for {@link CMAESOptimizer}.
  */
-@RunWith(RetryRunner.class)
 public class CMAESOptimizerTest {
 
     static final int DIM = 13;
@@ -125,7 +122,6 @@ public class CMAESOptimizerTest {
     }
 
     @Test
-    @Retry(3)
     public void testRosen() {
         final int dim = 12;
         double[] startPoint = OptimTestUtils.point(dim, 0.1);
@@ -142,7 +138,6 @@ public class CMAESOptimizerTest {
     }
 
     @Test
-    @Retry(3)
     public void testMaximize() {
         double[] startPoint = OptimTestUtils.point(DIM,1.0);
         double[] insigma = OptimTestUtils.point(DIM,0.1);

[commons-math] 01/02: Relax expectations (unit test).

Posted by er...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

erans pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-math.git

commit dd0acaa9ff26939cb3b9a7e4e5b13815d1853d38
Author: Gilles Sadowski <gi...@gmail.com>
AuthorDate: Fri Aug 27 19:15:17 2021 +0200

    Relax expectations (unit test).
---
 .../scalar/noderiv/std_test_func.simplex.multidirectional.csv         | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/commons-math-legacy/src/test/resources/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/std_test_func.simplex.multidirectional.csv b/commons-math-legacy/src/test/resources/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/std_test_func.simplex.multidirectional.csv
index 1e8f88e..ee704aa 100644
--- a/commons-math-legacy/src/test/resources/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/std_test_func.simplex.multidirectional.csv
+++ b/commons-math-legacy/src/test/resources/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/std_test_func.simplex.multidirectional.csv
@@ -32,7 +32,7 @@
 #
 PARABOLA, 8, 0 0 0 0 0 0 0 0, 20, 40, 1e-4, 1500, false
 PARABOLA, 8, 0 0 0 0 0 0 0 0, 20, 40, 1e-4, 2600, true
-PARABOLA, 16, 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0, 20, 40, 1e-4, 5500, false
+PARABOLA, 16, 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0, 20, 40, 1e-4, 5800, false
 PARABOLA, 16, 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0, 20, 40, 1e-4, 10000, true
 ROSENBROCK, 2, 1 1, 0.9, 1.1, 3e-3, 11000, false
 ROSENBROCK, 2, 1 1, 0.9, 1.1, 3e-3, 500, true
@@ -60,7 +60,7 @@ LEVY, 2, 1 1, 0.9, 1.1, 1e-3, 120, false
 SCHWEFEL, 2, 420.9687 420.9687, 9, 11, 1, 120, false
 ZAKHAROV, 2, 0 0, 3, 4, 1e-4, 130, false
 PERM, 2, 1 2, 0.9, 1.1, 2e-3, 24000, false
-PERM, 2, 1 2, 0.9, 1.1, 2e-3, 400, true
+PERM, 2, 1 2, 0.9, 1.1, 2e-3, 430, true
 STYBLINSKI_TANG, 2, -2.903534 -2.903534, 1, 2, 1e-4, 120, false
 #HAPPY_CAT, 2, -1 -1, 2, 3, 1e-4, 50, false
 #SALOMON, 2, 0 0, 2, 3, 1e-4, 50, false