You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by br...@apache.org on 2005/08/20 06:26:35 UTC
svn commit: r233996 - in /jakarta/commons/proper/math/branches/MATH_1_1/src:
java/org/apache/commons/math/stat/ java/org/apache/commons/math/util/
test/org/apache/commons/math/linear/ test/org/apache/commons/math/stat/
test/org/apache/commons/math/stat...
Author: brentworden
Date: Fri Aug 19 21:26:27 2005
New Revision: 233996
URL: http://svn.apache.org/viewcvs?rev=233996&view=rev
Log:
added test cases to increase test coverage.
Modified:
jakarta/commons/proper/math/branches/MATH_1_1/src/java/org/apache/commons/math/stat/StatUtils.java
jakarta/commons/proper/math/branches/MATH_1_1/src/java/org/apache/commons/math/util/MathUtils.java
jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/linear/RealMatrixImplTest.java
jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/stat/FrequencyTest.java
jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/stat/StatUtilsTest.java
jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/stat/descriptive/rank/PercentileTest.java
Modified: jakarta/commons/proper/math/branches/MATH_1_1/src/java/org/apache/commons/math/stat/StatUtils.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/math/branches/MATH_1_1/src/java/org/apache/commons/math/stat/StatUtils.java?rev=233996&r1=233995&r2=233996&view=diff
==============================================================================
--- jakarta/commons/proper/math/branches/MATH_1_1/src/java/org/apache/commons/math/stat/StatUtils.java (original)
+++ jakarta/commons/proper/math/branches/MATH_1_1/src/java/org/apache/commons/math/stat/StatUtils.java Fri Aug 19 21:26:27 2005
@@ -604,8 +604,8 @@
double sum2 = 0d;
double diff = 0d;
int n = sample1.length;
- if (n < 2) {
- throw new IllegalArgumentException("Input array lengths must be at least 2.");
+ if (n < 2 || n != sample2.length) {
+ throw new IllegalArgumentException("Input array lengths must be equal and at least 2.");
}
for (int i = 0; i < n; i++) {
diff = sample1[i] - sample2[i];
Modified: jakarta/commons/proper/math/branches/MATH_1_1/src/java/org/apache/commons/math/util/MathUtils.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/math/branches/MATH_1_1/src/java/org/apache/commons/math/util/MathUtils.java?rev=233996&r1=233995&r2=233996&view=diff
==============================================================================
--- jakarta/commons/proper/math/branches/MATH_1_1/src/java/org/apache/commons/math/util/MathUtils.java (original)
+++ jakarta/commons/proper/math/branches/MATH_1_1/src/java/org/apache/commons/math/util/MathUtils.java Fri Aug 19 21:26:27 2005
@@ -1,12 +1,17 @@
/*
- * Copyright 2003-2005 The Apache Software Foundation. Licensed under the Apache
- * License, Version 2.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
- * or agreed to in writing, software distributed under the License is
- * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the specific language
- * governing permissions and limitations under the License.
+ * Copyright 2003-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package org.apache.commons.math.util;
@@ -15,9 +20,7 @@
/**
* Some useful additions to the built-in functions in {@link Math}.
- *
- * @version $Revision$ $Date: 2005-07-30 02:25:26 -0500 (Sat, 30 Jul
- * 2005) $
+ * @version $Revision$ $Date$
*/
public final class MathUtils {
Modified: jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/linear/RealMatrixImplTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/linear/RealMatrixImplTest.java?rev=233996&r1=233995&r2=233996&view=diff
==============================================================================
--- jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/linear/RealMatrixImplTest.java (original)
+++ jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/linear/RealMatrixImplTest.java Fri Aug 19 21:26:27 2005
@@ -422,6 +422,11 @@
RealMatrix lu = m.getLUMatrix();
assertClose("LU decomposition", lu, (RealMatrix) new RealMatrixImpl(testDataLU), normTolerance);
verifyDecomposition(m, lu);
+ // access LU decomposition on same object to verify caching.
+ lu = m.getLUMatrix();
+ assertClose("LU decomposition", lu, (RealMatrix) new RealMatrixImpl(testDataLU), normTolerance);
+ verifyDecomposition(m, lu);
+
m = new RealMatrixImpl(luData);
lu = m.getLUMatrix();
assertClose("LU decomposition", lu, (RealMatrix) new RealMatrixImpl(luDataLUDecomposition), normTolerance);
@@ -638,6 +643,19 @@
// dimension overflow
try {
m.setSubMatrix(testData,1,1);
+ fail("expecting MatrixIndexException");
+ } catch (MatrixIndexException e) {
+ // expected
+ }
+ // dimension underflow
+ try {
+ m.setSubMatrix(testData,-1,1);
+ fail("expecting MatrixIndexException");
+ } catch (MatrixIndexException e) {
+ // expected
+ }
+ try {
+ m.setSubMatrix(testData,1,-1);
fail("expecting MatrixIndexException");
} catch (MatrixIndexException e) {
// expected
Modified: jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/stat/FrequencyTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/stat/FrequencyTest.java?rev=233996&r1=233995&r2=233996&view=diff
==============================================================================
--- jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/stat/FrequencyTest.java (original)
+++ jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/stat/FrequencyTest.java Fri Aug 19 21:26:27 2005
@@ -20,6 +20,8 @@
import java.io.StringReader;
import java.util.Iterator;
+import org.apache.commons.math.TestUtils;
+
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
@@ -111,6 +113,21 @@
assertEquals("one count", 3 , f.getCount("one"));
assertEquals("Z cumulative pct -- case insensitive", 1 , f.getCumPct("Z"), tolerance);
assertEquals("z cumulative pct -- case insensitive", 1 , f.getCumPct("z"), tolerance);
+
+ f = null;
+ f = new Frequency();
+ assertEquals(0L, f.getCount('a'));
+ assertEquals(0L, f.getCumFreq('b'));
+ TestUtils.assertEquals(Double.NaN, f.getPct('a'), 0.0);
+ TestUtils.assertEquals(Double.NaN, f.getCumPct('b'), 0.0);
+ f.addValue('a');
+ f.addValue('b');
+ f.addValue('c');
+ f.addValue('d');
+ assertEquals(1L, f.getCount('a'));
+ assertEquals(2L, f.getCumFreq('b'));
+ assertEquals(0.25, f.getPct('a'), 0.0);
+ assertEquals(0.5, f.getCumPct('b'), 0.0);
}
/** test pcts */
Modified: jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/stat/StatUtilsTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/stat/StatUtilsTest.java?rev=233996&r1=233995&r2=233996&view=diff
==============================================================================
--- jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/stat/StatUtilsTest.java (original)
+++ jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/stat/StatUtilsTest.java Fri Aug 19 21:26:27 2005
@@ -371,6 +371,19 @@
} catch (IllegalArgumentException ex) {
// expected
}
+ try {
+ StatUtils.varianceDifference(sample1, small, meanDifference);
+ fail("Expecting IllegalArgumentException");
+ } catch (IllegalArgumentException ex) {
+ // expected
+ }
+ try {
+ double[] single = {1.0};
+ StatUtils.varianceDifference(single, single, meanDifference);
+ fail("Expecting IllegalArgumentException");
+ } catch (IllegalArgumentException ex) {
+ // expected
+ }
}
public void testGeometricMean() throws Exception {
@@ -384,5 +397,7 @@
test = new double[] {2, 4, 6, 8};
assertEquals(Math.exp(0.25d * StatUtils.sumLog(test)),
StatUtils.geometricMean(test), Double.MIN_VALUE);
+ assertEquals(Math.exp(0.5 * StatUtils.sumLog(test, 0, 2)),
+ StatUtils.geometricMean(test, 0, 2), Double.MIN_VALUE);
}
}
Modified: jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/stat/descriptive/rank/PercentileTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/stat/descriptive/rank/PercentileTest.java?rev=233996&r1=233995&r2=233996&view=diff
==============================================================================
--- jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/stat/descriptive/rank/PercentileTest.java (original)
+++ jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/stat/descriptive/rank/PercentileTest.java Fri Aug 19 21:26:27 2005
@@ -72,6 +72,20 @@
assertEquals(3.75, p.evaluate(d), 1.0e-5);
p.setQuantile(50);
assertEquals(2.5, p.evaluate(d), 1.0e-5);
+
+ // invalid percentiles
+ try {
+ p.evaluate(d, 0, d.length, -1.0);
+ fail();
+ } catch (IllegalArgumentException ex) {
+ // success
+ }
+ try {
+ p.evaluate(d, 0, d.length, 101.0);
+ fail();
+ } catch (IllegalArgumentException ex) {
+ // success
+ }
}
public void testNISTExample() {
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org