diff --git a/src/test/org/apache/commons/math/stat/univariate/StorelessUnivariateStatisticAbstractTest.java b/src/test/org/apache/commons/math/stat/univariate/StorelessUnivariateStatisticAbstractTest.java new file mode 100644 index 000000000..8726ab01d --- /dev/null +++ b/src/test/org/apache/commons/math/stat/univariate/StorelessUnivariateStatisticAbstractTest.java @@ -0,0 +1,93 @@ +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2003 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Commons", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ +package org.apache.commons.math.stat.univariate; + +import junit.framework.TestCase; + +/** + * Test cases for the {@link UnivariateStatistic} class. + * + * @author Mark Diggory + */ +public abstract class StorelessUnivariateStatisticAbstractTest + extends UnivariateStatisticAbstractTest { + + public StorelessUnivariateStatisticAbstractTest(String name) { + super(name); + } + + public abstract UnivariateStatistic getUnivariateStatistic(); + + public abstract double expectedValue(); + + public void testIncrementation() throws Exception { + + StorelessUnivariateStatistic statistic = + (StorelessUnivariateStatistic) getUnivariateStatistic(); + + statistic.clear(); + + for (int i = 0; i < testArray.length; i++) { + statistic.increment(testArray[i]); + } + + assertEquals(expectedValue(), statistic.getValue(), getTolerance()); + + statistic.clear(); + + assertTrue(Double.isNaN(statistic.getValue())); + + } + +} diff --git a/src/test/org/apache/commons/math/stat/univariate/UnivariateStatisticAbstractTest.java b/src/test/org/apache/commons/math/stat/univariate/UnivariateStatisticAbstractTest.java index 02837a0cc..cd7610bcb 100644 --- a/src/test/org/apache/commons/math/stat/univariate/UnivariateStatisticAbstractTest.java +++ b/src/test/org/apache/commons/math/stat/univariate/UnivariateStatisticAbstractTest.java @@ -124,5 +124,5 @@ public abstract class UnivariateStatisticAbstractTest extends TestCase { getUnivariateStatistic().evaluate(testArray), getTolerance()); } - + } diff --git a/src/test/org/apache/commons/math/stat/univariate/moment/KurtosisTest.java b/src/test/org/apache/commons/math/stat/univariate/moment/KurtosisTest.java index 8310cdbd4..912a22823 100644 --- a/src/test/org/apache/commons/math/stat/univariate/moment/KurtosisTest.java +++ b/src/test/org/apache/commons/math/stat/univariate/moment/KurtosisTest.java @@ -56,6 +56,7 @@ package org.apache.commons.math.stat.univariate.moment; import junit.framework.Test; import junit.framework.TestSuite; +import org.apache.commons.math.stat.univariate.StorelessUnivariateStatisticAbstractTest; import org.apache.commons.math.stat.univariate.UnivariateStatistic; import org.apache.commons.math.stat.univariate.UnivariateStatisticAbstractTest; @@ -64,7 +65,7 @@ import org.apache.commons.math.stat.univariate.UnivariateStatisticAbstractTest; * * @author Mark Diggory */ -public class KurtosisTest extends UnivariateStatisticAbstractTest{ +public class KurtosisTest extends StorelessUnivariateStatisticAbstractTest{ protected Kurtosis stat; diff --git a/src/test/org/apache/commons/math/stat/univariate/moment/MeanTest.java b/src/test/org/apache/commons/math/stat/univariate/moment/MeanTest.java index 4b1e8e6a3..7690acb77 100644 --- a/src/test/org/apache/commons/math/stat/univariate/moment/MeanTest.java +++ b/src/test/org/apache/commons/math/stat/univariate/moment/MeanTest.java @@ -56,6 +56,7 @@ package org.apache.commons.math.stat.univariate.moment; import junit.framework.Test; import junit.framework.TestSuite; +import org.apache.commons.math.stat.univariate.StorelessUnivariateStatisticAbstractTest; import org.apache.commons.math.stat.univariate.UnivariateStatistic; import org.apache.commons.math.stat.univariate.UnivariateStatisticAbstractTest; @@ -64,7 +65,7 @@ import org.apache.commons.math.stat.univariate.UnivariateStatisticAbstractTest; * * @author Mark Diggory */ -public class MeanTest extends UnivariateStatisticAbstractTest{ +public class MeanTest extends StorelessUnivariateStatisticAbstractTest{ protected Mean stat; diff --git a/src/test/org/apache/commons/math/stat/univariate/moment/SkewnessTest.java b/src/test/org/apache/commons/math/stat/univariate/moment/SkewnessTest.java index b06d91de8..7ad1606b6 100644 --- a/src/test/org/apache/commons/math/stat/univariate/moment/SkewnessTest.java +++ b/src/test/org/apache/commons/math/stat/univariate/moment/SkewnessTest.java @@ -56,6 +56,7 @@ package org.apache.commons.math.stat.univariate.moment; import junit.framework.Test; import junit.framework.TestSuite; +import org.apache.commons.math.stat.univariate.StorelessUnivariateStatisticAbstractTest; import org.apache.commons.math.stat.univariate.UnivariateStatistic; import org.apache.commons.math.stat.univariate.UnivariateStatisticAbstractTest; @@ -64,7 +65,7 @@ import org.apache.commons.math.stat.univariate.UnivariateStatisticAbstractTest; * * @author Mark Diggory */ -public class SkewnessTest extends UnivariateStatisticAbstractTest{ +public class SkewnessTest extends StorelessUnivariateStatisticAbstractTest{ protected Skewness stat; diff --git a/src/test/org/apache/commons/math/stat/univariate/moment/StandardDeviationTest.java b/src/test/org/apache/commons/math/stat/univariate/moment/StandardDeviationTest.java index 887fc3a84..2623dc39c 100644 --- a/src/test/org/apache/commons/math/stat/univariate/moment/StandardDeviationTest.java +++ b/src/test/org/apache/commons/math/stat/univariate/moment/StandardDeviationTest.java @@ -56,6 +56,7 @@ package org.apache.commons.math.stat.univariate.moment; import junit.framework.Test; import junit.framework.TestSuite; +import org.apache.commons.math.stat.univariate.StorelessUnivariateStatisticAbstractTest; import org.apache.commons.math.stat.univariate.UnivariateStatistic; import org.apache.commons.math.stat.univariate.UnivariateStatisticAbstractTest; @@ -64,7 +65,7 @@ import org.apache.commons.math.stat.univariate.UnivariateStatisticAbstractTest; * * @author Mark Diggory */ -public class StandardDeviationTest extends UnivariateStatisticAbstractTest{ +public class StandardDeviationTest extends StorelessUnivariateStatisticAbstractTest{ protected StandardDeviation stat; diff --git a/src/test/org/apache/commons/math/stat/univariate/moment/VarianceTest.java b/src/test/org/apache/commons/math/stat/univariate/moment/VarianceTest.java index 5bfabeb28..f99a7ef46 100644 --- a/src/test/org/apache/commons/math/stat/univariate/moment/VarianceTest.java +++ b/src/test/org/apache/commons/math/stat/univariate/moment/VarianceTest.java @@ -56,6 +56,7 @@ package org.apache.commons.math.stat.univariate.moment; import junit.framework.Test; import junit.framework.TestSuite; +import org.apache.commons.math.stat.univariate.StorelessUnivariateStatisticAbstractTest; import org.apache.commons.math.stat.univariate.UnivariateStatistic; import org.apache.commons.math.stat.univariate.UnivariateStatisticAbstractTest; @@ -64,7 +65,7 @@ import org.apache.commons.math.stat.univariate.UnivariateStatisticAbstractTest; * * @author Mark Diggory */ -public class VarianceTest extends UnivariateStatisticAbstractTest{ +public class VarianceTest extends StorelessUnivariateStatisticAbstractTest{ protected Variance stat; diff --git a/src/test/org/apache/commons/math/stat/univariate/rank/MaxTest.java b/src/test/org/apache/commons/math/stat/univariate/rank/MaxTest.java index 1f4445ce1..b7c0f9565 100644 --- a/src/test/org/apache/commons/math/stat/univariate/rank/MaxTest.java +++ b/src/test/org/apache/commons/math/stat/univariate/rank/MaxTest.java @@ -56,6 +56,7 @@ package org.apache.commons.math.stat.univariate.rank; import junit.framework.Test; import junit.framework.TestSuite; +import org.apache.commons.math.stat.univariate.StorelessUnivariateStatisticAbstractTest; import org.apache.commons.math.stat.univariate.UnivariateStatistic; import org.apache.commons.math.stat.univariate.UnivariateStatisticAbstractTest; @@ -64,7 +65,7 @@ import org.apache.commons.math.stat.univariate.UnivariateStatisticAbstractTest; * * @author Mark Diggory */ -public class MaxTest extends UnivariateStatisticAbstractTest{ +public class MaxTest extends StorelessUnivariateStatisticAbstractTest{ protected Max stat; diff --git a/src/test/org/apache/commons/math/stat/univariate/rank/MinTest.java b/src/test/org/apache/commons/math/stat/univariate/rank/MinTest.java index 1d72da157..21ca88dac 100644 --- a/src/test/org/apache/commons/math/stat/univariate/rank/MinTest.java +++ b/src/test/org/apache/commons/math/stat/univariate/rank/MinTest.java @@ -56,6 +56,7 @@ package org.apache.commons.math.stat.univariate.rank; import junit.framework.Test; import junit.framework.TestSuite; +import org.apache.commons.math.stat.univariate.StorelessUnivariateStatisticAbstractTest; import org.apache.commons.math.stat.univariate.UnivariateStatistic; import org.apache.commons.math.stat.univariate.UnivariateStatisticAbstractTest; @@ -64,7 +65,7 @@ import org.apache.commons.math.stat.univariate.UnivariateStatisticAbstractTest; * * @author Mark Diggory */ -public class MinTest extends UnivariateStatisticAbstractTest{ +public class MinTest extends StorelessUnivariateStatisticAbstractTest{ protected Min stat; diff --git a/src/test/org/apache/commons/math/stat/univariate/summary/ProductTest.java b/src/test/org/apache/commons/math/stat/univariate/summary/ProductTest.java index 4aea3aba1..9a50eb5d6 100644 --- a/src/test/org/apache/commons/math/stat/univariate/summary/ProductTest.java +++ b/src/test/org/apache/commons/math/stat/univariate/summary/ProductTest.java @@ -56,6 +56,7 @@ package org.apache.commons.math.stat.univariate.summary; import junit.framework.Test; import junit.framework.TestSuite; +import org.apache.commons.math.stat.univariate.StorelessUnivariateStatisticAbstractTest; import org.apache.commons.math.stat.univariate.UnivariateStatistic; import org.apache.commons.math.stat.univariate.UnivariateStatisticAbstractTest; @@ -64,7 +65,7 @@ import org.apache.commons.math.stat.univariate.UnivariateStatisticAbstractTest; * * @author Mark Diggory */ -public class ProductTest extends UnivariateStatisticAbstractTest{ +public class ProductTest extends StorelessUnivariateStatisticAbstractTest{ protected Product stat; diff --git a/src/test/org/apache/commons/math/stat/univariate/summary/SumLogTest.java b/src/test/org/apache/commons/math/stat/univariate/summary/SumLogTest.java index fac46b1cf..5e364309a 100644 --- a/src/test/org/apache/commons/math/stat/univariate/summary/SumLogTest.java +++ b/src/test/org/apache/commons/math/stat/univariate/summary/SumLogTest.java @@ -56,6 +56,7 @@ package org.apache.commons.math.stat.univariate.summary; import junit.framework.Test; import junit.framework.TestSuite; +import org.apache.commons.math.stat.univariate.StorelessUnivariateStatisticAbstractTest; import org.apache.commons.math.stat.univariate.UnivariateStatistic; import org.apache.commons.math.stat.univariate.UnivariateStatisticAbstractTest; @@ -64,7 +65,7 @@ import org.apache.commons.math.stat.univariate.UnivariateStatisticAbstractTest; * * @author Mark Diggory */ -public class SumLogTest extends UnivariateStatisticAbstractTest{ +public class SumLogTest extends StorelessUnivariateStatisticAbstractTest{ protected SumOfLogs stat; diff --git a/src/test/org/apache/commons/math/stat/univariate/summary/SumSqTest.java b/src/test/org/apache/commons/math/stat/univariate/summary/SumSqTest.java index 1815a365f..351cef231 100644 --- a/src/test/org/apache/commons/math/stat/univariate/summary/SumSqTest.java +++ b/src/test/org/apache/commons/math/stat/univariate/summary/SumSqTest.java @@ -56,6 +56,7 @@ package org.apache.commons.math.stat.univariate.summary; import junit.framework.Test; import junit.framework.TestSuite; +import org.apache.commons.math.stat.univariate.StorelessUnivariateStatisticAbstractTest; import org.apache.commons.math.stat.univariate.UnivariateStatistic; import org.apache.commons.math.stat.univariate.UnivariateStatisticAbstractTest; @@ -64,7 +65,7 @@ import org.apache.commons.math.stat.univariate.UnivariateStatisticAbstractTest; * * @author Mark Diggory */ -public class SumSqTest extends UnivariateStatisticAbstractTest{ +public class SumSqTest extends StorelessUnivariateStatisticAbstractTest{ protected SumOfSquares stat; diff --git a/src/test/org/apache/commons/math/stat/univariate/summary/SumTest.java b/src/test/org/apache/commons/math/stat/univariate/summary/SumTest.java index b717cd133..403cdd256 100644 --- a/src/test/org/apache/commons/math/stat/univariate/summary/SumTest.java +++ b/src/test/org/apache/commons/math/stat/univariate/summary/SumTest.java @@ -56,6 +56,7 @@ package org.apache.commons.math.stat.univariate.summary; import junit.framework.Test; import junit.framework.TestSuite; +import org.apache.commons.math.stat.univariate.StorelessUnivariateStatisticAbstractTest; import org.apache.commons.math.stat.univariate.UnivariateStatistic; import org.apache.commons.math.stat.univariate.UnivariateStatisticAbstractTest; @@ -64,7 +65,7 @@ import org.apache.commons.math.stat.univariate.UnivariateStatisticAbstractTest; * * @author Mark Diggory */ -public class SumTest extends UnivariateStatisticAbstractTest{ +public class SumTest extends StorelessUnivariateStatisticAbstractTest{ protected Sum stat;