Added tests for special values, quantile range checking.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/math/trunk@141325 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
78ec9dc5b5
commit
a2e44f7732
|
@ -23,7 +23,7 @@ import org.apache.commons.math.stat.univariate.UnivariateStatisticAbstractTest;
|
|||
|
||||
/**
|
||||
* Test cases for the {@link UnivariateStatistic} class.
|
||||
* @version $Revision: 1.13 $ $Date: 2004/06/17 21:37:05 $
|
||||
* @version $Revision: 1.14 $ $Date: 2004/06/19 21:16:12 $
|
||||
*/
|
||||
public class PercentileTest extends UnivariateStatisticAbstractTest{
|
||||
|
||||
|
@ -80,10 +80,72 @@ public class PercentileTest extends UnivariateStatisticAbstractTest{
|
|||
};
|
||||
Percentile p = new Percentile(90);
|
||||
assertEquals(95.1981, p.evaluate(d), 1.0e-4);
|
||||
assertEquals(95.1990, p.evaluate(d,0,d.length, 100d), 0);
|
||||
}
|
||||
|
||||
public void test5() {
|
||||
Percentile percentile = new Percentile(5);
|
||||
assertEquals(this.percentile5, percentile.evaluate(testArray), getTolerance());
|
||||
}
|
||||
|
||||
public void testNullEmpty() {
|
||||
Percentile percentile = new Percentile(50);
|
||||
double[] nullArray = null;
|
||||
double[] emptyArray = new double[] {};
|
||||
try {
|
||||
percentile.evaluate(nullArray);
|
||||
fail("Expecting IllegalArgumentException for null array");
|
||||
} catch (IllegalArgumentException ex) {
|
||||
// expected
|
||||
}
|
||||
assertTrue(Double.isNaN(percentile.evaluate(emptyArray)));
|
||||
}
|
||||
|
||||
public void testSingleton() {
|
||||
Percentile percentile = new Percentile(50);
|
||||
double[] singletonArray = new double[] {1d};
|
||||
assertEquals(1d, percentile.evaluate(singletonArray), 0);
|
||||
assertEquals(1d, percentile.evaluate(singletonArray, 0, 1), 0);
|
||||
assertEquals(1d, percentile.evaluate(singletonArray, 0, 1, 5), 0);
|
||||
assertEquals(1d, percentile.evaluate(singletonArray, 0, 1, 100), 0);
|
||||
assertTrue(Double.isNaN(percentile.evaluate(singletonArray, 0, 0)));
|
||||
}
|
||||
|
||||
public void testSpecialValues() {
|
||||
Percentile percentile = new Percentile(50);
|
||||
double[] specialValues = new double[] {0d, 1d, 2d, 3d, 4d, Double.NaN};
|
||||
assertEquals(2.5d, percentile.evaluate(specialValues), 0);
|
||||
specialValues = new double[] {Double.NEGATIVE_INFINITY, 1d, 2d, 3d,
|
||||
Double.NaN, Double.POSITIVE_INFINITY};
|
||||
assertEquals(2.5d, percentile.evaluate(specialValues), 0);
|
||||
specialValues = new double[] {1d, 1d, Double.POSITIVE_INFINITY,
|
||||
Double.POSITIVE_INFINITY};
|
||||
assertTrue(Double.isInfinite(percentile.evaluate(specialValues)));
|
||||
specialValues = new double[] {1d, 1d, Double.NaN,
|
||||
Double.NaN};
|
||||
assertTrue(Double.isNaN(percentile.evaluate(specialValues)));
|
||||
specialValues = new double[] {1d, 1d, Double.NEGATIVE_INFINITY,
|
||||
Double.NEGATIVE_INFINITY};
|
||||
// Interpolation results in NEGATIVE_INFINITY + POSITIVE_INFINITY
|
||||
assertTrue(Double.isNaN(percentile.evaluate(specialValues)));
|
||||
}
|
||||
|
||||
public void testSetQuantile() {
|
||||
Percentile percentile = new Percentile(10);
|
||||
percentile.setQuantile(100); // OK
|
||||
assertEquals(100, percentile.getQuantile(), 0);
|
||||
try {
|
||||
percentile.setQuantile(0);
|
||||
fail("Expecting IllegalArgumentException");
|
||||
} catch (IllegalArgumentException ex) {
|
||||
// expected
|
||||
}
|
||||
try {
|
||||
percentile = new Percentile(0);
|
||||
fail("Expecting IllegalArgumentException");
|
||||
} catch (IllegalArgumentException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue