### Question:
BetaDistribution extends AbstractContinuousDistribution { @Override public double logDensity(double x) { if (x < 0 || x > 1) { return Double.NEGATIVE_INFINITY; } else if (x == 0) { if (alpha < 1) { throw new DistributionException(DistributionException.TOO_SMALL, alpha, 1.0); } return Double.NEGATIVE_INFINITY; } else if (x == 1) { if (beta < 1) { throw new DistributionException(DistributionException.TOO_SMALL, beta, 1.0); } return Double.NEGATIVE_INFINITY; } else { final double logX = Math.log(x); final double log1mX = Math.log1p(-x); return (alpha - 1) * logX + (beta - 1) * log1mX - z; } } BetaDistribution(double alpha,
                            double beta); double getAlpha(); double getBeta(); @Override double density(double x); @Override double logDensity(double x); @Override double cumulativeProbability(double x); @Override double getMean(); @Override double getVariance(); @Override double getSupportLowerBound(); @Override double getSupportUpperBound(); @Override boolean isSupportConnected(); @Override ContinuousDistribution.Sampler createSampler(final UniformRandomProvider rng);  }### Answer:
@Test void testLogDensityPrecondition1() { final BetaDistribution d = new BetaDistribution(0.5, 3); Assertions.assertThrows(DistributionException.class, () -> d.logDensity(0.0)); }
@Test void testLogDensityPrecondition2() { final BetaDistribution d = new BetaDistribution(2, 0.5); Assertions.assertThrows(DistributionException.class, () -> d.logDensity(1.0)); }