1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
27
28
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);
61 fail("Expecting IllegalArgumentException");
62 } catch (IllegalArgumentException ex) {
63
64 }
65 try {
66 testStatistic.test(testArray, 0, 7);
67 fail("Expecting IllegalArgumentException");
68 } catch (IllegalArgumentException ex) {
69
70 }
71 try {
72 testStatistic.test(testArray, -1, 1);
73 fail("Expecting IllegalArgumentException");
74 } catch (IllegalArgumentException ex) {
75
76 }
77 try {
78 testStatistic.test(testArray, 0, -1);
79 fail("Expecting IllegalArgumentException");
80 } catch (IllegalArgumentException ex) {
81
82 }
83 try {
84 testStatistic.test(nullArray, 0, 1);
85 fail("Expecting IllegalArgumentException");
86 } catch (IllegalArgumentException ex) {
87
88 }
89 }
90 }