1 16 package org.apache.commons.math.distribution; 17 18 25 public class ExponentialDistributionTest extends ContinuousDistributionAbstractTest { 26 27 31 public ExponentialDistributionTest(String name) { 32 super(name); 33 } 34 35 37 38 public ContinuousDistribution makeDistribution() { 39 return DistributionFactory.newInstance().createExponentialDistribution(5.0); 40 } 41 42 43 public double[] makeCumulativeTestPoints() { 44 return new double[] {0.005002502d, 0.05025168d, 0.1265890d, 0.2564665d, 0.5268026d, 46 34.53878d, 23.02585d, 18.44440d, 14.97866d, 11.51293d}; 47 } 48 49 50 public double[] makeCumulativeTestValues() { 51 return new double[] {0.001d, 0.01d, 0.025d, 0.05d, 0.1d, 0.999d, 52 0.990d, 0.975d, 0.950d, 0.900d}; 53 } 54 55 57 public void testCumulativeProbabilityExtremes() throws Exception { 58 setCumulativeTestPoints(new double[] {-2, 0}); 59 setCumulativeTestValues(new double[] {0, 0}); 60 verifyCumulativeProbabilities(); 61 } 62 63 public void testInverseCumulativeProbabilityExtremes() throws Exception { 64 setInverseCumulativeTestPoints(new double[] {0, 1}); 65 setInverseCumulativeTestValues(new double[] {0, Double.POSITIVE_INFINITY}); 66 verifyInverseCumulativeProbabilities(); 67 } 68 69 public void testCumulativeProbability2() throws Exception { 70 double actual = getDistribution().cumulativeProbability(0.25, 0.75); 71 assertEquals(0.0905214, actual, 10e-4); 72 } 73 74 public void testMeanAccessors() { 75 ExponentialDistribution distribution = (ExponentialDistribution) getDistribution(); 76 assertEquals(5d, distribution.getMean(), Double.MIN_VALUE); 77 distribution.setMean(2d); 78 assertEquals(2d, distribution.getMean(), Double.MIN_VALUE); 79 try { 80 distribution.setMean(0); 81 fail("Expecting IllegalArgumentException for 0 mean"); 82 } catch (IllegalArgumentException ex) { 83 } 85 } 86 87 } 88 | Popular Tags |