You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ps...@apache.org on 2004/06/19 23:16:12 UTC
cvs commit: jakarta-commons/math/src/test/org/apache/commons/math/stat/univariate/rank PercentileTest.java
psteitz 2004/06/19 14:16:12
Modified: math/src/test/org/apache/commons/math/stat/univariate/rank
PercentileTest.java
Log:
Added tests for special values, quantile range checking.
Revision Changes Path
1.14 +63 -1 jakarta-commons/math/src/test/org/apache/commons/math/stat/univariate/rank/PercentileTest.java
Index: PercentileTest.java
===================================================================
RCS file: /home/cvs/jakarta-commons/math/src/test/org/apache/commons/math/stat/univariate/rank/PercentileTest.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- PercentileTest.java 17 Jun 2004 21:37:05 -0000 1.13
+++ PercentileTest.java 19 Jun 2004 21:16:12 -0000 1.14
@@ -80,10 +80,72 @@
};
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
+ }
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org