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 c947e72f30028e3094445bd3072cfb9684c54811
Author: Alex Herbert <aherb...@apache.org>
AuthorDate: Sun Mar 3 16:29:07 2019 +0000

    GeometricSamplerTest: Test to show probability of success < 1 is valid.
---
 .../sampling/distribution/GeometricSamplerTest.java   | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git 
a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/GeometricSamplerTest.java
 
b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/GeometricSamplerTest.java
index a1d424c..b3bab01 100644
--- 
a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/GeometricSamplerTest.java
+++ 
b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/GeometricSamplerTest.java
@@ -40,6 +40,25 @@ public class GeometricSamplerTest {
     }
 
     /**
+     * Test to demonstrate that any probability of success under one produces 
a valid
+     * mean for the exponential distribution.
+     */
+    @Test
+    public void testProbabilityOfSuccessUnderOneIsValid() {
+        // The sampler explicitly handles probabilityOfSuccess == 1 as an edge 
case.
+        // Anything under it should be valid for sampling from an 
ExponentialDistribution.
+        final double probabilityOfSuccess = Math.nextAfter(1, -1);
+        // Map to the mean
+        final double exponentialMean = 1.0 / 
(-Math.log1p(-probabilityOfSuccess));
+        // As long as this is finite positive then the sampler is valid
+        Assert.assertTrue(exponentialMean > 0 && exponentialMean <= 
Double.MAX_VALUE);
+        // The internal exponential sampler validates the mean so demonstrate 
creating a
+        // geometric sampler does not throw.
+        final UniformRandomProvider rng = 
RandomSource.create(RandomSource.SPLIT_MIX_64);
+        new GeometricSampler(rng, probabilityOfSuccess);
+    }
+
+    /**
      * Test the edge case where the probability of success is 1 since it uses 
a different
      * {@link Object#toString()} method to the normal case tested elsewhere.
      */

Reply via email to