You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2016/04/20 02:05:23 UTC
[5/8] [math] Added additional methods to TestUtils that test the
accuracy of Complex[] arrays found in proposed changes to ComplexUtils
Added additional methods to TestUtils that test the accuracy of Complex[] arrays found in proposed changes to ComplexUtils
Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/d75ed5d0
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/d75ed5d0
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/d75ed5d0
Branch: refs/heads/feature-MATH-1290
Commit: d75ed5d0451fe4c96c6a15a4639f63e51857782f
Parents: 4f271dd
Author: Eric Barnhill <er...@protonmail.ch>
Authored: Tue Apr 19 21:39:44 2016 +0200
Committer: Eric Barnhill <er...@protonmail.ch>
Committed: Tue Apr 19 21:39:44 2016 +0200
----------------------------------------------------------------------
.../org/apache/commons/math4/TestUtils.java | 68 ++++++++++++++++++++
1 file changed, 68 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-math/blob/d75ed5d0/src/test/java/org/apache/commons/math4/TestUtils.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/TestUtils.java b/src/test/java/org/apache/commons/math4/TestUtils.java
index 109e64d..5dde4e4 100644
--- a/src/test/java/org/apache/commons/math4/TestUtils.java
+++ b/src/test/java/org/apache/commons/math4/TestUtils.java
@@ -364,6 +364,74 @@ public class TestUtils {
Assert.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);
+ Assert.fail(out.toString());
+ }
+ boolean failure = false;
+ for (int i=0; i < expected.length; i++) {
+ if (!Precision.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) {
+ Assert.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) {
+ 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);
+ Assert.fail(out.toString());
+ }
+ boolean failure = false;
+ for (int i=0; i < expected.length; i++) {
+ if (!Precision.equalsIncludingNaN(expected[i].getReal(), observed[i].getReal(), tolerance)) {
+ failure = true;
+ out.append("\n Real elements at index ");
+ out.append(i);
+ out.append(" differ. ");
+ out.append(" expected = ");
+ out.append(expected[i].getReal());
+ out.append(" observed = ");
+ out.append(observed[i].getReal());
+ }
+ if (!Precision.equalsIncludingNaN(expected[i].getImaginary(), observed[i].getImaginary(), tolerance)) {
+ failure = true;
+ out.append("\n Imaginary elements at index ");
+ out.append(i);
+ out.append(" differ. ");
+ out.append(" expected = ");
+ out.append(expected[i].getImaginary());
+ out.append(" observed = ");
+ out.append(observed[i].getImaginary());
+ }
+ }
+ if (failure) {
+ Assert.fail(out.toString());
+ }
+ }
/** verifies that two arrays are equal */
public static <T extends FieldElement<T>> void assertEquals(T[] m, T[] n) {