This is an automated email from the ASF dual-hosted git repository. aherbert pushed a commit to branch complex-gsoc-2022 in repository https://gitbox.apache.org/repos/asf/commons-numbers.git
commit 8270297571275b1cf0c80f068d8ebb9b2de9512d Author: aherbert <aherb...@apache.org> AuthorDate: Wed Jul 20 11:22:07 2022 +0100 Update formatting of new assertion methods Consistent javadoc conventions. Ensure the operation name appears before the two operations. Drop inline checkstyle exclusion. This is now in the suppressions file. --- .../commons/numbers/complex/CReferenceTest.java | 28 +++--- .../commons/numbers/complex/CStandardTest.java | 112 ++++++++++----------- .../numbers/complex/ComplexEdgeCaseTest.java | 13 ++- .../commons/numbers/complex/ComplexTest.java | 4 +- .../apache/commons/numbers/complex/TestUtils.java | 16 +-- 5 files changed, 84 insertions(+), 89 deletions(-) diff --git a/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/CReferenceTest.java b/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/CReferenceTest.java index dd283af3..1a139053 100644 --- a/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/CReferenceTest.java +++ b/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/CReferenceTest.java @@ -154,25 +154,23 @@ class CReferenceTest { * * <p>Numbers must have the same sign. Thus -0.0 and 0.0 are never equal. * - * Assert the operation on the complex number is <em>exactly</em> equal to the operation on + * <p>Assert the operation on the complex number is <em>exactly</em> equal to the operation on * complex real and imaginary parts. * - * @param c Input complex number. + * @param c Input number. * @param name Operation name. * @param operation1 Operation on the Complex object. * @param operation2 Operation on the complex real and imaginary parts. * @param expected Expected result. + * @param maxUlps Maximum units of least precision between the two values. */ static void assertComplex(Complex c, - String name, - UnaryOperator<Complex> operation1, - ComplexUnaryOperator<ComplexNumber> operation2, - Complex expected, long maxUlps) { - - final Complex z = TestUtils.assertSame(c, operation1, operation2, name); - - assertEquals(() -> "UnaryOperator " + name + "(" + c + "): real", expected.real(), z.real(), maxUlps); - assertEquals(() -> "UnaryOperator " + name + "(" + c + "): imaginary", expected.imag(), z.imag(), maxUlps); + String name, UnaryOperator<Complex> operation1, + ComplexUnaryOperator<ComplexNumber> operation2, + Complex expected, long maxUlps) { + final Complex z = TestUtils.assertSame(c, name, operation1, operation2); + assertEquals(() -> c + "." + name + "(): real", expected.real(), z.real(), maxUlps); + assertEquals(() -> c + "." + name + "(): imaginary", expected.imag(), z.imag(), maxUlps); } /** @@ -257,15 +255,15 @@ class CReferenceTest { /** * Assert the operation using the data loaded from test resources. * - * @param name Operation name + * @param name Operation name. * @param operation1 Operation on the Complex object. * @param operation2 Operation on the complex real and imaginary parts. * @param maxUlps Maximum units of least precision between the two values. */ private static void assertOperation(String name, - UnaryOperator<Complex> operation1, - ComplexUnaryOperator<ComplexNumber> operation2, - long maxUlps) { + UnaryOperator<Complex> operation1, + ComplexUnaryOperator<ComplexNumber> operation2, + long maxUlps) { final List<Complex[]> data = loadTestData(name); final long ulps = getTestUlps(maxUlps); for (final Complex[] pair : data) { diff --git a/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/CStandardTest.java b/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/CStandardTest.java index edd3c435..5d02360e 100644 --- a/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/CStandardTest.java +++ b/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/CStandardTest.java @@ -330,13 +330,13 @@ class CStandardTest { * <li>sinh(inf, nan) * </ul> * + * @param name Operation name. * @param operation1 Operation on the Complex object. * @param operation2 Operation on the complex real and imaginary parts. - * @param name Operation name. */ - private static void assertConjugateEquality(UnaryOperator<Complex> operation1, - ComplexUnaryOperator<ComplexNumber> operation2, - String name) { + private static void assertConjugateEquality(String name, + UnaryOperator<Complex> operation1, + ComplexUnaryOperator<ComplexNumber> operation2) { // Edge cases. Inf/NaN are specifically handled in the C99 test cases // but are repeated here to enforce the conjugate equality even when the C99 // standard does not specify a sign. This may be revised in the future. @@ -346,7 +346,7 @@ class CStandardTest { for (final double y : parts) { // No conjugate for imaginary NaN if (!Double.isNaN(y)) { - assertConjugateEquality(complex(x, y), operation1, operation2, UnspecifiedSign.NONE, name); + assertConjugateEquality(complex(x, y), name, operation1, operation2, UnspecifiedSign.NONE); } } } @@ -355,7 +355,7 @@ class CStandardTest { for (int i = 0; i < 100; i++) { final double x = next(rng); final double y = next(rng); - assertConjugateEquality(complex(x, y), operation1, operation2, UnspecifiedSign.NONE, name); + assertConjugateEquality(complex(x, y), name, operation1, operation2, UnspecifiedSign.NONE); } } @@ -379,13 +379,13 @@ class CStandardTest { * @param name Operation name. */ private static void assertConjugateEquality(Complex z, - UnaryOperator<Complex> operation1, - ComplexUnaryOperator<ComplexNumber> operation2, - UnspecifiedSign sign, String name) { + String name, UnaryOperator<Complex> operation1, + ComplexUnaryOperator<ComplexNumber> operation2, + UnspecifiedSign sign) { final Complex zConj = z.conj(); - final Complex c1 = TestUtils.assertSame(zConj, operation1, operation2, name); - final Complex c2 = TestUtils.assertSame(z, operation1, operation2, name).conj(); + final Complex c1 = TestUtils.assertSame(zConj, name, operation1, operation2); + final Complex c2 = TestUtils.assertSame(z, name, operation1, operation2).conj(); final Complex t1 = sign.removeSign(c1); final Complex t2 = sign.removeSign(c2); @@ -621,16 +621,16 @@ class CStandardTest { * complex real and imaginary parts. * * @param z Input complex number. + * @param name Operation name. * @param operation1 Operation on the Complex object. * @param operation2 Operation on the complex real and imaginary parts. * @param expected Expected complex number. - * @param name Operation name. */ private static void assertComplex(Complex z, - UnaryOperator<Complex> operation1, - ComplexUnaryOperator<ComplexNumber> operation2, - Complex expected, String name) { - assertComplex(z, operation1, operation2, expected, FunctionType.NONE, UnspecifiedSign.NONE, name); + String name, UnaryOperator<Complex> operation1, + ComplexUnaryOperator<ComplexNumber> operation2, + Complex expected) { + assertComplex(z, name, operation1, operation2, expected, FunctionType.NONE, UnspecifiedSign.NONE); } /** @@ -658,28 +658,24 @@ class CStandardTest { * complex real and imaginary parts. * * @param z Input complex number. + * @param name Operation name. * @param operation1 Operation on the Complex object. * @param operation2 Operation on the complex real and imaginary parts. * @param expected Expected complex number. - * @param type the type - * @param sign the sign specification - * @param name Operation name. + * @param type Function type. + * @param sign Function sign specification. */ private static void assertComplex(Complex z, - UnaryOperator<Complex> operation1, - ComplexUnaryOperator<ComplexNumber> operation2, - Complex expected, - FunctionType type, - UnspecifiedSign sign, - String name) { - + String name, UnaryOperator<Complex> operation1, + ComplexUnaryOperator<ComplexNumber> operation2, + Complex expected, FunctionType type, UnspecifiedSign sign) { // Developer note: Set the sign specification to UnspecifiedSign.NONE // to see which equalities fail. They should be for input defined // in ISO C99 with an unspecified output sign, e.g. // sign = UnspecifiedSign.NONE // Test the operation - final Complex c = TestUtils.assertSame(z, operation1, operation2, name); + final Complex c = TestUtils.assertSame(z, name, operation1, operation2); final Complex t1 = sign.removeSign(c); final Complex t2 = sign.removeSign(expected); @@ -691,7 +687,7 @@ class CStandardTest { } if (!Double.isNaN(z.getImaginary())) { - assertConjugateEquality(z, operation1, operation2, sign, name); + assertConjugateEquality(z, name, operation1, operation2, sign); } if (type != FunctionType.NONE) { @@ -705,7 +701,7 @@ class CStandardTest { // = -(-re, -im) (odd) // (-re, -im) = (-re, im) if (!Double.isNaN(z.getImaginary())) { - assertConjugateEquality(z.negate(), operation1, operation2, sign, name); + assertConjugateEquality(z.negate(), name, operation1, operation2, sign); } } } @@ -1438,33 +1434,34 @@ class CStandardTest { */ @Test void testLog() { + final String name = "log"; final UnaryOperator<Complex> operation1 = Complex::log; final ComplexUnaryOperator<ComplexNumber> operation2 = ComplexFunctions::log; - assertConjugateEquality(operation1, operation2, "log"); - assertComplex(negZeroZero, operation1, operation2, negInfPi, "log"); - assertComplex(Complex.ZERO, operation1, operation2, negInfZero, "log"); + assertConjugateEquality(name, operation1, operation2); + assertComplex(negZeroZero, name, operation1, operation2, negInfPi); + assertComplex(Complex.ZERO, name, operation1, operation2, negInfZero); for (double x : finite) { - assertComplex(complex(x, inf), operation1, operation2, infPiTwo, "log"); + assertComplex(complex(x, inf), name, operation1, operation2, infPiTwo); } for (double x : finite) { - assertComplex(complex(x, nan), operation1, operation2, NAN, "log"); + assertComplex(complex(x, nan), name, operation1, operation2, NAN); } for (double y : positiveFinite) { - assertComplex(complex(-inf, y), operation1, operation2, infPi, "log"); + assertComplex(complex(-inf, y), name, operation1, operation2, infPi); } for (double y : positiveFinite) { - assertComplex(complex(inf, y), operation1, operation2, infZero, "log"); + assertComplex(complex(inf, y), name, operation1, operation2, infZero); } - assertComplex(negInfInf, operation1, operation2, infThreePiFour, "log"); - assertComplex(infInf, operation1, operation2, infPiFour, "log"); - assertComplex(negInfNaN, operation1, operation2, infNaN, "log"); - assertComplex(infNaN, operation1, operation2, infNaN, "log"); + assertComplex(negInfInf, name, operation1, operation2, infThreePiFour); + assertComplex(infInf, name, operation1, operation2, infPiFour); + assertComplex(negInfNaN, name, operation1, operation2, infNaN); + assertComplex(infNaN, name, operation1, operation2, infNaN); for (double y : finite) { - assertComplex(complex(nan, y), operation1, operation2, NAN, "log"); + assertComplex(complex(nan, y), name, operation1, operation2, NAN); } - assertComplex(nanInf, operation1, operation2, infNaN, "log"); - assertComplex(NAN, operation1, operation2, NAN, "log"); + assertComplex(nanInf, name, operation1, operation2, infNaN); + assertComplex(NAN, name, operation1, operation2, NAN); } /** @@ -1473,33 +1470,34 @@ class CStandardTest { */ @Test void testLog10() { + final String name = "log10"; final UnaryOperator<Complex> operation1 = Complex::log10; final ComplexUnaryOperator<ComplexNumber> operation2 = ComplexFunctions::log10; - assertConjugateEquality(operation1, operation2, "log10"); - assertComplex(negZeroZero, operation1, operation2, negInfPi, "log10"); - assertComplex(Complex.ZERO, operation1, operation2, negInfZero, "log10"); + assertConjugateEquality(name, operation1, operation2); + assertComplex(negZeroZero, name, operation1, operation2, negInfPi); + assertComplex(Complex.ZERO, name, operation1, operation2, negInfZero); for (double x : finite) { - assertComplex(complex(x, inf), operation1, operation2, infPiTwo, "log10"); + assertComplex(complex(x, inf), name, operation1, operation2, infPiTwo); } for (double x : finite) { - assertComplex(complex(x, nan), operation1, operation2, NAN, "log10"); + assertComplex(complex(x, nan), name, operation1, operation2, NAN); } for (double y : positiveFinite) { - assertComplex(complex(-inf, y), operation1, operation2, infPi, "log10"); + assertComplex(complex(-inf, y), name, operation1, operation2, infPi); } for (double y : positiveFinite) { - assertComplex(complex(inf, y), operation1, operation2, infZero, "log10"); + assertComplex(complex(inf, y), name, operation1, operation2, infZero); } - assertComplex(negInfInf, operation1, operation2, infThreePiFour, "log10"); - assertComplex(infInf, operation1, operation2, infPiFour, "log10"); - assertComplex(negInfNaN, operation1, operation2, infNaN, "log10"); - assertComplex(infNaN, operation1, operation2, infNaN, "log10"); + assertComplex(negInfInf, name, operation1, operation2, infThreePiFour); + assertComplex(infInf, name, operation1, operation2, infPiFour); + assertComplex(negInfNaN, name, operation1, operation2, infNaN); + assertComplex(infNaN, name, operation1, operation2, infNaN); for (double y : finite) { - assertComplex(complex(nan, y), operation1, operation2, NAN, "log10"); + assertComplex(complex(nan, y), name, operation1, operation2, NAN); } - assertComplex(nanInf, operation1, operation2, infNaN, "log10"); - assertComplex(NAN, operation1, operation2, NAN, "log10"); + assertComplex(nanInf, name, operation1, operation2, infNaN); + assertComplex(NAN, name, operation1, operation2, NAN); } /** diff --git a/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexEdgeCaseTest.java b/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexEdgeCaseTest.java index c0e31008..3fd467ff 100644 --- a/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexEdgeCaseTest.java +++ b/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexEdgeCaseTest.java @@ -98,9 +98,9 @@ class ComplexEdgeCaseTest { * @param y Expected imaginary part. */ private static void assertComplex(double a, double b, - String name, UnaryOperator<Complex> operation1, - ComplexUnaryOperator<ComplexNumber> operation2, - double x, double y) { + String name, UnaryOperator<Complex> operation1, + ComplexUnaryOperator<ComplexNumber> operation2, + double x, double y) { assertComplex(a, b, name, operation1, operation2, x, y, 1); } @@ -124,9 +124,9 @@ class ComplexEdgeCaseTest { * @param maxUlps Maximum units of least precision between the two values. */ private static void assertComplex(double a, double b, - String name, UnaryOperator<Complex> operation1, - ComplexUnaryOperator<ComplexNumber> operation2, - double x, double y, long maxUlps) { + String name, UnaryOperator<Complex> operation1, + ComplexUnaryOperator<ComplexNumber> operation2, + double x, double y, long maxUlps) { final Complex c = Complex.ofCartesian(a, b); final Complex e = Complex.ofCartesian(x, y); CReferenceTest.assertComplex(c, name, operation1, operation2, e, maxUlps); @@ -146,7 +146,6 @@ class ComplexEdgeCaseTest { * @param x Expected real part. * @param y Expected imaginary part. */ - // CHECKSTYLE: stop ParameterNumberCheck private static void assertComplex(double a, double b, double c, double d, String name, BiFunction<Complex, Complex, Complex> operation, double x, double y) { diff --git a/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexTest.java b/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexTest.java index fb358872..657d2d75 100644 --- a/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexTest.java +++ b/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexTest.java @@ -1417,8 +1417,8 @@ class ComplexTest { final UniformRandomProvider rng = RandomSource.SPLIT_MIX_64.create(); for (int i = 0; i < 10; i++) { final Complex z = Complex.ofCartesian(rng.nextDouble() * 2, rng.nextDouble() * 2); - final Complex lnz = TestUtils.assertSame(z, Complex::log, ComplexFunctions::log, "log"); - final Complex log10z = TestUtils.assertSame(z, Complex::log10, ComplexFunctions::log10, "log10"); + final Complex lnz = TestUtils.assertSame(z, "log", Complex::log, ComplexFunctions::log); + final Complex log10z = TestUtils.assertSame(z, "log10", Complex::log10, ComplexFunctions::log10); // This is prone to floating-point error so use a delta Assertions.assertEquals(lnz.getReal() / ln10, log10z.getReal(), 1e-12, "real"); diff --git a/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/TestUtils.java b/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/TestUtils.java index 6efd2b36..e3d86a60 100644 --- a/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/TestUtils.java +++ b/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/TestUtils.java @@ -394,20 +394,20 @@ public final class TestUtils { * complex real and imaginary parts. * * @param c Input complex number. + * @param name Operation name. * @param operation1 Operation on the Complex object. * @param operation2 Operation on the complex real and imaginary parts. - * @param name Operation name. - * @return Resulting complex number from the given operation. + * @return Result complex number from the given operation. */ - static Complex assertSame(Complex c, - UnaryOperator<Complex> operation1, - ComplexUnaryOperator<ComplexNumber> operation2, - String name) { + public static Complex assertSame(Complex c, + String name, + UnaryOperator<Complex> operation1, + ComplexUnaryOperator<ComplexNumber> operation2) { final Complex z = operation1.apply(c); // Test operation2 produces the exact same result final ComplexNumber z2 = operation2.apply(c.real(), c.imag(), ComplexNumber::new); - Assertions.assertEquals(z.real(), z2.getReal(), () -> name + " real"); - Assertions.assertEquals(z.imag(), z2.getImaginary(), () -> name + " imaginary"); + Assertions.assertEquals(z.real(), z2.getReal(), () -> "Unary operator mismatch: " + name + " real"); + Assertions.assertEquals(z.imag(), z2.getImaginary(), () -> "Unary operator mismatch: " + name + " imaginary"); return z; } }