1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.math.stat.descriptive;
18  
19  import org.apache.commons.math.stat.descriptive.moment.FourthMoment;
20  import org.apache.commons.math.stat.descriptive.moment.Kurtosis;
21  import org.apache.commons.math.stat.descriptive.moment.Mean;
22  import org.apache.commons.math.stat.descriptive.moment.Skewness;
23  import org.apache.commons.math.stat.descriptive.moment.Variance;
24  
25  import junit.framework.TestCase;
26  
27  /**
28   * @version $Revision: 670469 $ $Date: 2008-06-23 04:01:38 -0400 (Mon, 23 Jun 2008) $
29   */
30  public class InteractionTest extends TestCase {
31  
32      protected double mean = 12.40454545454550;
33      protected double var = 10.00235930735930;
34      protected double skew = 1.437423729196190;
35      protected double kurt = 2.377191264804700;
36  
37      protected double tolerance = 10E-12;
38  
39      protected double[] testArray =
40          {
41              12.5,
42              12,
43              11.8,
44              14.2,
45              14.9,
46              14.5,
47              21,
48              8.2,
49              10.3,
50              11.3,
51              14.1,
52              9.9,
53              12.2,
54              12,
55              12.1,
56              11,
57              19.8,
58              11,
59              10,
60              8.8,
61              9,
62              12.3 };
63  
64      public InteractionTest(String name) {
65          super(name);
66      }
67  
68  
69      public void testInteraction() {
70          
71          FourthMoment m4 = new FourthMoment();
72          Mean m = new Mean(m4);
73          Variance v = new Variance(m4);
74          Skewness s= new Skewness(m4);
75          Kurtosis k = new Kurtosis(m4);
76  
77          for (int i = 0; i < testArray.length; i++){
78              m4.increment(testArray[i]);
79          }
80          
81          assertEquals(mean,m.getResult(),tolerance);
82          assertEquals(var,v.getResult(),tolerance);
83          assertEquals(skew ,s.getResult(),tolerance);
84          assertEquals(kurt,k.getResult(),tolerance);
85  
86      }
87  
88  }