1 16 17 package org.apache.commons.math.distribution; 18 19 26 public class HypergeometricDistributionTest extends IntegerDistributionAbstractTest { 27 28 32 public HypergeometricDistributionTest(String name) { 33 super(name); 34 } 35 36 38 39 public IntegerDistribution makeDistribution() { 40 return DistributionFactory.newInstance().createHypergeometricDistribution(10,5, 5); 41 } 42 43 44 public int[] makeDensityTestPoints() { 45 return new int[] {-1, 0, 1, 2, 3, 4, 5, 10}; 46 } 47 48 49 public double[] makeDensityTestValues() { 50 return new double[] {0d, 0.003968d, 0.099206d, 0.396825d, 0.396825d, 51 0.099206d, 0.003968d, 0d}; 52 } 53 54 55 public int[] makeCumulativeTestPoints() { 56 return makeDensityTestPoints(); 57 } 58 59 60 public double[] makeCumulativeTestValues() { 61 return new double[] {0d, .003968d, .103175d, .50000d, .896825d, .996032d, 62 1.00000d, 1d}; 63 } 64 65 66 public double[] makeInverseCumulativeTestPoints() { 67 return new double[] {0d, 0.001d, 0.010d, 0.025d, 0.050d, 0.100d, 0.999d, 68 0.990d, 0.975d, 0.950d, 0.900d, 1d}; 69 } 70 71 72 public int[] makeInverseCumulativeTestValues() { 73 return new int[] {-1, -1, 0, 0, 0, 0, 4, 3, 3, 3, 3, 5}; 74 } 75 76 78 79 public void testDegenerateNoFailures() throws Exception { 80 setDistribution(DistributionFactory.newInstance().createHypergeometricDistribution(5,5,3)); 81 setCumulativeTestPoints(new int[] {-1, 0, 1, 3, 10 }); 82 setCumulativeTestValues(new double[] {0d, 0d, 0d, 1d, 1d}); 83 setDensityTestPoints(new int[] {-1, 0, 1, 3, 10}); 84 setDensityTestValues(new double[] {0d, 0d, 0d, 1d, 0d}); 85 setInverseCumulativeTestPoints(new double[] {0.1d, 0.5d}); 86 setInverseCumulativeTestValues(new int[] {2, 2}); 87 verifyDensities(); 88 verifyCumulativeProbabilities(); 89 verifyInverseCumulativeProbabilities(); 90 } 91 92 93 public void testDegenerateNoSuccesses() throws Exception { 94 setDistribution(DistributionFactory.newInstance().createHypergeometricDistribution(5,0,3)); 95 setCumulativeTestPoints(new int[] {-1, 0, 1, 3, 10 }); 96 setCumulativeTestValues(new double[] {0d, 1d, 1d, 1d, 1d}); 97 setDensityTestPoints(new int[] {-1, 0, 1, 3, 10}); 98 setDensityTestValues(new double[] {0d, 1d, 0d, 0d, 0d}); 99 setInverseCumulativeTestPoints(new double[] {0.1d, 0.5d}); 100 setInverseCumulativeTestValues(new int[] {-1, -1}); 101 verifyDensities(); 102 verifyCumulativeProbabilities(); 103 verifyInverseCumulativeProbabilities(); 104 } 105 106 107 public void testDegenerateFullSample() throws Exception { 108 setDistribution(DistributionFactory.newInstance().createHypergeometricDistribution(5,3,5)); 109 setCumulativeTestPoints(new int[] {-1, 0, 1, 3, 10 }); 110 setCumulativeTestValues(new double[] {0d, 0d, 0d, 1d, 1d}); 111 setDensityTestPoints(new int[] {-1, 0, 1, 3, 10}); 112 setDensityTestValues(new double[] {0d, 0d, 0d, 1d, 0d}); 113 setInverseCumulativeTestPoints(new double[] {0.1d, 0.5d}); 114 setInverseCumulativeTestValues(new int[] {2, 2}); 115 verifyDensities(); 116 verifyCumulativeProbabilities(); 117 verifyInverseCumulativeProbabilities(); 118 } 119 120 public void testPopulationSize() { 121 HypergeometricDistribution dist = DistributionFactory.newInstance().createHypergeometricDistribution(5,3,5); 122 try { 123 dist.setPopulationSize(-1); 124 fail("negative population size. IllegalArgumentException expected"); 125 } catch(IllegalArgumentException ex) { 126 } 127 128 dist.setPopulationSize(10); 129 assertEquals(10, dist.getPopulationSize()); 130 } 131 } 132 | Popular Tags |