1   /*
2    * 
3    * Copyright (c) 2004 The Apache Software Foundation. All rights reserved.
4    * 
5    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6    * use this file except in compliance with the License. You may obtain a copy
7    * 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, WITHOUT
13   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14   * License for the specific language governing permissions and limitations
15   * under the License.
16   *  
17   */
18  package org.apache.commons.math.stat.descriptive;
19  
20  import junit.framework.Test;
21  import junit.framework.TestCase;
22  import junit.framework.TestSuite;
23  
24  import org.apache.commons.math.stat.descriptive.moment.Mean;
25  
26  /**
27   * Tests for AbstractUnivariateStatistic 
28   *
29   * @version $Revision: 155427 $ $Date: 2005-02-26 06:11:52 -0700 (Sat, 26 Feb 2005) $
30   */
31  public class AbstractUnivariateStatisticTest extends TestCase {
32      
33      public AbstractUnivariateStatisticTest(String name) {
34          super(name);
35      }
36      
37      public static Test suite() {
38          TestSuite suite = new TestSuite(AbstractUnivariateStatisticTest.class);
39          suite.setName("AbstractUnivariateStatistic Tests");
40          return suite;
41      }
42      
43      protected double[] testArray = {0, 1, 2, 3, 4, 5};
44      protected double[] nullArray = null;
45      protected double[] singletonArray = {0};
46      protected Mean testStatistic = new Mean();
47      
48      public void testTestPositive() {
49          for (int j = 0; j < 6; j++) {
50              for (int i = 1; i < (7 - j); i++) {
51                  assertTrue(testStatistic.test(testArray, 0, i));
52              }  
53          }
54          assertTrue(testStatistic.test(singletonArray, 0, 1));
55      }
56      
57      public void testTestNegative() {
58          assertFalse(testStatistic.test(singletonArray, 0, 0));
59          assertFalse(testStatistic.test(testArray, 0, 0));
60          try {
61              testStatistic.test(singletonArray, 2, 1);  // start past end
62              fail("Expecting IllegalArgumentException");
63          } catch (IllegalArgumentException ex) {
64              // expected
65          }
66          try {
67              testStatistic.test(testArray, 0, 7);  // end past end
68              fail("Expecting IllegalArgumentException");
69          } catch (IllegalArgumentException ex) {
70              // expected
71          }
72          try {
73              testStatistic.test(testArray, -1, 1);  // start negative
74              fail("Expecting IllegalArgumentException");
75          } catch (IllegalArgumentException ex) {
76              // expected
77          }
78          try {
79              testStatistic.test(testArray, 0, -1);  // length negative
80              fail("Expecting IllegalArgumentException");
81          } catch (IllegalArgumentException ex) {
82              // expected
83          }
84          try {
85              testStatistic.test(nullArray, 0, 1);  // null array
86              fail("Expecting IllegalArgumentException");
87          } catch (IllegalArgumentException ex) {
88              // expected
89          }      
90      } 
91  }