예제 #1
0
 @Test
 public void testNextBinomial() {
   BinomialDistributionTest testInstance = new BinomialDistributionTest();
   int[] densityPoints = testInstance.makeDensityTestPoints();
   double[] densityValues = testInstance.makeDensityTestValues();
   int sampleSize = 1000;
   int length = TestUtils.eliminateZeroMassPoints(densityPoints, densityValues);
   BinomialDistribution distribution = (BinomialDistribution) testInstance.makeDistribution();
   double[] expectedCounts = new double[length];
   long[] observedCounts = new long[length];
   for (int i = 0; i < length; i++) {
     expectedCounts[i] = sampleSize * densityValues[i];
   }
   randomData.reSeed(1000);
   for (int i = 0; i < sampleSize; i++) {
     int value =
         randomData.nextBinomial(
             distribution.getNumberOfTrials(), distribution.getProbabilityOfSuccess());
     for (int j = 0; j < length; j++) {
       if (value == densityPoints[j]) {
         observedCounts[j]++;
       }
     }
   }
   TestUtils.assertChiSquareAccept(densityPoints, expectedCounts, observedCounts, .001);
 }