This is an automated email from the ASF dual-hosted git repository. erans pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-numbers.git
commit 18135b9d149de8b81d8f81a5586864f586b1f501 Author: Schamschi <[email protected]> AuthorDate: Tue Jun 18 23:54:26 2019 +0200 NUMBERS-117: Remove redundant methods in org.apache.commons.numbers.complex.TestUtils Remove the following methods: assertEquals(double, double, double) assertEquals(String, double, double, double) assertSame(double, double) assertEquals(double[], double[], double) assertEquals(String, double[], double[], double) assertEquals(String, float[], float[], float) equalsIncludingNaN(double, double, double) Remove the following private method that became unused after the removal of the above methods: equalsIncludingNaN(double, double) --- .../apache/commons/numbers/complex/TestUtils.java | 131 +-------------------- 1 file changed, 4 insertions(+), 127 deletions(-) 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 484dc07..3fae6c5 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 @@ -41,42 +41,12 @@ public class TestUtils { } /** - * Verifies that expected and actual are within delta, or are both NaN or - * infinities of the same sign. - */ - public static void assertEquals(double expected, double actual, double delta) { - Assertions.assertEquals(expected, actual, delta, (String) null); - } - - /** - * Verifies that expected and actual are within delta, or are both NaN or - * infinities of the same sign. - */ - public static void assertEquals(String msg, double expected, double actual, double delta) { - // check for NaN - if(Double.isNaN(expected)){ - Assertions.assertTrue(Double.isNaN(actual), - "" + actual + " is not NaN."); - } else { - Assertions.assertEquals(expected, actual, delta, msg); - } - } - - /** - * Verifies that the two arguments are exactly the same, either - * both NaN or infinities of same sign, or identical floating point values. - */ - public static void assertSame(double expected, double actual) { - Assertions.assertEquals(expected, actual, 0); - } - - /** * Verifies that real and imaginary parts of the two complex arguments * are exactly the same. Also ensures that NaN / infinite components match. */ public static void assertSame(Complex expected, Complex actual) { - assertSame(expected.getReal(), actual.getReal()); - assertSame(expected.getImaginary(), actual.getImaginary()); + Assertions.assertEquals(expected.getReal(), actual.getReal()); + Assertions.assertEquals(expected.getImaginary(), actual.getImaginary()); } /** @@ -89,13 +59,6 @@ public class TestUtils { } /** - * Verifies that two double arrays have equal entries, up to tolerance - */ - public static void assertEquals(double expected[], double observed[], double tolerance) { - assertEquals("Array comparison failure", expected, observed, tolerance); - } - - /** * Serializes an object to a bytes array and then recovers the object from the bytes array. * Returns the deserialized object. * @@ -234,64 +197,6 @@ public class TestUtils { } /** verifies that two arrays are close (sup norm) */ - public static void assertEquals(String msg, double[] expected, double[] observed, double tolerance) { - StringBuilder out = new StringBuilder(msg); - if (expected.length != observed.length) { - out.append("\n Arrays not same length. \n"); - out.append("expected has length "); - out.append(expected.length); - out.append(" observed length = "); - out.append(observed.length); - Assertions.fail(out.toString()); - } - boolean failure = false; - for (int i=0; i < expected.length; i++) { - if (!equalsIncludingNaN(expected[i], observed[i], tolerance)) { - failure = true; - out.append("\n Elements at index "); - out.append(i); - out.append(" differ. "); - out.append(" expected = "); - out.append(expected[i]); - out.append(" observed = "); - out.append(observed[i]); - } - } - if (failure) { - Assertions.fail(out.toString()); - } - } - - /** verifies that two arrays are close (sup norm) */ - public static void assertEquals(String msg, float[] expected, float[] observed, float tolerance) { - StringBuilder out = new StringBuilder(msg); - if (expected.length != observed.length) { - out.append("\n Arrays not same length. \n"); - out.append("expected has length "); - out.append(expected.length); - out.append(" observed length = "); - out.append(observed.length); - Assertions.fail(out.toString()); - } - boolean failure = false; - for (int i=0; i < expected.length; i++) { - if (!equalsIncludingNaN(expected[i], observed[i], tolerance)) { - failure = true; - out.append("\n Elements at index "); - out.append(i); - out.append(" differ. "); - out.append(" expected = "); - out.append(expected[i]); - out.append(" observed = "); - out.append(observed[i]); - } - } - if (failure) { - Assertions.fail(out.toString()); - } - } - - /** verifies that two arrays are close (sup norm) */ public static void assertEquals(String msg, Complex[] expected, Complex[] observed, double tolerance) { StringBuilder out = new StringBuilder(msg); if (expected.length != observed.length) { @@ -304,7 +209,7 @@ public class TestUtils { } boolean failure = false; for (int i=0; i < expected.length; i++) { - if (!equalsIncludingNaN(expected[i].getReal(), observed[i].getReal(), tolerance)) { + if (!Precision.equalsIncludingNaN(expected[i].getReal(), observed[i].getReal(), tolerance)) { failure = true; out.append("\n Real elements at index "); out.append(i); @@ -314,7 +219,7 @@ public class TestUtils { out.append(" observed = "); out.append(observed[i].getReal()); } - if (!equalsIncludingNaN(expected[i].getImaginary(), observed[i].getImaginary(), tolerance)) { + if (!Precision.equalsIncludingNaN(expected[i].getImaginary(), observed[i].getImaginary(), tolerance)) { failure = true; out.append("\n Imaginary elements at index "); out.append(i); @@ -375,34 +280,6 @@ public class TestUtils { } return positiveMassCount; } - - /** - * Returns true if the arguments are both NaN, are equal or are within the range - * of allowed error (inclusive). - * - * @param x first value - * @param y second value - * @param eps the amount of absolute error to allow. - * @return {@code true} if the values are equal or within range of each other, - * or both are NaN. - */ - private static boolean equalsIncludingNaN(double x, double y, double eps) { - return equalsIncludingNaN(x, y) || (Math.abs(y - x) <= eps); - } - - /** - * Returns true if the arguments are both NaN or they are - * equal as defined by {@link #equals(double,double) equals(x, y, 1)}. - * - * @param x first value - * @param y second value - * @return {@code true} if the values are equal or both are NaN. - */ - private static boolean equalsIncludingNaN(double x, double y) { - return (x != x || y != y) ? !(x != x ^ y != y) : Precision.equals(x, y, 1); - } - - }
