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 org.hipparchus.stat.descriptive.StorelessUnivariateStatisticAbstractTest;
25 import org.junit.Assert;
26 import org.junit.Test;
27
28
29
30
31 public class GeometricMeanTest extends StorelessUnivariateStatisticAbstractTest{
32
33 @Override
34 public GeometricMean getUnivariateStatistic() {
35 return new GeometricMean();
36 }
37
38 @Override
39 public double expectedValue() {
40 return this.geoMean;
41 }
42
43 @Test
44 public void testSpecialValues() {
45 GeometricMean mean = getUnivariateStatistic();
46
47 Assert.assertTrue(Double.isNaN(mean.getResult()));
48
49
50 mean.increment(1d);
51 Assert.assertFalse(Double.isNaN(mean.getResult()));
52
53
54 mean.increment(0d);
55 Assert.assertEquals(0d, mean.getResult(), 0);
56
57
58 mean.increment(Double.POSITIVE_INFINITY);
59 Assert.assertTrue(Double.isNaN(mean.getResult()));
60
61
62 mean.clear();
63 Assert.assertTrue(Double.isNaN(mean.getResult()));
64
65
66 mean.increment(Double.POSITIVE_INFINITY);
67 Assert.assertEquals(Double.POSITIVE_INFINITY, mean.getResult(), 0);
68
69
70 mean.increment(-2d);
71 Assert.assertTrue(Double.isNaN(mean.getResult()));
72 }
73
74 }