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 4348fb1bac241472174df8deefc50aea0e0f2331
Author: aherbert <[email protected]>
AuthorDate: Mon Apr 15 16:30:57 2019 +0100

    RNG-92: LargeMeanPoissonSampler requires mean >= 1.
---
 .../rng/sampling/distribution/LargeMeanPoissonSampler.java |  6 +++---
 .../sampling/distribution/LargeMeanPoissonSamplerTest.java | 14 +++++++-------
 src/changes/changes.xml                                    |  3 +++
 3 files changed, 13 insertions(+), 10 deletions(-)

diff --git 
a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/LargeMeanPoissonSampler.java
 
b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/LargeMeanPoissonSampler.java
index 2d8cfd9..a02c131 100644
--- 
a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/LargeMeanPoissonSampler.java
+++ 
b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/LargeMeanPoissonSampler.java
@@ -105,13 +105,13 @@ public class LargeMeanPoissonSampler
     /**
      * @param rng Generator of uniformly distributed random numbers.
      * @param mean Mean.
-     * @throws IllegalArgumentException if {@code mean <= 0} or
+     * @throws IllegalArgumentException if {@code mean < 1} or
      * {@code mean > 0.5 *} {@link Integer#MAX_VALUE}.
      */
     public LargeMeanPoissonSampler(UniformRandomProvider rng,
                                    double mean) {
-        if (mean <= 0) {
-            throw new IllegalArgumentException("mean is not strictly positive: 
" + mean);
+        if (mean < 1) {
+            throw new IllegalArgumentException("mean is not >= 1: " + mean);
         }
         // The algorithm is not valid if Math.floor(mean) is not an integer.
         if (mean > MAX_MEAN) {
diff --git 
a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/LargeMeanPoissonSamplerTest.java
 
b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/LargeMeanPoissonSamplerTest.java
index 7e36082..b7b2271 100644
--- 
a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/LargeMeanPoissonSamplerTest.java
+++ 
b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/LargeMeanPoissonSamplerTest.java
@@ -44,22 +44,22 @@ public class LargeMeanPoissonSamplerTest {
     }
 
     /**
-     * Test the constructor with a bad mean.
+     * Test the constructor with a mean below 1.
      */
     @Test(expected=IllegalArgumentException.class)
-    public void testConstructorThrowsWithZeroMean() {
+    public void testConstructorThrowsWithMeanBelow1() {
         final RestorableUniformRandomProvider rng =
                 RandomSource.create(RandomSource.SPLIT_MIX_64);
-        final double mean = 0;
+        final double mean = Math.nextDown(1);
         @SuppressWarnings("unused")
         LargeMeanPoissonSampler sampler = new LargeMeanPoissonSampler(rng, 
mean);
     }
 
     /**
-     * Test the constructor with a negative fractional mean.
+     * Test the constructor using the state with a negative fractional mean.
      */
     @Test(expected=IllegalArgumentException.class)
-    public void testConstructorThrowsWithNegativeFractionalMean() {
+    public void testConstructorThrowsWithStateAndNegativeFractionalMean() {
         final RestorableUniformRandomProvider rng =
                 RandomSource.create(RandomSource.SPLIT_MIX_64);
         final LargeMeanPoissonSamplerState state = new 
LargeMeanPoissonSampler(rng, 1).getState();
@@ -71,7 +71,7 @@ public class LargeMeanPoissonSamplerTest {
      * Test the constructor with a non-fractional mean.
      */
     @Test(expected=IllegalArgumentException.class)
-    public void testConstructorThrowsWithNonFractionalMean() {
+    public void testConstructorThrowsWithStateAndNonFractionalMean() {
         final RestorableUniformRandomProvider rng =
                 RandomSource.create(RandomSource.SPLIT_MIX_64);
         final LargeMeanPoissonSamplerState state = new 
LargeMeanPoissonSampler(rng, 1).getState();
@@ -83,7 +83,7 @@ public class LargeMeanPoissonSamplerTest {
      * Test the constructor with fractional mean of 1.
      */
     @Test(expected=IllegalArgumentException.class)
-    public void testConstructorThrowsWithFractionalMeanOne() {
+    public void testConstructorThrowsWithStateAndFractionalMeanOne() {
         final RestorableUniformRandomProvider rng =
                 RandomSource.create(RandomSource.SPLIT_MIX_64);
         final LargeMeanPoissonSamplerState state = new 
LargeMeanPoissonSampler(rng, 1).getState();
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 96c0c5a..f286d59 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -75,6 +75,9 @@ re-run tests that fail, and pass the build if they succeed
 within the allotted number of reruns (the test will be marked
 as 'flaky' in the report).
 ">
+      <action dev="aherbert" type="fix" issue="RNG-92">
+        "LargeMeanPoissonSampler": Requires mean >= 1.
+      </action>
       <action dev="aherbert" type="add" issue="RNG-70">
         New "XorShiRo" family of generators. This adds 6 new general purpose 
generators with
         different periods and 4 related generators with improved performance 
for floating-point

Reply via email to