TDigest implements Serializable { public abstract void add(double x, int w);  @SuppressWarnings("WeakerAccess") static TDigest createMergingDigest(double compression); @SuppressWarnings("WeakerAccess") static TDigest createAvlTreeDigest(double compression); @SuppressWarnings({"unused", "WeakerAccess", "SameParameterValue"}) static TDigest createDigest(double compression); abstract void add(double x, int w); abstract void add(List<? extends TDigest> others); abstract void compress(); abstract long size(); abstract double cdf(double x); abstract double quantile(double q); abstract Collection<Centroid> centroids(); abstract double compression(); abstract int byteSize(); abstract int smallByteSize(); void setScaleFunction(ScaleFunction scaleFunction); abstract void asBytes(ByteBuffer buf); abstract void asSmallBytes(ByteBuffer buf); abstract TDigest recordAllData(); abstract boolean isRecording(); abstract void add(double x); abstract void add(TDigest other); abstract int centroidCount(); double getMin(); double getMax();  }
@Test public void testIntEncoding() { Random gen = getRandom(); ByteBuffer buf = ByteBuffer.allocate(10000); List<Integer> ref = Lists.newArrayList(); for (int i = 0; i < 3000; i++) { int n = gen.nextInt(); n = n >>> (i / 100); ref.add(n); AbstractTDigest.encode(buf, n); } buf.flip(); for (int i = 0; i < 3000; i++) { int n = AbstractTDigest.decode(buf); assertEquals(String.format("%d:", i), ref.get(i).intValue(), n); } }
@Test public void testNaN() { final TDigest digest = factory().create(); Random gen = getRandom(); final int iters = gen.nextInt(100); for (int i = 0; i < iters; ++i) { digest.add(gen.nextDouble(), 1 + gen.nextInt(10)); } try { if (gen.nextBoolean()) { digest.add(Double.NaN); } else { digest.add(Double.NaN, 1); } fail("NaN should be an illegal argument"); } catch (IllegalArgumentException e) { } }