/** Test of add method, of class Statistics. */ @Test public strictfp void testAdd_double() { ListStatistics stats = new ListStatistics(); stats.addValue(VALUES[0]); assertEquals(1, stats.getN()); assertEquals(VALUES[0], stats.getSum(), 0.0); assertEquals(VALUES[0], stats.getMax(), 0.0); assertEquals(VALUES[0], stats.getMin(), 0.0); assertEquals(VALUES[0], stats.getMean(), 0.0); assertEquals(Double.NaN, stats.getVariance(), 0.0); assertEquals(Double.NaN, stats.getStandardDeviation(), 0.0); }
/** Test of toString, of class Statistics */ @Test public strictfp void testToString() { String expResult = "N:25 Mean: 51.03316951740001 Min: 2.34517545 Max: 96.66786311 StdDev: 28.582874479178013"; String result = instance.toString(); assertEquals(expResult, result); }
@Test public strictfp void testSignificant_Never() { ListStatistics s1 = new ListStatistics(); ListStatistics s2 = new ListStatistics(); for (int c = 0; c < 10; c++) { s1.addValue(1); s1.addValue(1.1); s2.addValue(1); s2.addValue(1.1); } for (double conf : new double[] {0.5, 0.9, 0.99, 0.999, 0.9999, 0.99999}) { Assert.assertFalse("Diff not significant at " + conf, s1.isDifferent(s2, conf)); Assert.assertEquals(0, s1.compareTo(s2, conf)); } }
/** Test of getMax method, of class Statistics. */ @Test public strictfp void testGetMax() { assertEquals(96.66786311, instance.getMax(), 0.0); }
/** Test of getMean method, of class Statistics. */ @Test public strictfp void testGetMean() { assertEquals(51.033, instance.getMean(), 0.001); }
/** Test of getSum method, of class Statistics. */ @Test public strictfp void testGetSum() { assertEquals(1275.829, instance.getSum(), 0.001); }
/** Test of getN method, of class Statistics. */ @Test public strictfp void testGetN() { assertEquals((long) VALUES.length, instance.getN()); }
@BeforeClass public static void setUpClass() throws Exception { for (double value : VALUES) { instance.addValue(value); } }
/** Test of getConfidenceIntervalAt, of class Statistics */ @Test public strictfp void testGetConfidenceInterval() { double[] interval = instance.getConfidenceIntervalAt(0.999); assertEquals(29.62232, interval[0], 0.002); assertEquals(72.44402, interval[1], 0.002); }
@Test public strictfp void testSignificant_Sometimes() { ListStatistics s1 = new ListStatistics(); ListStatistics s2 = new ListStatistics(); for (int c = 0; c < 10; c++) { s1.addValue(1); s1.addValue(2); s2.addValue(1); s2.addValue(3); } Assert.assertTrue("Diff significant at 0.5", s1.isDifferent(s2, 0.5)); Assert.assertTrue("Diff significant at 0.9", s1.isDifferent(s2, 0.9)); Assert.assertFalse("Diff not significant at 0.99", s1.isDifferent(s2, 0.99)); Assert.assertFalse("Diff not significant at 0.999", s1.isDifferent(s2, 0.999)); Assert.assertFalse("Diff not significant at 0.9999", s1.isDifferent(s2, 0.9999)); Assert.assertEquals("compareTo at 0.5", 1, s1.compareTo(s2, 0.5)); Assert.assertEquals("compareTo at 0.9", 1, s1.compareTo(s2, 0.9)); Assert.assertEquals("compareTo at 0.99", 0, s1.compareTo(s2, 0.99)); Assert.assertEquals("compareTo at 0.999", 0, s1.compareTo(s2, 0.999)); Assert.assertEquals("compareTo at 0.9999", 0, s1.compareTo(s2, 0.9999)); }
@Test public strictfp void testPercentile_100() { assertEquals(96.667, instance.getPercentile(100), 0.002); }
@Test public strictfp void testPercentile_90() { assertEquals(93.044, instance.getPercentile(90), 0.002); }
@Test public strictfp void testPercentile_50() { assertEquals(56.460, instance.getPercentile(50), 0.002); }
@Test public strictfp void testPercentile_00() { assertEquals(2.345, instance.getPercentile(0), 0.002); }
/** Test of getMin method, of class Statistics. */ @Test public strictfp void testGetMin() { assertEquals(2.34517545, instance.getMin(), 0.0); }
@Test public strictfp void testSingle() { ListStatistics s = new ListStatistics(); s.addValue(42.0D); Assert.assertEquals(1, s.getN()); Assert.assertEquals(42.0D, s.getSum()); Assert.assertEquals(42.0D, s.getMin()); Assert.assertEquals(42.0D, s.getMax()); Assert.assertEquals(42.0D, s.getMean()); Assert.assertEquals(Double.NaN, s.getMeanErrorAt(0.5)); Assert.assertEquals(Double.NaN, s.getVariance()); Assert.assertEquals(Double.NaN, s.getStandardDeviation()); Assert.assertEquals(Double.NaN, s.getConfidenceIntervalAt(0.50)[0]); Assert.assertEquals(Double.NaN, s.getConfidenceIntervalAt(0.50)[1]); Assert.assertEquals(42.0D, s.getPercentile(0)); Assert.assertEquals(42.0D, s.getPercentile(100)); }
/** Test of getVariance method, of class Statistics. */ @Test public strictfp void testGetVariance() { assertEquals(816.9807, instance.getVariance(), 0.0001); }
/** Test of getStandardDeviation method, of class Statistics. */ @Test public strictfp void testGetStandardDeviation() { assertEquals(28.5828, instance.getStandardDeviation(), 0.0001); }