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;
018    
019    import org.apache.commons.math.stat.descriptive.moment.FourthMoment;
020    import org.apache.commons.math.stat.descriptive.moment.Kurtosis;
021    import org.apache.commons.math.stat.descriptive.moment.Mean;
022    import org.apache.commons.math.stat.descriptive.moment.Skewness;
023    import org.apache.commons.math.stat.descriptive.moment.Variance;
024    
025    import junit.framework.TestCase;
026    
027    /**
028     * @version $Revision: 670469 $ $Date: 2008-06-23 04:01:38 -0400 (Mon, 23 Jun 2008) $
029     */
030    public class InteractionTest extends TestCase {
031    
032        protected double mean = 12.40454545454550;
033        protected double var = 10.00235930735930;
034        protected double skew = 1.437423729196190;
035        protected double kurt = 2.377191264804700;
036    
037        protected double tolerance = 10E-12;
038    
039        protected double[] testArray =
040            {
041                12.5,
042                12,
043                11.8,
044                14.2,
045                14.9,
046                14.5,
047                21,
048                8.2,
049                10.3,
050                11.3,
051                14.1,
052                9.9,
053                12.2,
054                12,
055                12.1,
056                11,
057                19.8,
058                11,
059                10,
060                8.8,
061                9,
062                12.3 };
063    
064        public InteractionTest(String name) {
065            super(name);
066        }
067    
068    
069        public void testInteraction() {
070            
071            FourthMoment m4 = new FourthMoment();
072            Mean m = new Mean(m4);
073            Variance v = new Variance(m4);
074            Skewness s= new Skewness(m4);
075            Kurtosis k = new Kurtosis(m4);
076    
077            for (int i = 0; i < testArray.length; i++){
078                m4.increment(testArray[i]);
079            }
080            
081            assertEquals(mean,m.getResult(),tolerance);
082            assertEquals(var,v.getResult(),tolerance);
083            assertEquals(skew ,s.getResult(),tolerance);
084            assertEquals(kurt,k.getResult(),tolerance);
085    
086        }
087    
088    }