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.assertTrue;
25
26 import org.hipparchus.stat.descriptive.StorelessUnivariateStatisticAbstractTest;
27 import org.junit.Test;
28
29
30
31
32 public class FirstMomentTest extends StorelessUnivariateStatisticAbstractTest {
33
34 @Override
35 public FirstMoment getUnivariateStatistic() {
36 return new FirstMoment();
37 }
38
39 @Override
40 public double expectedValue() {
41 return this.mean;
42 }
43
44 @Test
45 public void testSpecialValues() {
46 final FirstMoment mean = new FirstMoment();
47
48 mean.clear();
49 mean.increment(Double.POSITIVE_INFINITY);
50 mean.increment(1d);
51 assertTrue(Double.isNaN(mean.getResult()));
52
53 mean.clear();
54 mean.increment(Double.POSITIVE_INFINITY);
55 mean.increment(-1d);
56 assertTrue(Double.isNaN(mean.getResult()));
57
58 mean.clear();
59 mean.increment(Double.NEGATIVE_INFINITY);
60 mean.increment(1d);
61 assertTrue(Double.isNaN(mean.getResult()));
62
63 mean.clear();
64 mean.increment(Double.NEGATIVE_INFINITY);
65 mean.increment(-1d);
66 assertTrue(Double.isNaN(mean.getResult()));
67
68 mean.clear();
69 mean.increment(Double.POSITIVE_INFINITY);
70 mean.increment(Double.POSITIVE_INFINITY);
71 assertTrue(Double.isNaN(mean.getResult()));
72
73 mean.clear();
74 mean.increment(Double.NEGATIVE_INFINITY);
75 mean.increment(Double.NEGATIVE_INFINITY);
76 assertTrue(Double.isNaN(mean.getResult()));
77
78 mean.clear();
79 mean.increment(Double.POSITIVE_INFINITY);
80 mean.increment(Double.NEGATIVE_INFINITY);
81 assertTrue(Double.isNaN(mean.getResult()));
82
83 mean.clear();
84 mean.increment(Double.NEGATIVE_INFINITY);
85 mean.increment(Double.POSITIVE_INFINITY);
86 assertTrue(Double.isNaN(mean.getResult()));
87
88 mean.clear();
89 mean.increment(Double.NaN);
90 mean.increment(Double.POSITIVE_INFINITY);
91 assertTrue(Double.isNaN(mean.getResult()));
92
93 mean.clear();
94 mean.increment(Double.NaN);
95 mean.increment(Double.NEGATIVE_INFINITY);
96 assertTrue(Double.isNaN(mean.getResult()));
97
98 mean.clear();
99 mean.increment(Double.NaN);
100 mean.increment(0d);
101 assertTrue(Double.isNaN(mean.getResult()));
102 }
103 }