You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by tn...@apache.org on 2013/10/31 22:54:22 UTC

svn commit: r1537714 - in /commons/proper/math/trunk/src: changes/ main/java/org/apache/commons/math3/stat/descriptive/ main/java/org/apache/commons/math3/util/ test/java/org/apache/commons/math3/util/

Author: tn
Date: Thu Oct 31 21:54:21 2013
New Revision: 1537714

URL: http://svn.apache.org/r1537714
Log:
[MATH-1002] Renamed methods to verifyValues, also copied unit tests to MathArraysTest.

Modified:
    commons/proper/math/trunk/src/changes/changes.xml
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/AbstractUnivariateStatistic.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/MathArrays.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/util/MathArraysTest.java   (contents, props changed)

Modified: commons/proper/math/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/changes/changes.xml?rev=1537714&r1=1537713&r2=1537714&view=diff
==============================================================================
--- commons/proper/math/trunk/src/changes/changes.xml (original)
+++ commons/proper/math/trunk/src/changes/changes.xml Thu Oct 31 21:54:21 2013
@@ -94,7 +94,7 @@ If the output is not quite correct, chec
       </action>
       <action dev="sebb" type="add" issue="MATH-1002">
         AbstractUnivariateStatistic.test(double[] values, int begin, int length, boolean allowEmpty)
-        has uses outside subclasses; implementation moved to MathArrays.
+        has uses outside subclasses; implementation moved to MathArrays.verifyValues(...).
       </action>
       <action dev="tn" type="fix" issue="MATH-1033" due-to="Yuan Qu">
         The "KalmanFilter" wrongly enforced a column dimension of 1 for

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/AbstractUnivariateStatistic.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/AbstractUnivariateStatistic.java?rev=1537714&r1=1537713&r2=1537714&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/AbstractUnivariateStatistic.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/AbstractUnivariateStatistic.java Thu Oct 31 21:54:21 2013
@@ -158,7 +158,7 @@ public abstract class AbstractUnivariate
         final double[] values,
         final int begin,
         final int length) throws MathIllegalArgumentException {
-        return MathArrays.test(values, begin, length, false);
+        return MathArrays.verifyValues(values, begin, length, false);
     }
 
     /**
@@ -186,7 +186,7 @@ public abstract class AbstractUnivariate
     @Deprecated
     protected boolean test(final double[] values, final int begin,
             final int length, final boolean allowEmpty) throws MathIllegalArgumentException {
-        return MathArrays.test(values, begin, length, allowEmpty);
+        return MathArrays.verifyValues(values, begin, length, allowEmpty);
     }
 
     /**
@@ -225,7 +225,7 @@ public abstract class AbstractUnivariate
         final double[] weights,
         final int begin,
         final int length) throws MathIllegalArgumentException {
-        return MathArrays.test(values, weights, begin, length, false);
+        return MathArrays.verifyValues(values, weights, begin, length, false);
     }
 
     /**
@@ -266,7 +266,7 @@ public abstract class AbstractUnivariate
     protected boolean test(final double[] values, final double[] weights,
             final int begin, final int length, final boolean allowEmpty) throws MathIllegalArgumentException {
 
-        return MathArrays.test(values, weights, begin, length, allowEmpty);
+        return MathArrays.verifyValues(values, weights, begin, length, allowEmpty);
     }
 }
 

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/MathArrays.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/MathArrays.java?rev=1537714&r1=1537713&r2=1537714&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/MathArrays.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/MathArrays.java Thu Oct 31 21:54:21 2013
@@ -1568,11 +1568,9 @@ public class MathArrays {
      * @throws MathIllegalArgumentException if the indices are invalid or the array is null
      * @since 3.3
      */
-    public static boolean test(
-        final double[] values,
-        final int begin,
-        final int length) throws MathIllegalArgumentException {
-        return test(values, begin, length, false);
+    public static boolean verifyValues(final double[] values, final int begin, final int length)
+            throws MathIllegalArgumentException {
+        return verifyValues(values, begin, length, false);
     }
 
     /**
@@ -1596,7 +1594,7 @@ public class MathArrays {
      * @throws MathIllegalArgumentException if the indices are invalid or the array is null
      * @since 3.3
      */
-    public static boolean test(final double[] values, final int begin,
+    public static boolean verifyValues(final double[] values, final int begin,
             final int length, final boolean allowEmpty) throws MathIllegalArgumentException {
 
         if (values == null) {
@@ -1653,12 +1651,12 @@ public class MathArrays {
      * @throws MathIllegalArgumentException if the indices are invalid or the array is null
      * @since 3.3
      */
-    public static boolean test(
+    public static boolean verifyValues(
         final double[] values,
         final double[] weights,
         final int begin,
         final int length) throws MathIllegalArgumentException {
-        return test(values, weights, begin, length, false);
+        return verifyValues(values, weights, begin, length, false);
     }
 
     /**
@@ -1694,7 +1692,7 @@ public class MathArrays {
      * are no positive weights.
      * @since 3.3
      */
-    public static boolean test(final double[] values, final double[] weights,
+    public static boolean verifyValues(final double[] values, final double[] weights,
             final int begin, final int length, final boolean allowEmpty) throws MathIllegalArgumentException {
 
         if (weights == null || values == null) {
@@ -1726,6 +1724,6 @@ public class MathArrays {
             throw new MathIllegalArgumentException(LocalizedFormats.WEIGHT_AT_LEAST_ONE_NON_ZERO);
         }
 
-        return test(values, begin, length, allowEmpty);
+        return verifyValues(values, begin, length, allowEmpty);
     }
 }

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/util/MathArraysTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/util/MathArraysTest.java?rev=1537714&r1=1537713&r2=1537714&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/util/MathArraysTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/util/MathArraysTest.java Thu Oct 31 21:54:21 2013
@@ -14,7 +14,6 @@
 package org.apache.commons.math3.util;
 
 import java.util.Arrays;
-import java.util.Iterator;
 
 import org.apache.commons.math3.TestUtils;
 import org.apache.commons.math3.exception.DimensionMismatchException;
@@ -36,6 +35,12 @@ import org.junit.Test;
  */
 public class MathArraysTest {
     
+    private double[] testArray = {0, 1, 2, 3, 4, 5};
+    private double[] testWeightsArray = {0.3, 0.2, 1.3, 1.1, 1.0, 1.8};
+    private double[] testNegativeWeightsArray = {-0.3, 0.2, -1.3, 1.1, 1.0, 1.8};
+    private double[] nullArray = null;
+    private double[] singletonArray = {0};
+
     @Test
     public void testScale() {
         final double[] test = new double[] { -2.5, -1, 0, 1, 2.5 };
@@ -996,4 +1001,69 @@ public class MathArraysTest {
         final int[] natural = MathArrays.natural(0);
         Assert.assertEquals(0, natural.length);
     }
+    
+    @Test
+    public void testVerifyValuesPositive() {
+        for (int j = 0; j < 6; j++) {
+            for (int i = 1; i < (7 - j); i++) {
+                Assert.assertTrue(MathArrays.verifyValues(testArray, 0, i));
+            }
+        }
+        Assert.assertTrue(MathArrays.verifyValues(singletonArray, 0, 1));
+        Assert.assertTrue(MathArrays.verifyValues(singletonArray, 0, 0, true));
+    }
+
+    @Test
+    public void testVerifyValuesNegative() {
+        Assert.assertFalse(MathArrays.verifyValues(singletonArray, 0, 0));
+        Assert.assertFalse(MathArrays.verifyValues(testArray, 0, 0));
+        try {
+            MathArrays.verifyValues(singletonArray, 2, 1);  // start past end
+            Assert.fail("Expecting MathIllegalArgumentException");
+        } catch (MathIllegalArgumentException ex) {
+            // expected
+        }
+        try {
+            MathArrays.verifyValues(testArray, 0, 7);  // end past end
+            Assert.fail("Expecting MathIllegalArgumentException");
+        } catch (MathIllegalArgumentException ex) {
+            // expected
+        }
+        try {
+            MathArrays.verifyValues(testArray, -1, 1);  // start negative
+            Assert.fail("Expecting MathIllegalArgumentException");
+        } catch (MathIllegalArgumentException ex) {
+            // expected
+        }
+        try {
+            MathArrays.verifyValues(testArray, 0, -1);  // length negative
+            Assert.fail("Expecting MathIllegalArgumentException");
+        } catch (MathIllegalArgumentException ex) {
+            // expected
+        }
+        try {
+            MathArrays.verifyValues(nullArray, 0, 1);  // null array
+            Assert.fail("Expecting MathIllegalArgumentException");
+        } catch (MathIllegalArgumentException ex) {
+            // expected
+        }
+        try {
+            MathArrays.verifyValues(testArray, nullArray, 0, 1);  // null weights array
+            Assert.fail("Expecting MathIllegalArgumentException");
+        } catch (MathIllegalArgumentException ex) {
+            // expected
+        }
+        try {
+            MathArrays.verifyValues(singletonArray, testWeightsArray, 0, 1);  // weights.length != value.length
+            Assert.fail("Expecting MathIllegalArgumentException");
+        } catch (MathIllegalArgumentException ex) {
+            // expected
+        }
+        try {
+            MathArrays.verifyValues(testArray, testNegativeWeightsArray, 0, 6);  // can't have negative weights
+            Assert.fail("Expecting MathIllegalArgumentException");
+        } catch (MathIllegalArgumentException ex) {
+            // expected
+        }
+    }
 }

Propchange: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/util/MathArraysTest.java
------------------------------------------------------------------------------
    svn:keywords = Id Revision