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/03/03 16:29:10 UTC
[commons-rng] 01/02: UnitSphereSamplerTest: Test to show any normSq
value after 0 is valid.
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-rng.git
commit 52858ebe5277184a46c2d7fecfe55ea907d3c2ea
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Sun Mar 3 16:22:20 2019 +0000
UnitSphereSamplerTest: Test to show any normSq value after 0 is valid.
---
.../commons/rng/sampling/UnitSphereSamplerTest.java | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/UnitSphereSamplerTest.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/UnitSphereSamplerTest.java
index 5d32105..0d64d26 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/UnitSphereSamplerTest.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/UnitSphereSamplerTest.java
@@ -96,6 +96,21 @@ public class UnitSphereSamplerTest {
}
/**
+ * Test to demonstrate that using floating-point equality of the norm squared with
+ * zero is valid. Any norm squared after zero should produce a valid scaling factor.
+ */
+ @Test
+ public void testNextNormSquaredAfterZeroIsValid() {
+ // The sampler explicitly handles length == 0 using recursion.
+ // Anything above zero should be valid.
+ final double normSq = Math.nextAfter(0, 1);
+ // Map to the scaling factor
+ final double f = 1 / Math.sqrt(normSq);
+ // As long as this is finite positive then the sampler is valid
+ Assert.assertTrue(f > 0 && f <= Double.MAX_VALUE);
+ }
+
+ /**
* @return the length (L2-norm) of given vector.
*/
private static double length(double[] vector) {