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 ProductTest extends StorelessUnivariateStatisticAbstractTest {
35
36 @Override
37 public Product getUnivariateStatistic() {
38 return new Product();
39 }
40
41 @Override
42 public double getTolerance() {
43 return 10E8;
44 }
45
46 @Override
47 public double expectedValue() {
48 return this.product;
49 }
50
51
52 public double expectedWeightedValue() {
53 return this.weightedProduct;
54 }
55
56 @Test
57 public void testSpecialValues() {
58 Product product = getUnivariateStatistic();
59 assertEquals(1, product.getResult(), 0);
60 product.increment(1);
61 assertEquals(1, product.getResult(), 0);
62 product.increment(Double.POSITIVE_INFINITY);
63 assertEquals(Double.POSITIVE_INFINITY, product.getResult(), 0);
64 product.increment(Double.NEGATIVE_INFINITY);
65 assertEquals(Double.NEGATIVE_INFINITY, product.getResult(), 0);
66 product.increment(Double.NaN);
67 assertTrue(Double.isNaN(product.getResult()));
68 product.increment(1);
69 assertTrue(Double.isNaN(product.getResult()));
70 }
71
72 @Test
73 public void testWeightedProduct() {
74 Product product = new Product();
75 assertEquals(expectedWeightedValue(),
76 product.evaluate(testArray, testWeightsArray, 0, testArray.length),getTolerance());
77 assertEquals(expectedValue(),
78 product.evaluate(testArray, unitWeightsArray, 0, testArray.length), getTolerance());
79 }
80
81 @Override
82 protected void checkClearValue(StorelessUnivariateStatistic statistic){
83 assertEquals(1, statistic.getResult(), 0);
84 }
85
86 }