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:25 UTC

[7/8] [math] Changes proposed in JIRA feature-MATH-1290: Addition of array-based extraction and conversion methods to and from Complex[] arrays; patching of a method name in LaguerreSolver now that it has been changed in ComplexUtils; creation of some me

Changes proposed in JIRA feature-MATH-1290: Addition of array-based extraction and conversion methods to and from Complex[] arrays; patching of a method name in LaguerreSolver now that it has been changed in ComplexUtils; creation of some methods in TestUtils that evaluate Complex[] arrays; and creation of JUnit tests for the new methods proposed in 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/ea4c2fdc
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/ea4c2fdc
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/ea4c2fdc

Branch: refs/heads/feature-MATH-1290
Commit: ea4c2fdc9396bd88263e8444ad7e457a4d23ce41
Parents: 02e4f6b 1d3fd2b
Author: Eric Barnhill <er...@protonmail.ch>
Authored: Tue Apr 19 21:56:11 2016 +0200
Committer: Eric Barnhill <er...@protonmail.ch>
Committed: Tue Apr 19 21:56:11 2016 +0200

----------------------------------------------------------------------
 .../commons/math4/complex/ComplexUtils.java     | 872 +++++++------------
 .../org/apache/commons/math4/TestUtils.java     |  68 ++
 .../commons/math4/complex/ComplexUtilsTest.java | 178 ++--
 3 files changed, 471 insertions(+), 647 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/ea4c2fdc/src/test/java/org/apache/commons/math4/TestUtils.java
----------------------------------------------------------------------
diff --cc src/test/java/org/apache/commons/math4/TestUtils.java
index 68a0138,5dde4e4..c75aaea
--- a/src/test/java/org/apache/commons/math4/TestUtils.java
+++ b/src/test/java/org/apache/commons/math4/TestUtils.java
@@@ -364,55 -364,55 +364,123 @@@ 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 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());