Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 89F9010FB7 for ; Thu, 31 Oct 2013 21:54:46 +0000 (UTC) Received: (qmail 70804 invoked by uid 500); 31 Oct 2013 21:54:46 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 70734 invoked by uid 500); 31 Oct 2013 21:54:46 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 70727 invoked by uid 99); 31 Oct 2013 21:54:46 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 31 Oct 2013 21:54:46 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 31 Oct 2013 21:54:44 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 84C6F23888CD; Thu, 31 Oct 2013 21:54:22 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: 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/ Date: Thu, 31 Oct 2013 21:54:22 -0000 To: commits@commons.apache.org From: tn@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20131031215422.84C6F23888CD@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 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(...). 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