1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.math4.legacy.stat.descriptive.summary;
18
19 import org.apache.commons.math4.legacy.stat.descriptive.StorelessUnivariateStatistic;
20 import org.apache.commons.math4.legacy.stat.descriptive.StorelessUnivariateStatisticAbstractTest;
21 import org.apache.commons.math4.legacy.stat.descriptive.UnivariateStatistic;
22 import org.junit.Assert;
23 import org.junit.Test;
24
25
26
27
28 public class ProductTest extends StorelessUnivariateStatisticAbstractTest{
29
30 protected Product stat;
31
32
33
34
35 @Override
36 public UnivariateStatistic getUnivariateStatistic() {
37 return new Product();
38 }
39
40
41
42
43 @Override
44 public double getTolerance() {
45 return 10E8;
46 }
47
48
49
50
51 @Override
52 public double expectedValue() {
53 return this.product;
54 }
55
56
57 public double expectedWeightedValue() {
58 return this.weightedProduct;
59 }
60
61 @Test
62 public void testSpecialValues() {
63 Product product = new Product();
64 Assert.assertEquals(1, product.getResult(), 0);
65 product.increment(1);
66 Assert.assertEquals(1, product.getResult(), 0);
67 product.increment(Double.POSITIVE_INFINITY);
68 Assert.assertEquals(Double.POSITIVE_INFINITY, product.getResult(), 0);
69 product.increment(Double.NEGATIVE_INFINITY);
70 Assert.assertEquals(Double.NEGATIVE_INFINITY, product.getResult(), 0);
71 product.increment(Double.NaN);
72 Assert.assertTrue(Double.isNaN(product.getResult()));
73 product.increment(1);
74 Assert.assertTrue(Double.isNaN(product.getResult()));
75 }
76
77 @Test
78 public void testWeightedProduct() {
79 Product product = new Product();
80 Assert.assertEquals(expectedWeightedValue(),
81 product.evaluate(testArray, testWeightsArray, 0, testArray.length),getTolerance());
82 Assert.assertEquals(expectedValue(),
83 product.evaluate(testArray, unitWeightsArray, 0, testArray.length), getTolerance());
84 }
85
86 @Override
87 protected void checkClearValue(StorelessUnivariateStatistic statistic){
88 Assert.assertEquals(1, statistic.getResult(), 0);
89 }
90 }