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 org.apache.commons.math.stat.descriptive.moment.FourthMoment;
19  import org.apache.commons.math.stat.descriptive.moment.Kurtosis;
20  import org.apache.commons.math.stat.descriptive.moment.Mean;
21  import org.apache.commons.math.stat.descriptive.moment.Skewness;
22  import org.apache.commons.math.stat.descriptive.moment.Variance;
23  
24  import junit.framework.TestCase;
25  
26  /**
27   * @version $Revision: 155427 $ $Date: 2005-02-26 06:11:52 -0700 (Sat, 26 Feb 2005) $
28   */
29  public class InteractionTest extends TestCase {
30  
31      protected double mean = 12.40454545454550;
32      protected double var = 10.00235930735930;
33      protected double skew = 1.437423729196190;
34      protected double kurt = 2.377191264804700;
35  
36      protected double tolerance = 10E-12;
37  
38      protected double[] testArray =
39          {
40              12.5,
41              12,
42              11.8,
43              14.2,
44              14.9,
45              14.5,
46              21,
47              8.2,
48              10.3,
49              11.3,
50              14.1,
51              9.9,
52              12.2,
53              12,
54              12.1,
55              11,
56              19.8,
57              11,
58              10,
59              8.8,
60              9,
61              12.3 };
62  
63      public InteractionTest(String name) {
64          super(name);
65      }
66  
67  
68      public void testInteraction() {
69          
70          FourthMoment m4 = new FourthMoment();
71          Mean m = new Mean(m4);
72          Variance v = new Variance(m4);
73          Skewness s= new Skewness(m4);
74          Kurtosis k = new Kurtosis(m4);
75  
76          for (int i = 0; i < testArray.length; i++){
77              m4.increment(testArray[i]);
78          }
79          
80          assertEquals(mean,m.getResult(),tolerance);
81          assertEquals(var,v.getResult(),tolerance);
82          assertEquals(skew ,s.getResult(),tolerance);
83          assertEquals(kurt,k.getResult(),tolerance);
84  
85      }
86  
87  }