You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ah...@apache.org on 2020/06/23 17:00:54 UTC
[commons-statistics] 27/35: Increase AbstractDiscreteDistribution
test coverage.
This is an automated email from the ASF dual-hosted git repository.
aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-statistics.git
commit c170b7ac4f52d2a647154ae6a4162a70d198e7f5
Author: aherbert <ah...@apache.org>
AuthorDate: Tue Jun 23 16:59:38 2020 +0100
Increase AbstractDiscreteDistribution test coverage.
---
.../AbstractDiscreteDistributionTest.java | 74 ++++++++++++++++++++++
1 file changed, 74 insertions(+)
diff --git a/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/AbstractDiscreteDistributionTest.java b/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/AbstractDiscreteDistributionTest.java
index cbb42ab..3166dac 100644
--- a/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/AbstractDiscreteDistributionTest.java
+++ b/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/AbstractDiscreteDistributionTest.java
@@ -73,6 +73,80 @@ public class AbstractDiscreteDistributionTest {
}
}
+ @Test
+ public void testInverseCumulativeProbabilityExtremes() {
+ // Require a lower bound of MIN_VALUE and the cumulative probability
+ // at that bound to be lower/higher than the argument cumulative probability.
+ final DiscreteDistribution dist = new AbstractDiscreteDistribution() {
+ @Override
+ public double probability(int x) {
+ return 0;
+ }
+ @Override
+ public double cumulativeProbability(int x) {
+ return x == Integer.MIN_VALUE ? 0.1 : 1.0;
+ }
+ @Override
+ public double getMean() {
+ return 0;
+ }
+ @Override
+ public double getVariance() {
+ return 0;
+ }
+ @Override
+ public int getSupportLowerBound() {
+ return Integer.MIN_VALUE;
+ }
+ @Override
+ public int getSupportUpperBound() {
+ return 42;
+ }
+ @Override
+ public boolean isSupportConnected() {
+ return false;
+ }
+ };
+ Assertions.assertEquals(Integer.MIN_VALUE, dist.inverseCumulativeProbability(0.05));
+ Assertions.assertEquals(dist.getSupportUpperBound(), dist.inverseCumulativeProbability(1.0));
+ }
+
+ @Test
+ public void testInverseCumulativeProbabilityWithNaN() {
+ final DiscreteDistribution dist = new AbstractDiscreteDistribution() {
+ @Override
+ public double probability(int x) {
+ return 0;
+ }
+ @Override
+ public double cumulativeProbability(int x) {
+ // NaN is not allowed
+ return Double.NaN;
+ }
+ @Override
+ public double getMean() {
+ return 0;
+ }
+ @Override
+ public double getVariance() {
+ return 0;
+ }
+ @Override
+ public int getSupportLowerBound() {
+ return Integer.MIN_VALUE;
+ }
+ @Override
+ public int getSupportUpperBound() {
+ return Integer.MAX_VALUE;
+ }
+ @Override
+ public boolean isSupportConnected() {
+ return false;
+ }
+ };
+ Assertions.assertThrows(IllegalStateException.class, () -> dist.inverseCumulativeProbability(0.5));
+ }
+
/**
* Simple distribution modeling a 6-sided die
*/