diff --git a/src/main/java/org/apache/commons/math3/optimization/SimplePointChecker.java b/src/main/java/org/apache/commons/math3/optimization/SimplePointChecker.java index f19e7350b..d76a425be 100644 --- a/src/main/java/org/apache/commons/math3/optimization/SimplePointChecker.java +++ b/src/main/java/org/apache/commons/math3/optimization/SimplePointChecker.java @@ -87,8 +87,7 @@ public class SimplePointChecker> * * @param relativeThreshold Relative tolerance threshold. * @param absoluteThreshold Absolute tolerance threshold. - * @param maxIter Maximum iteration count. Setting it to a negative - * value will disable this stopping criterion. + * @param maxIter Maximum iteration count. * @throws NotStrictlyPositiveException if {@code maxIter <= 0}. * * @since 3.1 diff --git a/src/main/java/org/apache/commons/math3/optimization/SimpleValueChecker.java b/src/main/java/org/apache/commons/math3/optimization/SimpleValueChecker.java index fe29b5916..1412d8ad1 100644 --- a/src/main/java/org/apache/commons/math3/optimization/SimpleValueChecker.java +++ b/src/main/java/org/apache/commons/math3/optimization/SimpleValueChecker.java @@ -85,8 +85,7 @@ public class SimpleValueChecker * * @param relativeThreshold relative tolerance threshold * @param absoluteThreshold absolute tolerance threshold - * @param maxIter Maximum iteration count. Setting it to a negative - * value will disable this stopping criterion. + * @param maxIter Maximum iteration count. * @throws NotStrictlyPositiveException if {@code maxIter <= 0}. * * @since 3.1 diff --git a/src/main/java/org/apache/commons/math3/optimization/SimpleVectorValueChecker.java b/src/main/java/org/apache/commons/math3/optimization/SimpleVectorValueChecker.java index a823ed46b..3f2f04481 100644 --- a/src/main/java/org/apache/commons/math3/optimization/SimpleVectorValueChecker.java +++ b/src/main/java/org/apache/commons/math3/optimization/SimpleVectorValueChecker.java @@ -87,8 +87,7 @@ public class SimpleVectorValueChecker * * @param relativeThreshold Relative tolerance threshold. * @param absoluteThreshold Absolute tolerance threshold. - * @param maxIter Maximum iteration count. Setting it to a negative - * value will disable this stopping criterion. + * @param maxIter Maximum iteration count. * @throws NotStrictlyPositiveException if {@code maxIter <= 0}. * * @since 3.1 diff --git a/src/test/java/org/apache/commons/math3/optimization/SimplePointCheckerTest.java b/src/test/java/org/apache/commons/math3/optimization/SimplePointCheckerTest.java new file mode 100644 index 000000000..03e5f6379 --- /dev/null +++ b/src/test/java/org/apache/commons/math3/optimization/SimplePointCheckerTest.java @@ -0,0 +1,54 @@ +/* + * 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.math3.optimization; + +import org.apache.commons.math3.exception.NotStrictlyPositiveException; +import org.junit.Test; +import org.junit.Assert; + +public class SimplePointCheckerTest { + @Test(expected=NotStrictlyPositiveException.class) + public void testIterationCheckPrecondition() { + new SimplePointChecker(1e-1, 1e-2, 0); + } + + @Test + public void testIterationCheck() { + final int max = 10; + final SimplePointChecker checker + = new SimplePointChecker(1e-1, 1e-2, max); + Assert.assertTrue(checker.converged(max, null, null)); + Assert.assertTrue(checker.converged(max + 1, null, null)); + } + + @Test + public void testIterationCheckDisabled() { + final SimplePointChecker checker + = new SimplePointChecker(1e-8, 1e-8); + + final PointValuePair a = new PointValuePair(new double[] { 1d }, 1d); + final PointValuePair b = new PointValuePair(new double[] { 10d }, 10d); + + Assert.assertFalse(checker.converged(-1, a, b)); + Assert.assertFalse(checker.converged(0, a, b)); + Assert.assertFalse(checker.converged(1000000, a, b)); + + Assert.assertTrue(checker.converged(-1, a, a)); + Assert.assertTrue(checker.converged(-1, b, b)); + } + +} diff --git a/src/test/java/org/apache/commons/math3/optimization/SimpleValueCheckerTest.java b/src/test/java/org/apache/commons/math3/optimization/SimpleValueCheckerTest.java new file mode 100644 index 000000000..668ffbd16 --- /dev/null +++ b/src/test/java/org/apache/commons/math3/optimization/SimpleValueCheckerTest.java @@ -0,0 +1,52 @@ +/* + * 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.math3.optimization; + +import org.apache.commons.math3.exception.NotStrictlyPositiveException; +import org.junit.Test; +import org.junit.Assert; + +public class SimpleValueCheckerTest { + @Test(expected=NotStrictlyPositiveException.class) + public void testIterationCheckPrecondition() { + new SimpleValueChecker(1e-1, 1e-2, 0); + } + + @Test + public void testIterationCheck() { + final int max = 10; + final SimpleValueChecker checker = new SimpleValueChecker(1e-1, 1e-2, max); + Assert.assertTrue(checker.converged(max, null, null)); + Assert.assertTrue(checker.converged(max + 1, null, null)); + } + + @Test + public void testIterationCheckDisabled() { + final SimpleValueChecker checker = new SimpleValueChecker(1e-8, 1e-8); + + final PointValuePair a = new PointValuePair(new double[] { 1d }, 1d); + final PointValuePair b = new PointValuePair(new double[] { 10d }, 10d); + + Assert.assertFalse(checker.converged(-1, a, b)); + Assert.assertFalse(checker.converged(0, a, b)); + Assert.assertFalse(checker.converged(1000000, a, b)); + + Assert.assertTrue(checker.converged(-1, a, a)); + Assert.assertTrue(checker.converged(-1, b, b)); + } + +} diff --git a/src/test/java/org/apache/commons/math3/optimization/SimpleVectorValueCheckerTest.java b/src/test/java/org/apache/commons/math3/optimization/SimpleVectorValueCheckerTest.java new file mode 100644 index 000000000..3730b443a --- /dev/null +++ b/src/test/java/org/apache/commons/math3/optimization/SimpleVectorValueCheckerTest.java @@ -0,0 +1,54 @@ +/* + * 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.math3.optimization; + +import org.apache.commons.math3.exception.NotStrictlyPositiveException; +import org.junit.Test; +import org.junit.Assert; + +public class SimpleVectorValueCheckerTest { + @Test(expected=NotStrictlyPositiveException.class) + public void testIterationCheckPrecondition() { + new SimpleVectorValueChecker(1e-1, 1e-2, 0); + } + + @Test + public void testIterationCheck() { + final int max = 10; + final SimpleVectorValueChecker checker = new SimpleVectorValueChecker(1e-1, 1e-2, max); + Assert.assertTrue(checker.converged(max, null, null)); + Assert.assertTrue(checker.converged(max + 1, null, null)); + } + + @Test + public void testIterationCheckDisabled() { + final SimpleVectorValueChecker checker = new SimpleVectorValueChecker(1e-8, 1e-8); + + final PointVectorValuePair a = new PointVectorValuePair(new double[] { 1d }, + new double[] { 1d }); + final PointVectorValuePair b = new PointVectorValuePair(new double[] { 10d }, + new double[] { 10d }); + + Assert.assertFalse(checker.converged(-1, a, b)); + Assert.assertFalse(checker.converged(0, a, b)); + Assert.assertFalse(checker.converged(1000000, a, b)); + + Assert.assertTrue(checker.converged(-1, a, a)); + Assert.assertTrue(checker.converged(-1, b, b)); + } + +}