You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ah...@apache.org on 2019/12/21 17:16:36 UTC
[commons-numbers] 03/03: Test abs() and arg() return the input to
ofPolar constructor.
This is an automated email from the ASF dual-hosted git repository.
aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-numbers.git
commit ceb62698d95a6b6a562a896c8ed8e82e72f1e411
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Sat Dec 21 17:16:29 2019 +0000
Test abs() and arg() return the input to ofPolar constructor.
---
.../org/apache/commons/numbers/complex/ComplexTest.java | 15 +++++++++++++++
1 file changed, 15 insertions(+)
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 7d6770d..82c2cee 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
@@ -123,6 +123,21 @@ public class ComplexTest {
}
@Test
+ public void testPolarConstructorAbsArg() {
+ // The test should work with any seed but use a fixed seed to avoid build instability.
+ final UniformRandomProvider rng = RandomSource.create(RandomSource.SPLIT_MIX_64, 678678638L);
+ for (int i = 0; i < 10; i++) {
+ final double rho = rng.nextDouble();
+ // Range (pi, pi]: lower exclusive, upper inclusive
+ final double theta = pi - rng.nextDouble() * 2 * pi;
+ final Complex z = Complex.ofPolar(rho, theta);
+ // Match within 1 ULP
+ Assertions.assertEquals(rho, z.abs(), Math.ulp(rho));
+ Assertions.assertEquals(theta, z.arg(), Math.ulp(theta));
+ }
+ }
+
+ @Test
public void testCisConstructor() {
final double x = 0.12345;
final Complex z = Complex.ofCis(x);