### Question:
PercentileBuckets { public static double percentile(long[] counts, double p) { double[] pcts = {p}; double[] results = new double[1]; percentiles(counts, pcts, results); return results[0]; } private  PercentileBuckets(); static long[] asArray(); static T[] map(Class<T> c, Function<Long, T> f); static long get(int i); static int length(); static int indexOf(long v); static long bucket(long v); static void percentiles(long[] counts, double[] pcts, double[] results); static double percentile(long[] counts, double p);  }### Answer:
@Test public void percentile() { long[] counts = new long[PercentileBuckets.length()]; for (int i = 0; i < 100_000; ++i) { ++counts[PercentileBuckets.indexOf(i)]; } double[] pcts = new double[] {0.0, 25.0, 50.0, 75.0, 90.0, 95.0, 98.0, 99.0, 99.5, 100.0}; for (double pct : pcts) { double expected = pct * 1e3; double threshold = 0.1 * expected + 1e-12; Assertions.assertEquals(expected, PercentileBuckets.percentile(counts, pct), threshold); } }