01: /*
02: *
03: * Copyright (c) 2004 The Apache Software Foundation. All rights reserved.
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
06: * use this file except in compliance with the License. You may obtain a copy
07: * of the License at
08: *
09: * 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(
39: AbstractUnivariateStatisticTest.class);
40: suite.setName("AbstractUnivariateStatistic Tests");
41: return suite;
42: }
43:
44: protected double[] testArray = { 0, 1, 2, 3, 4, 5 };
45: protected double[] nullArray = null;
46: protected double[] singletonArray = { 0 };
47: protected Mean testStatistic = new Mean();
48:
49: public void testTestPositive() {
50: for (int j = 0; j < 6; j++) {
51: for (int i = 1; i < (7 - j); i++) {
52: assertTrue(testStatistic.test(testArray, 0, i));
53: }
54: }
55: assertTrue(testStatistic.test(singletonArray, 0, 1));
56: }
57:
58: public void testTestNegative() {
59: assertFalse(testStatistic.test(singletonArray, 0, 0));
60: assertFalse(testStatistic.test(testArray, 0, 0));
61: try {
62: testStatistic.test(singletonArray, 2, 1); // start past end
63: fail("Expecting IllegalArgumentException");
64: } catch (IllegalArgumentException ex) {
65: // expected
66: }
67: try {
68: testStatistic.test(testArray, 0, 7); // end past end
69: fail("Expecting IllegalArgumentException");
70: } catch (IllegalArgumentException ex) {
71: // expected
72: }
73: try {
74: testStatistic.test(testArray, -1, 1); // start negative
75: fail("Expecting IllegalArgumentException");
76: } catch (IllegalArgumentException ex) {
77: // expected
78: }
79: try {
80: testStatistic.test(testArray, 0, -1); // length negative
81: fail("Expecting IllegalArgumentException");
82: } catch (IllegalArgumentException ex) {
83: // expected
84: }
85: try {
86: testStatistic.test(nullArray, 0, 1); // null array
87: fail("Expecting IllegalArgumentException");
88: } catch (IllegalArgumentException ex) {
89: // expected
90: }
91: }
92: }
|