use of com.twitter.common.stats.ApproximateHistogram in project commons by twitter.
the class ApproximateHistogramTest method testIsBufferEmpty.
@Test
public void testIsBufferEmpty() {
ApproximateHistogram hist = new ApproximateHistogram(b, h);
for (int i = 0; i < 3 * b; i++) {
hist.add(i);
}
assertEquals(false, hist.isBufferEmpty(2));
assertEquals(true, hist.isBufferEmpty(3));
for (int i = 0; i < 2 * b; i++) {
hist.add(i);
}
assertEquals(true, hist.isBufferEmpty(2));
assertEquals(false, hist.isBufferEmpty(3));
}
use of com.twitter.common.stats.ApproximateHistogram in project commons by twitter.
the class ApproximateHistogramTest method testBiggestIndexFinder.
@Test
public void testBiggestIndexFinder() {
ApproximateHistogram hist = new ApproximateHistogram(b, h);
int n = 3;
for (int i = 1; i <= n; i++) {
hist.add(i);
}
initIndexArray(hist, b);
for (int i = 1; i <= n; i++) {
assertEquals(n - i + 1, getBiggest(hist));
}
n = 2 * b;
for (int i = 4; i <= n; i++) {
hist.add(i);
}
initIndexArray(hist, b);
for (int i = 1; i <= n; i++) {
assertEquals(n - i + 1, getBiggest(hist));
}
hist.add(2 * b + 1);
n += 1;
initIndexArray(hist, b);
assertEquals(n, getBiggest(hist));
for (int i = 2; i <= n; i += 2) {
assertEquals(n - i + 1, getBiggest(hist));
}
}
use of com.twitter.common.stats.ApproximateHistogram in project commons by twitter.
the class ApproximateHistogramTest method testHistogramWithNegative.
@Test
public void testHistogramWithNegative() {
ApproximateHistogram hist = new ApproximateHistogram();
hist.add(-1L);
assertEquals(-1L, hist.getQuantile(0.0));
assertEquals(-1L, hist.getQuantile(0.5));
assertEquals(-1L, hist.getQuantile(1.0));
}
Aggregations