1 16 package org.apache.commons.math.stat.descriptive.summary; 17 18 import junit.framework.Test; 19 import junit.framework.TestSuite; 20 21 import org.apache.commons.math.stat.descriptive.StorelessUnivariateStatisticAbstractTest; 22 import org.apache.commons.math.stat.descriptive.UnivariateStatistic; 23 24 29 public class SumSqTest extends StorelessUnivariateStatisticAbstractTest{ 30 31 protected SumOfSquares stat; 32 33 36 public SumSqTest(String name) { 37 super(name); 38 } 39 40 public static Test suite() { 41 TestSuite suite = new TestSuite(SumSqTest.class); 42 suite.setName("SumSq Tests"); 43 return suite; 44 } 45 46 49 public UnivariateStatistic getUnivariateStatistic() { 50 return new SumOfSquares(); 51 } 52 53 56 public double expectedValue() { 57 return this.sumSq; 58 } 59 60 public void testSpecialValues() { 61 SumOfSquares sumSq = new SumOfSquares(); 62 assertTrue(Double.isNaN(sumSq.getResult())); 63 sumSq.increment(2d); 64 assertEquals(4d, sumSq.getResult(), 0); 65 sumSq.increment(Double.POSITIVE_INFINITY); 66 assertEquals(Double.POSITIVE_INFINITY, sumSq.getResult(), 0); 67 sumSq.increment(Double.NEGATIVE_INFINITY); 68 assertEquals(Double.POSITIVE_INFINITY, sumSq.getResult(), 0); 69 sumSq.increment(Double.NaN); 70 assertTrue(Double.isNaN(sumSq.getResult())); 71 sumSq.increment(1); 72 assertTrue(Double.isNaN(sumSq.getResult())); 73 } 74 75 } 76 | Popular Tags |