EnumeratedRealDistribution extends AbstractRealDistribution { @Override public double sample() { return innerDistribution.sample(); } EnumeratedRealDistribution(final double[] singletons, final double[] probabilities);  EnumeratedRealDistribution(final RandomGenerator rng,
                                    final double[] singletons, final double[] probabilities); @Override double probability(final double x); double density(final double x); double cumulativeProbability(final double x); @Override double inverseCumulativeProbability(final double p); double getNumericalMean(); double getNumericalVariance(); double getSupportLowerBound(); double getSupportUpperBound(); boolean isSupportLowerBoundInclusive(); boolean isSupportUpperBoundInclusive(); boolean isSupportConnected(); @Override double sample();  }
@Test public void testSample() { final int n = 1000000; testDistribution.reseedRandomGenerator(-334759360); final double[] samples = testDistribution.sample(n); Assert.assertEquals(n, samples.length); double sum = 0; double sumOfSquares = 0; for (int i = 0; i < samples.length; i++) { sum += samples[i]; sumOfSquares += samples[i] * samples[i]; } Assert.assertEquals(testDistribution.getNumericalMean(), sum / n, 1e-2); Assert.assertEquals(testDistribution.getNumericalVariance(), sumOfSquares / n - FastMath.pow(sum / n, 2), 1e-2); }
@Test public void testIssue942() { List<Pair<Object,Double>> list = new ArrayList<Pair<Object, Double>>(); list.add(new Pair<Object, Double>(new Object() {}, new Double(0))); list.add(new Pair<Object, Double>(new Object() {}, new Double(1))); Assert.assertEquals(1, new EnumeratedDistribution<Object>(list).sample(1).length); }