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.summary;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertTrue;
26
27 import org.hipparchus.stat.descriptive.StorelessUnivariateStatistic;
28 import org.hipparchus.stat.descriptive.StorelessUnivariateStatisticAbstractTest;
29 import org.junit.Test;
30
31
32
33
34 public class SumTest extends StorelessUnivariateStatisticAbstractTest {
35
36 @Override
37 public Sum getUnivariateStatistic() {
38 return new Sum();
39 }
40
41 @Override
42 public double expectedValue() {
43 return this.sum;
44 }
45
46
47 public double expectedWeightedValue() {
48 return this.weightedSum;
49 }
50
51 @Test
52 public void testSpecialValues() {
53 Sum sum = getUnivariateStatistic();
54 assertEquals(0, sum.getResult(), 0);
55 sum.increment(1);
56 assertEquals(1, sum.getResult(), 0);
57 sum.increment(Double.POSITIVE_INFINITY);
58 assertEquals(Double.POSITIVE_INFINITY, sum.getResult(), 0);
59 sum.increment(Double.NEGATIVE_INFINITY);
60 assertTrue(Double.isNaN(sum.getResult()));
61 sum.increment(1);
62 assertTrue(Double.isNaN(sum.getResult()));
63 }
64
65 @Test
66 public void testWeightedSum() {
67 Sum sum = new Sum();
68 assertEquals(expectedWeightedValue(),
69 sum.evaluate(testArray, testWeightsArray, 0, testArray.length), getTolerance());
70 assertEquals(expectedValue(),
71 sum.evaluate(testArray, unitWeightsArray, 0, testArray.length), getTolerance());
72 }
73
74 @Override
75 protected void checkClearValue(StorelessUnivariateStatistic statistic) {
76 assertEquals(0, statistic.getResult(), 0);
77 }
78
79 }