MATH-902
Fixed Javadoc. Added unit tests. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1412713 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ccf9403db5
commit
04c63b1630
|
@ -87,8 +87,7 @@ public class SimplePointChecker<PAIR extends Pair<double[], ? extends Object>>
|
||||||
*
|
*
|
||||||
* @param relativeThreshold Relative tolerance threshold.
|
* @param relativeThreshold Relative tolerance threshold.
|
||||||
* @param absoluteThreshold Absolute tolerance threshold.
|
* @param absoluteThreshold Absolute tolerance threshold.
|
||||||
* @param maxIter Maximum iteration count. Setting it to a negative
|
* @param maxIter Maximum iteration count.
|
||||||
* value will disable this stopping criterion.
|
|
||||||
* @throws NotStrictlyPositiveException if {@code maxIter <= 0}.
|
* @throws NotStrictlyPositiveException if {@code maxIter <= 0}.
|
||||||
*
|
*
|
||||||
* @since 3.1
|
* @since 3.1
|
||||||
|
|
|
@ -85,8 +85,7 @@ public class SimpleValueChecker
|
||||||
*
|
*
|
||||||
* @param relativeThreshold relative tolerance threshold
|
* @param relativeThreshold relative tolerance threshold
|
||||||
* @param absoluteThreshold absolute tolerance threshold
|
* @param absoluteThreshold absolute tolerance threshold
|
||||||
* @param maxIter Maximum iteration count. Setting it to a negative
|
* @param maxIter Maximum iteration count.
|
||||||
* value will disable this stopping criterion.
|
|
||||||
* @throws NotStrictlyPositiveException if {@code maxIter <= 0}.
|
* @throws NotStrictlyPositiveException if {@code maxIter <= 0}.
|
||||||
*
|
*
|
||||||
* @since 3.1
|
* @since 3.1
|
||||||
|
|
|
@ -87,8 +87,7 @@ public class SimpleVectorValueChecker
|
||||||
*
|
*
|
||||||
* @param relativeThreshold Relative tolerance threshold.
|
* @param relativeThreshold Relative tolerance threshold.
|
||||||
* @param absoluteThreshold Absolute tolerance threshold.
|
* @param absoluteThreshold Absolute tolerance threshold.
|
||||||
* @param maxIter Maximum iteration count. Setting it to a negative
|
* @param maxIter Maximum iteration count.
|
||||||
* value will disable this stopping criterion.
|
|
||||||
* @throws NotStrictlyPositiveException if {@code maxIter <= 0}.
|
* @throws NotStrictlyPositiveException if {@code maxIter <= 0}.
|
||||||
*
|
*
|
||||||
* @since 3.1
|
* @since 3.1
|
||||||
|
|
|
@ -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<PointValuePair>(1e-1, 1e-2, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIterationCheck() {
|
||||||
|
final int max = 10;
|
||||||
|
final SimplePointChecker<PointValuePair> checker
|
||||||
|
= new SimplePointChecker<PointValuePair>(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<PointValuePair> checker
|
||||||
|
= new SimplePointChecker<PointValuePair>(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));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue