Author: luc
Date: Sun Mar 10 13:02:04 2013
New Revision: 1454846

URL: http://svn.apache.org/r1454846
Log:
Test new RandomDataGenerator class rather than deprecated RandomImpl.

Added:
    
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/random/RandomDataGeneratorTest.java
   (contents, props changed)
      - copied, changed from r1454840, 
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/random/RandomDataTest.java
Removed:
    
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/random/RandomDataTest.java
Modified:
    
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/random/RandomGeneratorAbstractTest.java

Copied: 
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/random/RandomDataGeneratorTest.java
 (from r1454840, 
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/random/RandomDataTest.java)
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/random/RandomDataGeneratorTest.java?p2=commons/proper/math/trunk/src/test/java/org/apache/commons/math3/random/RandomDataGeneratorTest.java&p1=commons/proper/math/trunk/src/test/java/org/apache/commons/math3/random/RandomDataTest.java&r1=1454840&r2=1454846&rev=1454846&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/random/RandomDataTest.java
 (original)
+++ 
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/random/RandomDataGeneratorTest.java
 Sun Mar 10 13:02:04 2013
@@ -51,16 +51,15 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 
 /**
- * Test cases for the RandomData class.
+ * Test cases for the RandomDataGenerator class.
  *
  * @version $Id$
- *          2009) $
  */
 @RunWith(RetryRunner.class)
-public class RandomDataTest {
+public class RandomDataGeneratorTest {
 
-    public RandomDataTest() {
-        randomData = new RandomDataImpl();
+    public RandomDataGeneratorTest() {
+        randomData = new RandomDataGenerator();
         randomData.reSeed(1000);
     }
 
@@ -69,7 +68,7 @@ public class RandomDataTest {
     protected final int largeSampleSize = 10000;
     private final String[] hex = { "0", "1", "2", "3", "4", "5", "6", "7", 
"8", "9",
             "a", "b", "c", "d", "e", "f" };
-    protected RandomDataImpl randomData = null;
+    protected RandomDataGenerator randomData = null;
     protected final ChiSquareTest testStatistic = new ChiSquareTest();
 
     @Test
@@ -828,16 +827,16 @@ public class RandomDataTest {
          */
 
         // test reseeding without first using the generators
-        RandomDataImpl rd = new RandomDataImpl();
+        RandomDataGenerator rd = new RandomDataGenerator();
         rd.reSeed(100);
         rd.nextLong(1, 2);
-        RandomDataImpl rd2 = new RandomDataImpl();
+        RandomDataGenerator rd2 = new RandomDataGenerator();
         rd2.reSeedSecure(2000);
         rd2.nextSecureLong(1, 2);
-        rd = new RandomDataImpl();
+        rd = new RandomDataGenerator();
         rd.reSeed();
         rd.nextLong(1, 2);
-        rd2 = new RandomDataImpl();
+        rd2 = new RandomDataGenerator();
         rd2.reSeedSecure();
         rd2.nextSecureLong(1, 2);
     }
@@ -992,21 +991,23 @@ public class RandomDataTest {
     @Test
     public void testNextInversionDeviate() {
         // Set the seed for the default random generator
-        randomData.reSeed(100);
+        RandomGenerator rg = new Well19937c(100);
+        RandomDataGenerator rdg = new RandomDataGenerator(rg);
         double[] quantiles = new double[10];
         for (int i = 0; i < 10; i++) {
-            quantiles[i] = randomData.nextUniform(0, 1);
+            quantiles[i] = rdg.nextUniform(0, 1);
         }
         // Reseed again so the inversion generator gets the same sequence
-        randomData.reSeed(100);
-        BetaDistribution betaDistribution = new BetaDistribution(2, 4);
+        rg.setSeed(100);
+        BetaDistribution betaDistribution = new BetaDistribution(rg, 2, 4,
+                                                                 
BetaDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
         /*
          *  Generate a sequence of deviates using inversion - the distribution 
function
          *  evaluated at the random value from the distribution should match 
the uniform
          *  random value used to generate it, which is stored in the 
quantiles[] array.
          */
         for (int i = 0; i < 10; i++) {
-            double value = randomData.nextInversionDeviate(betaDistribution);
+            double value = betaDistribution.sample();
             Assert.assertEquals(betaDistribution.cumulativeProbability(value), 
quantiles[i], 10E-9);
         }
     }

Propchange: 
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/random/RandomDataGeneratorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/random/RandomDataGeneratorTest.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: 
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/random/RandomGeneratorAbstractTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/random/RandomGeneratorAbstractTest.java?rev=1454846&r1=1454845&r2=1454846&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/random/RandomGeneratorAbstractTest.java
 (original)
+++ 
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/random/RandomGeneratorAbstractTest.java
 Sun Mar 10 13:02:04 2013
@@ -41,7 +41,7 @@ import org.junit.Test;
  * @version $Id$
  */
 
-public abstract class RandomGeneratorAbstractTest extends RandomDataTest {
+public abstract class RandomGeneratorAbstractTest extends 
RandomDataGeneratorTest {
 
     /** RandomGenerator under test */
     protected RandomGenerator generator;
@@ -57,7 +57,7 @@ public abstract class RandomGeneratorAbs
      */
     public RandomGeneratorAbstractTest() {
         generator = makeGenerator();
-        randomData = new RandomDataImpl(generator);
+        randomData = new RandomDataGenerator(generator);
     }
 
     /**
@@ -161,16 +161,19 @@ public abstract class RandomGeneratorAbs
         }
     }
 
-    @Override // TODO is this supposed to be an override?
-    @Test(expected=MathIllegalArgumentException.class)
-    public void testNextIntIAE() {
+    @Test
+    public void testNextIntIAE2() {
         try {
             generator.nextInt(-1);
             Assert.fail("MathIllegalArgumentException expected");
         } catch (MathIllegalArgumentException ex) {
             // ignored
         }
-        generator.nextInt(0);
+        try {
+            generator.nextInt(0);
+        } catch (MathIllegalArgumentException ex) {
+            // ignored
+        }
     }
 
     @Test


Reply via email to