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.moment;
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 UnivariateStatistic} class.
027 *
028 * @version $Revision: 762087 $ $Date: 2009-04-05 10:20:18 -0400 (Sun, 05 Apr 2009) $
029 */
030 public class SkewnessTest extends StorelessUnivariateStatisticAbstractTest{
031
032 protected Skewness stat;
033
034 /**
035 * @param name
036 */
037 public SkewnessTest(String name) {
038 super(name);
039 }
040
041 /**
042 * {@inheritDoc}
043 */
044 @Override
045 public UnivariateStatistic getUnivariateStatistic() {
046 return new Skewness();
047 }
048
049 public static Test suite() {
050 TestSuite suite = new TestSuite(SkewnessTest.class);
051 suite.setName("Skewness Tests");
052 return suite;
053 }
054
055 /**
056 * {@inheritDoc}
057 */
058 @Override
059 public double expectedValue() {
060 return this.skew;
061 }
062
063 /**
064 * Make sure Double.NaN is returned iff n < 3
065 *
066 */
067 public void testNaN() {
068 Skewness skew = new Skewness();
069 assertTrue(Double.isNaN(skew.getResult()));
070 skew.increment(1d);
071 assertTrue(Double.isNaN(skew.getResult()));
072 skew.increment(1d);
073 assertTrue(Double.isNaN(skew.getResult()));
074 skew.increment(1d);
075 assertFalse(Double.isNaN(skew.getResult()));
076 }
077
078 }