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
This commit is contained in:
parent
76f154179b
commit
30b9f935e7
|
@ -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()));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue