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/22 22:06:56 UTC

[commons-rng] branch master updated: Test the SmallMeanPoissonSampler sample is bounded to 1000 * mean

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 6172bb5  Test the SmallMeanPoissonSampler sample is bounded to 1000 * mean
6172bb5 is described below

commit 6172bb59deaf1bd44748f6551d61f8754e739cb4
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Fri Feb 22 22:06:46 2019 +0000

    Test the SmallMeanPoissonSampler sample is bounded to 1000 * mean
---
 .../distribution/SmallMeanPoissonSamplerTest.java  | 31 +++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)

diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/SmallMeanPoissonSamplerTest.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/SmallMeanPoissonSamplerTest.java
index 0d8d5c7..821645b 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/SmallMeanPoissonSamplerTest.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/SmallMeanPoissonSamplerTest.java
@@ -16,8 +16,9 @@
  */
 package org.apache.commons.rng.sampling.distribution;
 
-import org.apache.commons.rng.RestorableUniformRandomProvider;
+import org.apache.commons.rng.UniformRandomProvider;
 import org.apache.commons.rng.simple.RandomSource;
+import org.junit.Assert;
 import org.junit.Test;
 
 /**
@@ -33,7 +34,7 @@ public class SmallMeanPoissonSamplerTest {
      */
     @Test(expected=IllegalArgumentException.class)
     public void testConstructorThrowsWithMeanLargerThanUpperBound() {
-        final RestorableUniformRandomProvider rng =
+        final UniformRandomProvider rng =
             RandomSource.create(RandomSource.SPLIT_MIX_64);
         @SuppressWarnings("unused")
         SmallMeanPoissonSampler sampler = new SmallMeanPoissonSampler(rng, Integer.MAX_VALUE / 2 + 1);
@@ -44,9 +45,33 @@ public class SmallMeanPoissonSamplerTest {
      */
     @Test(expected=IllegalArgumentException.class)
     public void testConstructorThrowsWithZeroMean() {
-        final RestorableUniformRandomProvider rng =
+        final UniformRandomProvider rng =
             RandomSource.create(RandomSource.SPLIT_MIX_64);
         @SuppressWarnings("unused")
         SmallMeanPoissonSampler sampler = new SmallMeanPoissonSampler(rng, 0);
     }
+
+    /**
+     * Test the sample is bounded to 1000 * mean.
+     */
+    @Test
+    public void testSampleUpperBounds() {
+        // If the nextDouble() is always 1 then the sample will hit the upper bounds
+        final UniformRandomProvider rng = new UniformRandomProvider() {
+            public long nextLong(long n) { return 0; }
+            public long nextLong() { return 0; }
+            public int nextInt(int n) { return 0; }
+            public int nextInt() { return 0; }
+            public float nextFloat() { return 0; }
+            public double nextDouble() { return 1;}
+            public void nextBytes(byte[] bytes, int start, int len) {}
+            public void nextBytes(byte[] bytes) {}
+            public boolean nextBoolean() { return false; }
+        };
+        for (double mean : new double[] { 0.5, 1, 1.5, 2.2 }) {
+            final SmallMeanPoissonSampler sampler = new SmallMeanPoissonSampler(rng, mean);
+            final int expected = (int) Math.ceil(1000 * mean);
+            Assert.assertEquals(expected, sampler.sample());
+        }
+    }
 }