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/02/26 15:12:27 UTC

[commons-rng] branch master updated: Fix UnitSphereSampler test coverage.

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


The following commit(s) were added to refs/heads/master by this push:
     new 0cf148a  Fix UnitSphereSampler test coverage.
0cf148a is described below

commit 0cf148a8e692eee719d8250bfe17a2de3afe4788
Author: aherbert <ah...@apache.org>
AuthorDate: Tue Feb 26 15:12:01 2019 +0000

    Fix UnitSphereSampler test coverage.
---
 .../commons/rng/sampling/UnitSphereSamplerTest.java      | 16 ++++++++++++++++
 1 file changed, 16 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 fb4ac08..5d32105 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
@@ -20,6 +20,7 @@ import org.junit.Assert;
 import org.junit.Test;
 import org.apache.commons.rng.simple.RandomSource;
 import org.apache.commons.rng.UniformRandomProvider;
+import org.apache.commons.rng.core.source64.SplitMix64;
 
 /**
  * Test for {@link UnitSphereSampler}.
@@ -79,6 +80,21 @@ public class UnitSphereSamplerTest {
         new UnitSphereSampler(1, bad).nextVector();
     }
 
+    /** Cf. RNG-55. */
+    @Test
+    public void testBadProvider1ThenGoodProvider() {
+        // Create a provider that will create a bad first sample but then recover.
+        // This checks recursion will return a good value.
+        final UniformRandomProvider bad = new SplitMix64(0L) {
+                int count;
+                public long nextLong() { return (count++ == 0) ? 0 : super.nextLong(); }
+                public double nextDouble() { return (count++ == 0) ? 0 : super.nextDouble(); }
+            };
+
+        final double[] vector = new UnitSphereSampler(1, bad).nextVector();
+        Assert.assertEquals(1, vector.length);
+    }
+
     /**
      * @return the length (L2-norm) of given vector.
      */