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 junit.framework.TestCase; 020 021 /** 022 * Test cases for the {@link UnivariateStatistic} class. 023 * @version $Revision: 720030 $ $Date: 2008-11-23 13:47:50 -0500 (Sun, 23 Nov 2008) $ 024 */ 025 public abstract class UnivariateStatisticAbstractTest extends TestCase { 026 027 protected double mean = 12.404545454545455d; 028 protected double geoMean = 12.070589161633011d; 029 030 protected double var = 10.00235930735931d; 031 protected double std = Math.sqrt(var); 032 protected double skew = 1.437423729196190d; 033 protected double kurt = 2.377191264804700d; 034 035 protected double min = 8.2d; 036 protected double max = 21d; 037 protected double median = 12d; 038 protected double percentile5 = 8.29d; 039 protected double percentile95 = 20.82d; 040 041 protected double product = 628096400563833396009676.9200400128d; 042 protected double sumLog = 54.7969806116451507d; 043 protected double sumSq = 3595.250d; 044 protected double sum = 272.90d; 045 protected double secondMoment = 210.04954545454547d; 046 protected double thirdMoment = 868.0906859504136; 047 protected double fourthMoment = 9244.080993773481; 048 049 protected double tolerance = 10E-12; 050 051 protected double[] testArray = 052 {12.5, 12, 11.8, 14.2, 14.9, 14.5, 21, 8.2, 10.3, 11.3, 053 14.1, 9.9, 12.2, 12, 12.1, 11, 19.8, 11, 10, 8.8, 054 9, 12.3 }; 055 056 public UnivariateStatisticAbstractTest(String name) { 057 super(name); 058 } 059 060 public abstract UnivariateStatistic getUnivariateStatistic(); 061 062 public abstract double expectedValue(); 063 064 public double getTolerance() { 065 return tolerance; 066 } 067 068 public void testEvaluation() throws Exception { 069 assertEquals( 070 expectedValue(), 071 getUnivariateStatistic().evaluate(testArray), 072 getTolerance()); 073 } 074 075 public void testCopy() throws Exception { 076 UnivariateStatistic original = getUnivariateStatistic(); 077 UnivariateStatistic copy = original.copy(); 078 assertEquals( 079 expectedValue(), 080 copy.evaluate(testArray), 081 getTolerance()); 082 } 083 084 }