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 2018/04/23 10:50:39 UTC
commons-numbers git commit: NUMBERS-65: Test added to nthRoot that
proceeds around the unit circle in both directions using pos and neg args.
Repository: commons-numbers
Updated Branches:
refs/heads/master d3d9c455e -> a57399c7a
NUMBERS-65: Test added to nthRoot that proceeds around the unit circle
in both directions using pos and neg args.
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/a57399c7
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/a57399c7
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/a57399c7
Branch: refs/heads/master
Commit: a57399c7ae6e2e1c6919e34014f602a1eeccfd87
Parents: d3d9c45
Author: Eric Barnhill <er...@apache.org>
Authored: Mon Apr 23 12:53:39 2018 +0200
Committer: Eric Barnhill <er...@apache.org>
Committed: Mon Apr 23 12:53:39 2018 +0200
----------------------------------------------------------------------
.../commons/numbers/complex/ComplexTest.java | 48 ++++++++++++++++++++
1 file changed, 48 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a57399c7/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexTest.java
----------------------------------------------------------------------
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 4a6fd7d..36fcde8 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
@@ -734,6 +734,54 @@ public class ComplexTest {
}
/**
+ * Test: compute <b>third roots</b> using a negative argument
+ * to go clockwise around the unit circle. Fourth roots of one
+ * are taken in both directions around the circle using
+ * positive and negative arguments:
+ * <pre>
+ * <code>
+ * <b>z = 1</b>
+ * => z_0 = Positive: 1,0 ; Negative: 1,0
+ * => z_1 = Positive: 0,1 ; Negative: 0,-1
+ * => z_2 = Positive: -1,0 ; Negative: -1,0
+ * => z_3 = Positive: 0,-1 ; Negative: 0,1
+ * </code>
+ * </pre>
+ */
+ @Test
+ public void testNthRootNegativeArg() {
+ // The complex number we want to compute all third-roots for.
+ Complex z = Complex.ofCartesian(1, 0);
+ // The List holding all fourth roots
+ Complex[] fourthRootsOfZ = z.nthRoot(4).toArray(new Complex[0]);
+ // test z_0
+ Assert.assertEquals(1, fourthRootsOfZ[0].getReal(), 1.0e-5);
+ Assert.assertEquals(0, fourthRootsOfZ[0].getImaginary(), 1.0e-5);
+// test z_1
+ Assert.assertEquals(0, fourthRootsOfZ[1].getReal(), 1.0e-5);
+ Assert.assertEquals(1, fourthRootsOfZ[1].getImaginary(), 1.0e-5);
+ // test z_2
+ Assert.assertEquals(-1, fourthRootsOfZ[2].getReal(), 1.0e-5);
+ Assert.assertEquals(0, fourthRootsOfZ[2].getImaginary(), 1.0e-5);
+ // test z_3
+ Assert.assertEquals(0, fourthRootsOfZ[3].getReal(), 1.0e-5);
+ Assert.assertEquals(-1, fourthRootsOfZ[3].getImaginary(), 1.0e-5);
+ // go clockwise around the unit circle using negative argument
+ fourthRootsOfZ = z.nthRoot(-4).toArray(new Complex[0]);
+ // test z_0
+ Assert.assertEquals(1, fourthRootsOfZ[0].getReal(), 1.0e-5);
+ Assert.assertEquals(0, fourthRootsOfZ[0].getImaginary(), 1.0e-5);
+// test z_1
+ Assert.assertEquals(0, fourthRootsOfZ[1].getReal(), 1.0e-5);
+ Assert.assertEquals(-1, fourthRootsOfZ[1].getImaginary(), 1.0e-5);
+ // test z_2
+ Assert.assertEquals(-1, fourthRootsOfZ[2].getReal(), 1.0e-5);
+ Assert.assertEquals(0, fourthRootsOfZ[2].getImaginary(), 1.0e-5);
+ // test z_3
+ Assert.assertEquals(0, fourthRootsOfZ[3].getReal(), 1.0e-5);
+ Assert.assertEquals(1, fourthRootsOfZ[3].getImaginary(), 1.0e-5);
+ }
+ /**
* Test standard values
*/
@Test