001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.commons.math.stat.descriptive.summary;
018
019 import junit.framework.Test;
020 import junit.framework.TestSuite;
021
022 import org.apache.commons.math.stat.descriptive.StorelessUnivariateStatisticAbstractTest;
023 import org.apache.commons.math.stat.descriptive.UnivariateStatistic;
024
025 /**
026 * Test cases for the {@link SumOfSquares} class.
027 *
028 * @version $Revision: 762087 $ $Date: 2009-04-05 10:20:18 -0400 (Sun, 05 Apr 2009) $
029 */
030 public class SumSqTest extends StorelessUnivariateStatisticAbstractTest{
031
032 protected SumOfSquares stat;
033
034 /**
035 * @param name
036 */
037 public SumSqTest(String name) {
038 super(name);
039 }
040
041 public static Test suite() {
042 TestSuite suite = new TestSuite(SumSqTest.class);
043 suite.setName("SumSq Tests");
044 return suite;
045 }
046
047 /**
048 * {@inheritDoc}
049 */
050 @Override
051 public UnivariateStatistic getUnivariateStatistic() {
052 return new SumOfSquares();
053 }
054
055 /**
056 * {@inheritDoc}
057 */
058 @Override
059 public double expectedValue() {
060 return this.sumSq;
061 }
062
063 public void testSpecialValues() {
064 SumOfSquares sumSq = new SumOfSquares();
065 assertTrue(Double.isNaN(sumSq.getResult()));
066 sumSq.increment(2d);
067 assertEquals(4d, sumSq.getResult(), 0);
068 sumSq.increment(Double.POSITIVE_INFINITY);
069 assertEquals(Double.POSITIVE_INFINITY, sumSq.getResult(), 0);
070 sumSq.increment(Double.NEGATIVE_INFINITY);
071 assertEquals(Double.POSITIVE_INFINITY, sumSq.getResult(), 0);
072 sumSq.increment(Double.NaN);
073 assertTrue(Double.isNaN(sumSq.getResult()));
074 sumSq.increment(1);
075 assertTrue(Double.isNaN(sumSq.getResult()));
076 }
077
078 }