From e5ea3a0485a350cde9ffa034ebdc205ffa4ac54a Mon Sep 17 00:00:00 2001 From: Phil Steitz Date: Fri, 18 Jun 2004 07:04:20 +0000 Subject: [PATCH] Added tests for special values. git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/math/trunk@141317 13f79535-47bb-0310-9956-ffa450edef68 --- .../univariate/moment/GeometricMeanTest.java | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/test/org/apache/commons/math/stat/univariate/moment/GeometricMeanTest.java b/src/test/org/apache/commons/math/stat/univariate/moment/GeometricMeanTest.java index bad3cb3de..f1f85056d 100644 --- a/src/test/org/apache/commons/math/stat/univariate/moment/GeometricMeanTest.java +++ b/src/test/org/apache/commons/math/stat/univariate/moment/GeometricMeanTest.java @@ -23,7 +23,7 @@ import org.apache.commons.math.stat.univariate.UnivariateStatistic; /** * Test cases for the {@link UnivariateStatistic} class. - * @version $Revision: 1.10 $ $Date: 2004/06/17 21:37:05 $ + * @version $Revision: 1.11 $ $Date: 2004/06/18 07:04:20 $ */ public class GeometricMeanTest extends StorelessUnivariateStatisticAbstractTest{ @@ -55,5 +55,35 @@ public class GeometricMeanTest extends StorelessUnivariateStatisticAbstractTest{ public double expectedValue() { return this.geoMean; } + + public void testSpecialValues() { + GeometricMean mean = new GeometricMean(); + // empty + assertTrue(Double.isNaN(mean.getResult())); + + // finite data + mean.increment(1d); + assertFalse(Double.isNaN(mean.getResult())); + + // add 0 -- makes log sum blow to minus infinity, should make 0 + mean.increment(0d); + assertEquals(0d, mean.getResult(), 0); + + // add positive infinity - note the minus infinity above + mean.increment(Double.POSITIVE_INFINITY); + assertTrue(Double.isNaN(mean.getResult())); + + // clear + mean.clear(); + assertTrue(Double.isNaN(mean.getResult())); + + // positive infinity by itself + mean.increment(Double.POSITIVE_INFINITY); + assertEquals(Double.POSITIVE_INFINITY, mean.getResult(), 0); + + // negative value -- should make NaN + mean.increment(-2d); + assertTrue(Double.isNaN(mean.getResult())); + } }