commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject [43/53] [math] MATH-1158.
Date Fri, 25 Mar 2016 15:19:28 GMT
MATH-1158.

Method "createSampler" overridden in "ConstantRealDistribution".


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/82f4ce51
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/82f4ce51
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/82f4ce51

Branch: refs/heads/feature-MATH-1158
Commit: 82f4ce516c18ef5fb3096f6a90455fce90a5b290
Parents: 1d5f8fa
Author: Gilles <erans@apache.org>
Authored: Sat Mar 12 02:31:13 2016 +0100
Committer: Gilles <erans@apache.org>
Committed: Sat Mar 12 02:31:13 2016 +0100

----------------------------------------------------------------------
 .../distribution/ConstantRealDistribution.java  | 20 ++++++++++++++++++++
 .../ConstantRealDistributionTest.java           |  5 +++--
 2 files changed, 23 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/82f4ce51/src/main/java/org/apache/commons/math4/distribution/ConstantRealDistribution.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/distribution/ConstantRealDistribution.java
b/src/main/java/org/apache/commons/math4/distribution/ConstantRealDistribution.java
index 35854a4..862fe75 100644
--- a/src/main/java/org/apache/commons/math4/distribution/ConstantRealDistribution.java
+++ b/src/main/java/org/apache/commons/math4/distribution/ConstantRealDistribution.java
@@ -18,6 +18,7 @@
 package org.apache.commons.math4.distribution;
 
 import org.apache.commons.math4.exception.OutOfRangeException;
+import org.apache.commons.math4.rng.UniformRandomProvider;
 
 /**
  * Implementation of the constant real distribution.
@@ -106,6 +107,7 @@ public class ConstantRealDistribution extends AbstractRealDistribution
{
 
     /** {@inheritDoc} */
     @Override
+    @Deprecated
     public double sample()  {
         return value;
     }
@@ -115,5 +117,23 @@ public class ConstantRealDistribution extends AbstractRealDistribution
{
      * @param seed (ignored)
      */
     @Override
+    @Deprecated
     public void reseedRandomGenerator(long seed) {}
+
+    /**
+     * {@inheritDoc}
+     *
+     * @param rng Not used: distribution contains a single value.
+     * @return the value of the distribution.
+     */
+    @Override
+    public RealDistribution.Sampler createSampler(final UniformRandomProvider rng) {
+        return new RealDistribution.Sampler() {
+            /** {@inheritDoc} */
+            @Override
+            public double sample() {
+                return value;
+            }
+        };
+    }
 }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/82f4ce51/src/test/java/org/apache/commons/math4/distribution/ConstantRealDistributionTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/distribution/ConstantRealDistributionTest.java
b/src/test/java/org/apache/commons/math4/distribution/ConstantRealDistributionTest.java
index 275d29a..211a670 100644
--- a/src/test/java/org/apache/commons/math4/distribution/ConstantRealDistributionTest.java
+++ b/src/test/java/org/apache/commons/math4/distribution/ConstantRealDistributionTest.java
@@ -94,9 +94,10 @@ public class ConstantRealDistributionTest extends RealDistributionAbstractTest
{
     @Test
     @Override
     public void testSampler() {
-        ConstantRealDistribution dist = new ConstantRealDistribution(0);
+        final double value = 12.345;
+        final RealDistribution.Sampler sampler = new ConstantRealDistribution(value).createSampler(null);
         for (int i = 0; i < 10; i++) {
-            Assert.assertEquals(0, dist.sample(), 0);
+            Assert.assertEquals(value, sampler.sample(), 0);
         }
     }
 }


Mime
View raw message