MATH-1416: Depend on "Commons Numbers".

This commit is contained in:
Gilles 2018-02-28 02:41:47 +01:00
parent db37a6d844
commit 56b28f34d9
2 changed files with 36 additions and 5 deletions

View File

@ -16,9 +16,9 @@
*/
package org.apache.commons.math4.analysis.solvers;
import org.apache.commons.numbers.complex.Complex;
import org.apache.commons.numbers.complex.ComplexUtils;
import org.apache.commons.math4.analysis.polynomials.PolynomialFunction;
import org.apache.commons.math4.complex.Complex;
import org.apache.commons.math4.complex.ComplexUtils;
import org.apache.commons.math4.exception.NoBracketingException;
import org.apache.commons.math4.exception.NoDataException;
import org.apache.commons.math4.exception.NullArgumentException;

View File

@ -16,10 +16,10 @@
*/
package org.apache.commons.math4.analysis.solvers;
import org.apache.commons.math4.TestUtils;
import org.apache.commons.numbers.complex.Complex;
import org.apache.commons.numbers.core.Precision;
import org.apache.commons.math4.analysis.polynomials.PolynomialFunction;
import org.apache.commons.math4.analysis.solvers.LaguerreSolver;
import org.apache.commons.math4.complex.Complex;
import org.apache.commons.math4.exception.NoBracketingException;
import org.apache.commons.math4.exception.NumberIsTooLargeException;
import org.apache.commons.math4.util.FastMath;
@ -129,7 +129,7 @@ public final class LaguerreSolverTest {
new Complex(0.5, -0.5 * FastMath.sqrt(3.0)) }) {
final double tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
FastMath.abs(expected.abs() * solver.getRelativeAccuracy()));
TestUtils.assertContains(result, expected, tolerance);
assertContains(result, expected, tolerance);
}
}
@ -157,4 +157,35 @@ public final class LaguerreSolverTest {
// expected
}
}
/**
* Fails iff values does not contain a number within epsilon of z.
*
* @param msg message to return with failure
* @param values complex array to search
* @param z value sought
* @param epsilon tolerance
*/
private static void assertContains(String msg, Complex[] values,
Complex z, double epsilon) {
for (Complex value : values) {
if (Precision.equals(value.getReal(), z.getReal(), epsilon) &&
Precision.equals(value.getImaginary(), z.getImaginary(), epsilon)) {
return;
}
}
Assert.fail(msg + " Unable to find " + z);
}
/**
* Fails iff values does not contain a number within epsilon of z.
*
* @param values complex array to search
* @param z value sought
* @param epsilon tolerance
*/
private static void assertContains(Complex[] values,
Complex z, double epsilon) {
assertContains(null, values, z, epsilon);
}
}