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/06 18:29:08 UTC
[commons-numbers] 14/19: Add a test for square()
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 89c907fb4e25d5851303863ea0b6b05cd4555920
Author: aherbert <ah...@apache.org>
AuthorDate: Fri Dec 6 16:16:43 2019 +0000
Add a test for square()
---
.../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 fdd0b68..8efd26d 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
@@ -1301,4 +1301,19 @@ public class ComplexTest {
Assertions.assertEquals(0.54930614433405489, c.getReal());
Assertions.assertEquals(1.5707963267948966, c.getImaginary());
}
+
+ @Test
+ public void testSquare() {
+ final UniformRandomProvider rng = RandomSource.create(RandomSource.SPLIT_MIX_64);
+ final double min = -5;
+ final double range = -2 * min;
+ for (int i = 0; i < 10; i++) {
+ final Complex z = Complex.ofCartesian(min + range * rng.nextDouble(),
+ min + range * rng.nextDouble());
+ final Complex c1 = z.multiply(z);
+ final Complex c2 = z.square();
+ Assertions.assertEquals(c1.getReal(), c2.getReal(), "real");
+ Assertions.assertEquals(c1.getImaginary(), c2.getImaginary(), "imaginary");
+ }
+ }
}