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 0c90ec596064c0c25f23cd351006ad0d22647887 Author: Schamschi <[email protected]> AuthorDate: Tue Jun 18 23:49:17 2019 +0200 NUMBERS-117: Remove redundant methods in org.apache.commons.numbers.core.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) Remove the following private methods that became unused after the removal of the above methods: equalsIncludingNaN(double, double, double) equalsIncludingNaN(double, double) --- .../apache/commons/numbers/core/PrecisionTest.java | 2 +- .../org/apache/commons/numbers/core/TestUtils.java | 123 --------------------- 2 files changed, 1 insertion(+), 124 deletions(-) diff --git a/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/PrecisionTest.java b/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/PrecisionTest.java index 9433a63..dc231bf 100644 --- a/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/PrecisionTest.java +++ b/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/PrecisionTest.java @@ -378,7 +378,7 @@ public class PrecisionTest { Assertions.assertEquals(39.25, Precision.round(39.245, 2, RoundingMode.HALF_UP), 0.0); // special values - TestUtils.assertEquals(Double.NaN, Precision.round(Double.NaN, 2), 0.0); + Assertions.assertEquals(Double.NaN, Precision.round(Double.NaN, 2), 0.0); Assertions.assertEquals(0.0, Precision.round(0.0, 2), 0.0); Assertions.assertEquals(Double.POSITIVE_INFINITY, Precision.round(Double.POSITIVE_INFINITY, 2), 0.0); Assertions.assertEquals(Double.NEGATIVE_INFINITY, Precision.round(Double.NEGATIVE_INFINITY, 2), 0.0); diff --git a/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/TestUtils.java b/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/TestUtils.java index bf9c333..b343f36 100644 --- a/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/TestUtils.java +++ b/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/TestUtils.java @@ -38,43 +38,6 @@ 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 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. * @@ -181,64 +144,6 @@ public class TestUtils { assertContains(null, values, x, epsilon); } - /** 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()); - } - } - /** * Updates observed counts of values in quartiles. * counts[0] <-> 1st quartile ... counts[3] <-> top quartile @@ -284,34 +189,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); - } - - }
