From 30b9f935e7ea56026e5c5347e897df52a3ad18a7 Mon Sep 17 00:00:00 2001 From: Gilles Sadowski Date: Tue, 16 Sep 2014 10:35:59 +0000 Subject: [PATCH] MATH-1146 Unit tests showing that the current implementation fails on some special values (infinities). Other descriptive statistics values are probably similarly affected. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1625238 13f79535-47bb-0310-9956-ffa450edef68 --- .../descriptive/moment/FirstMomentTest.java | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/src/test/java/org/apache/commons/math3/stat/descriptive/moment/FirstMomentTest.java b/src/test/java/org/apache/commons/math3/stat/descriptive/moment/FirstMomentTest.java index f66eee07f..644a35a85 100644 --- a/src/test/java/org/apache/commons/math3/stat/descriptive/moment/FirstMomentTest.java +++ b/src/test/java/org/apache/commons/math3/stat/descriptive/moment/FirstMomentTest.java @@ -18,6 +18,8 @@ package org.apache.commons.math3.stat.descriptive.moment; import org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatisticAbstractTest; import org.apache.commons.math3.stat.descriptive.UnivariateStatistic; +import org.junit.Assert; +import org.junit.Test; /** * Test cases for the {@link FirstMoment} class. @@ -44,4 +46,67 @@ public class FirstMomentTest extends StorelessUnivariateStatisticAbstractTest{ return this.mean; } + /** + * Added in an attempt to resolve MATH-1146 + * Commented out tests that won't pass with the current implementation. + */ + @Test + public void testSpecialValues() { + final FirstMoment mean = new FirstMoment(); + +// mean.clear(); +// mean.increment(Double.POSITIVE_INFINITY); +// mean.increment(1d); +// Assert.assertEquals(Double.POSITIVE_INFINITY, mean.getResult(), 0d); + +// mean.clear(); +// mean.increment(Double.POSITIVE_INFINITY); +// mean.increment(-1d); +// Assert.assertEquals(Double.POSITIVE_INFINITY, mean.getResult(), 0d); + +// mean.clear(); +// mean.increment(Double.NEGATIVE_INFINITY); +// mean.increment(1d); +// Assert.assertEquals(Double.NEGATIVE_INFINITY, mean.getResult(), 0d); + +// mean.clear(); +// mean.increment(Double.NEGATIVE_INFINITY); +// mean.increment(-1d); +// Assert.assertEquals(Double.NEGATIVE_INFINITY, mean.getResult(), 0d); + +// mean.clear(); +// mean.increment(Double.POSITIVE_INFINITY); +// mean.increment(Double.POSITIVE_INFINITY); +// Assert.assertEquals(Double.POSITIVE_INFINITY, mean.getResult(), 0d); + +// mean.clear(); +// mean.increment(Double.NEGATIVE_INFINITY); +// mean.increment(Double.NEGATIVE_INFINITY); +// Assert.assertEquals(Double.NEGATIVE_INFINITY, mean.getResult(), 0d); + + mean.clear(); + mean.increment(Double.POSITIVE_INFINITY); + mean.increment(Double.NEGATIVE_INFINITY); + Assert.assertTrue(Double.isNaN(mean.getResult())); + + mean.clear(); + mean.increment(Double.NEGATIVE_INFINITY); + mean.increment(Double.POSITIVE_INFINITY); + Assert.assertTrue(Double.isNaN(mean.getResult())); + + mean.clear(); + mean.increment(Double.NaN); + mean.increment(Double.POSITIVE_INFINITY); + Assert.assertTrue(Double.isNaN(mean.getResult())); + + mean.clear(); + mean.increment(Double.NaN); + mean.increment(Double.NEGATIVE_INFINITY); + Assert.assertTrue(Double.isNaN(mean.getResult())); + + mean.clear(); + mean.increment(Double.NaN); + mean.increment(0d); + Assert.assertTrue(Double.isNaN(mean.getResult())); + } }