1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.hipparchus.stat.descriptive.moment;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertTrue;
26
27 import org.hipparchus.stat.descriptive.StorelessUnivariateStatisticAbstractTest;
28 import org.junit.Test;
29
30
31
32
33 public class MeanTest extends StorelessUnivariateStatisticAbstractTest{
34
35 @Override
36 public Mean getUnivariateStatistic() {
37 return new Mean();
38 }
39
40 @Override
41 public double expectedValue() {
42 return this.mean;
43 }
44
45
46 public double expectedWeightedValue() {
47 return this.weightedMean;
48 }
49
50 @Test
51 public void testSmallSamples() {
52 Mean mean = getUnivariateStatistic();
53 assertTrue(Double.isNaN(mean.getResult()));
54 mean.increment(1d);
55 assertEquals(1d, mean.getResult(), 0);
56 }
57
58 @Test
59 public void testWeightedMean() {
60 Mean mean = getUnivariateStatistic();
61 assertEquals(expectedWeightedValue(),
62 mean.evaluate(testArray, testWeightsArray, 0, testArray.length),
63 getTolerance());
64 assertEquals(expectedValue(),
65 mean.evaluate(testArray, identicalWeightsArray, 0, testArray.length),
66 getTolerance());
67 }
68
69 }