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;
18  
19  
20  import java.util.Locale;
21  
22  import org.apache.commons.math4.legacy.TestUtils;
23  import org.junit.Assert;
24  import org.junit.Test;
25  
26  
27  
28  
29  
30  public final class StatisticalSummaryValuesTest {
31  
32      @Test
33      public void testEqualsAndHashCode() {
34          StatisticalSummaryValues u  = new StatisticalSummaryValues(1, 2, 3, 4, 5, 6);
35          StatisticalSummaryValues t = null;
36          Assert.assertEquals("reflexive", u, u);
37          Assert.assertNotEquals("non-null compared to null", u, t);
38          Assert.assertFalse("wrong type", u.equals(Double.valueOf(0)));
39          t = new StatisticalSummaryValues(1, 2, 3, 4, 5, 6);
40          Assert.assertEquals("instances with same data should be equal", t, u);
41          Assert.assertEquals("hash code", u.hashCode(), t.hashCode());
42  
43          u = new StatisticalSummaryValues(Double.NaN, 2, 3, 4, 5, 6);
44          t = new StatisticalSummaryValues(1, Double.NaN, 3, 4, 5, 6);
45          Assert.assertFalse("instances based on different data should be different",
46                  u.equals(t) ||t.equals(u));
47      }
48  
49      private void verifyEquality(StatisticalSummaryValues s, StatisticalSummaryValues u) {
50          Assert.assertEquals("N",s.getN(),u.getN());
51          TestUtils.assertEquals("sum",s.getSum(),u.getSum(), 0);
52          TestUtils.assertEquals("var",s.getVariance(),u.getVariance(), 0);
53          TestUtils.assertEquals("std",s.getStandardDeviation(),u.getStandardDeviation(), 0);
54          TestUtils.assertEquals("mean",s.getMean(),u.getMean(), 0);
55          TestUtils.assertEquals("min",s.getMin(),u.getMin(), 0);
56          TestUtils.assertEquals("max",s.getMax(),u.getMax(), 0);
57      }
58  
59      @Test
60      public void testToString() {
61          StatisticalSummaryValues u  = new StatisticalSummaryValues(4.5, 16, 10, 5, 4, 45);
62          Locale d = Locale.getDefault();
63          Locale.setDefault(Locale.US);
64          Assert.assertEquals("StatisticalSummaryValues:\n" +
65                       "n: 10\n" +
66                       "min: 4.0\n" +
67                       "max: 5.0\n" +
68                       "mean: 4.5\n" +
69                       "std dev: 4.0\n" +
70                       "variance: 16.0\n" +
71                       "sum: 45.0\n",  u.toString());
72          Locale.setDefault(d);
73      }
74  }