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 junit.framework.Test;
20  import junit.framework.TestCase;
21  import junit.framework.TestSuite;
22  
23  import org.apache.commons.math.stat.descriptive.moment.Mean;
24  
25  /**
26   * Tests for AbstractUnivariateStatistic 
27   *
28   * @version $Revision: 670469 $ $Date: 2008-06-23 04:01:38 -0400 (Mon, 23 Jun 2008) $
29   */
30  public class AbstractUnivariateStatisticTest extends TestCase {
31      
32      public AbstractUnivariateStatisticTest(String name) {
33          super(name);
34      }
35      
36      public static Test suite() {
37          TestSuite suite = new TestSuite(AbstractUnivariateStatisticTest.class);
38          suite.setName("AbstractUnivariateStatistic Tests");
39          return suite;
40      }
41      
42      protected double[] testArray = {0, 1, 2, 3, 4, 5};
43      protected double[] nullArray = null;
44      protected double[] singletonArray = {0};
45      protected Mean testStatistic = new Mean();
46      
47      public void testTestPositive() {
48          for (int j = 0; j < 6; j++) {
49              for (int i = 1; i < (7 - j); i++) {
50                  assertTrue(testStatistic.test(testArray, 0, i));
51              }  
52          }
53          assertTrue(testStatistic.test(singletonArray, 0, 1));
54      }
55      
56      public void testTestNegative() {
57          assertFalse(testStatistic.test(singletonArray, 0, 0));
58          assertFalse(testStatistic.test(testArray, 0, 0));
59          try {
60              testStatistic.test(singletonArray, 2, 1);  // start past end
61              fail("Expecting IllegalArgumentException");
62          } catch (IllegalArgumentException ex) {
63              // expected
64          }
65          try {
66              testStatistic.test(testArray, 0, 7);  // end past end
67              fail("Expecting IllegalArgumentException");
68          } catch (IllegalArgumentException ex) {
69              // expected
70          }
71          try {
72              testStatistic.test(testArray, -1, 1);  // start negative
73              fail("Expecting IllegalArgumentException");
74          } catch (IllegalArgumentException ex) {
75              // expected
76          }
77          try {
78              testStatistic.test(testArray, 0, -1);  // length negative
79              fail("Expecting IllegalArgumentException");
80          } catch (IllegalArgumentException ex) {
81              // expected
82          }
83          try {
84              testStatistic.test(nullArray, 0, 1);  // null array
85              fail("Expecting IllegalArgumentException");
86          } catch (IllegalArgumentException ex) {
87              // expected
88          }      
89      } 
90  }