01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy 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,
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: */
18:
19: package org.apache.jorphan.math;
20:
21: import junit.framework.TestCase;
22:
23: public class TestStatCalculator extends TestCase {
24:
25: StatCalculator calc;
26:
27: /**
28: *
29: */
30: public TestStatCalculator() {
31: super ();
32: }
33:
34: /**
35: * @param arg0
36: */
37: public TestStatCalculator(String arg0) {
38: super (arg0);
39: }
40:
41: public void setUp() {
42: calc = new StatCalculator();
43: }
44:
45: public void testPercentagePoint() throws Exception {
46: calc.addValue(10);
47: calc.addValue(9);
48: calc.addValue(5);
49: calc.addValue(6);
50: calc.addValue(1);
51: calc.addValue(3);
52: calc.addValue(8);
53: calc.addValue(2);
54: calc.addValue(7);
55: calc.addValue(4);
56: assertEquals(10, calc.getCount());
57: assertEquals(9, calc.getPercentPoint(0.8999999).intValue());
58: }
59:
60: public void testCalculation() {
61: calc.addValue(18);
62: calc.addValue(10);
63: calc.addValue(9);
64: calc.addValue(11);
65: calc.addValue(28);
66: calc.addValue(3);
67: calc.addValue(30);
68: calc.addValue(15);
69: calc.addValue(15);
70: calc.addValue(21);
71: assertEquals(16, (int) calc.getMean());
72: assertEquals(8.0622577F, (float) calc.getStandardDeviation(),
73: 0F);
74: assertEquals(30, calc.getMax().intValue());
75: assertEquals(3, calc.getMin().intValue());
76: assertEquals(15, calc.getMedian().intValue());
77: }
78: }
|