1   /*
2    * Copyright 2003-2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.commons.math.stat.descriptive;
17  
18  import junit.framework.TestCase;
19  
20  /**
21   * Test cases for the {@link UnivariateStatistic} class.
22   * @version $Revision: 155427 $ $Date: 2005-02-26 06:11:52 -0700 (Sat, 26 Feb 2005) $
23   */
24  public abstract class UnivariateStatisticAbstractTest extends TestCase {
25  
26      protected double mean = 12.404545454545455d;
27      protected double geoMean = 12.070589161633011d;
28  
29      protected double var = 10.00235930735931d;
30      protected double std = Math.sqrt(var);
31      protected double skew = 1.437423729196190d;
32      protected double kurt = 2.377191264804700d;
33  
34      protected double min = 8.2d;
35      protected double max = 21d;
36      protected double median = 12d;
37      protected double percentile5 = 8.29d;
38      protected double percentile95 = 20.82d;
39  
40      protected double product = 628096400563833396009676.9200400128d;
41      protected double sumLog = 54.7969806116451507d;
42      protected double sumSq = 3595.250d;
43      protected double sum = 272.90d;
44      protected double secondMoment = 210.04954545454547d;
45      protected double thirdMoment = 868.0906859504136;
46      protected double fourthMoment = 9244.080993773481;
47  
48      protected double tolerance = 10E-12;
49  
50      protected double[] testArray =
51          {12.5, 12, 11.8, 14.2, 14.9, 14.5, 21, 8.2, 10.3, 11.3,
52            14.1, 9.9, 12.2, 12, 12.1, 11, 19.8, 11, 10,  8.8,
53             9, 12.3 };
54  
55      public UnivariateStatisticAbstractTest(String name) {
56          super(name);
57      }
58  
59      public abstract UnivariateStatistic getUnivariateStatistic();
60  
61      public abstract double expectedValue();
62  
63      public double getTolerance() {
64          return tolerance;
65      }
66  
67      public void testEvaluation() throws Exception {   
68          assertEquals(
69              expectedValue(),
70              getUnivariateStatistic().evaluate(testArray),
71              getTolerance());
72      }
73      
74  }