configBuilder.setBucketsMax(11);
configBuilder.setDropNum(1);
HistogramBasedIntStats.StaticConfig config = configBuilder.build();
HistogramBasedIntStats stats = new HistogramBasedIntStats(config);
HistogramBasedIntStats.Stats s = new HistogramBasedIntStats.Stats();
//just add some data points less than the capacity and very statistics
for (int i = 1; i <= 10; ++i)
{
stats.add(1);
Assert.assertEquals(stats.size(), i, "correct size");
}
stats.calcStats(s);
Assert.assertEquals(s.getMax(), 1, "correct max");
Assert.assertEquals(s.getMin(), 1, "correct min");
Assert.assertEquals(s.getNum(), 10, "correct num");
Assert.assertEquals(s.getSum(), 10, "correct sum");
Assert.assertEquals(s.getMean(), 1.0, "correct mean");
Assert.assertEquals(s.getMedian(), 1, "correct median");
Assert.assertEquals(s.getStdDev(), 0.0, "correct stdDev");
//add more data points so that we push the previous ones out completely
for (int i = 1; i <= 20; ++i)
{
stats.add(5);
Assert.assertEquals(stats.size(), i <= 10 ? 10 + i : 20, "correct size" );
}
stats.calcStats(s);
Assert.assertEquals(s.getMax(), 5, "correct max");
Assert.assertEquals(s.getMin(), 5, "correct min");
Assert.assertEquals(s.getNum(), 20, "correct num");
Assert.assertEquals(s.getSum(), 100, "correct sum");
Assert.assertEquals(s.getMean(), 5.0, "correct mean");
Assert.assertEquals(s.getMedian(), 5, "correct median");
Assert.assertEquals(s.getStdDev(), 0.0, "correct stdDev");
//add a few more data points to test a mixture of different values
for (int i = 1; i <= 8; ++i)
{
stats.add(3);
Assert.assertEquals(stats.size(), 20, "correct size");
}
stats.calcStats(s);
Assert.assertEquals(s.getMax(), 5, "correct max");
Assert.assertEquals(s.getMin(), 3, "correct min");
Assert.assertEquals(s.getNum(), 20, "correct num");
Assert.assertEquals(s.getSum(), 84, "correct sum");
Assert.assertEquals(s.getMean(), 84.0/20, "correct mean");
Assert.assertEquals(s.getMedian(), 5, "correct median");
Assert.assertEquals(s.getPerc75(), 5, "correct 75 percentile");
Assert.assertEquals(s.getPerc99(), 5, "correct 99 percentile");
Assert.assertTrue(s.getStdDev() > 0.0, "correct stdDev");
//add a few more data points to test a mixture of different values
for (int i = 1; i <= 4; ++i)
{
stats.add(3);
Assert.assertEquals(stats.size(), 20, "correct size");
}
stats.calcStats(s);
Assert.assertEquals(s.getMax(), 5, "correct max");
Assert.assertEquals(s.getMin(), 3, "correct min");
Assert.assertEquals(s.getNum(), 20, "correct num");
Assert.assertEquals(s.getSum(), 76, "correct sum");
Assert.assertEquals(s.getMean(), 76.0/20, "correct mean");
Assert.assertEquals(s.getMedian(), 3, "correct median");
Assert.assertEquals(s.getPerc75(), 5, "correct 75 percentile");
Assert.assertEquals(s.getPerc95(), 5, "correct 95 percentile");
Assert.assertTrue(s.getStdDev() > 0.0, "correct stdDev");
//add a few more data points to test a mixture of different values
for (int i = 1; i <= 4; ++i)
{
stats.add(3);
Assert.assertEquals(stats.size(), 20, "correct size");
}
stats.calcStats(s);
Assert.assertEquals(s.getMax(), 5, "correct max");
Assert.assertEquals(s.getMin(), 3, "correct min");
Assert.assertEquals(s.getNum(), 20, "correct num");
Assert.assertEquals(s.getSum(), 68, "correct sum");
Assert.assertEquals(s.getMean(), 68.0/20, "correct mean");
Assert.assertEquals(s.getMedian(), 3, "correct median");
Assert.assertEquals(s.getPerc75(), 3, "correct 75 percentile");
Assert.assertEquals(s.getPerc90(), 5, "correct 90 percentile");
Assert.assertTrue(s.getStdDev() > 0.0, "correct stdDev");
//add a few more data points to test a mixture of different values
for (int i = 1; i <= 4; ++i)
{
stats.add(1);
Assert.assertEquals(stats.size(), 20, "correct size");
}
stats.calcStats(s);
Assert.assertEquals(s.getMax(), 3, "correct max");
Assert.assertEquals(s.getMin(), 1, "correct min");
Assert.assertEquals(s.getNum(), 20, "correct num");
Assert.assertEquals(s.getSum(), 4*1 + 16*3, "correct sum");
Assert.assertEquals(s.getMean(), s.getSum()/20.0, "correct mean");