You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2014/09/16 12:36:00 UTC
svn commit: r1625238 -
/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/stat/descriptive/moment/FirstMomentTest.java
Author: erans
Date: Tue Sep 16 10:35:59 2014
New Revision: 1625238
URL: http://svn.apache.org/r1625238
Log:
MATH-1146
Unit tests showing that the current implementation fails on some
special values (infinities). Other descriptive statistics values
are probably similarly affected.
Modified:
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/stat/descriptive/moment/FirstMomentTest.java
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/stat/descriptive/moment/FirstMomentTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/stat/descriptive/moment/FirstMomentTest.java?rev=1625238&r1=1625237&r2=1625238&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/stat/descriptive/moment/FirstMomentTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/stat/descriptive/moment/FirstMomentTest.java Tue Sep 16 10:35:59 2014
@@ -18,6 +18,8 @@ package org.apache.commons.math3.stat.de
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 Sto
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()));
+ }
}