Binning { int getInsertionPoint(double value) { int i = Collections.binarySearch(percentiles, value); if (i >= 0) { return i; } return -i - 2; }  Binning addPercentile(double percentile); Binning finishBuild(); double roundToPercentile(double value); int getNumberOfValuesBetween(double from, double to);  }
@Test public void testGetInsertionPoint() throws Exception { Binning binning = new Binning(); for (int i = 0; i < 100; i++) { binning.addPercentile(i * 0.1); } binning.finishBuild(); for (int i = 0; i < 100; i++) { assertEquals(i, binning.getInsertionPoint(i * 0.1)); assertEquals(i, binning.getInsertionPoint(i * 0.1 + 0.005)); } }