From 56b28f34d934efa0db1b753e83161fe12f8e44b1 Mon Sep 17 00:00:00 2001 From: Gilles Date: Wed, 28 Feb 2018 02:41:47 +0100 Subject: [PATCH] MATH-1416: Depend on "Commons Numbers". --- .../analysis/solvers/LaguerreSolver.java | 4 +- .../analysis/solvers/LaguerreSolverTest.java | 37 +++++++++++++++++-- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/apache/commons/math4/analysis/solvers/LaguerreSolver.java b/src/main/java/org/apache/commons/math4/analysis/solvers/LaguerreSolver.java index ab01885ef..f0ecdc864 100644 --- a/src/main/java/org/apache/commons/math4/analysis/solvers/LaguerreSolver.java +++ b/src/main/java/org/apache/commons/math4/analysis/solvers/LaguerreSolver.java @@ -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; diff --git a/src/test/java/org/apache/commons/math4/analysis/solvers/LaguerreSolverTest.java b/src/test/java/org/apache/commons/math4/analysis/solvers/LaguerreSolverTest.java index 610071062..caee1cc65 100644 --- a/src/test/java/org/apache/commons/math4/analysis/solvers/LaguerreSolverTest.java +++ b/src/test/java/org/apache/commons/math4/analysis/solvers/LaguerreSolverTest.java @@ -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); + } }