Skip to content

Commit

Permalink
Added small sample test to correspond to issue found by the addthis c…
Browse files Browse the repository at this point in the history
  • Loading branch information
tdunning committed Jul 15, 2017
1 parent 9ef5f5a commit f2f6970
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/test/java/com/tdunning/math/stats/TDigestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,44 @@ public void testSerialization() {
assertFalse(ix.hasNext());
}

/**
* Does basic sanity testing for a particular small example that used to fail.
* See https://github.com/addthis/stream-lib/issues/138
*/
@Test
public void testThreePointExample() {
TDigest tdigest = factory(100).create();
double x0 = 0.18615591526031494;
double x1 = 0.4241943657398224;
double x2 = 0.8813006281852722;

tdigest.add(x0);
tdigest.add(x1);
tdigest.add(x2);

double p10 = tdigest.quantile(0.1);
double p50 = tdigest.quantile(0.5);
double p90 = tdigest.quantile(0.9);
double p95 = tdigest.quantile(0.95);
double p99 = tdigest.quantile(0.99);

assertTrue("ordering of quantiles", p10 <= p50);
assertTrue("ordering of quantiles", p50 <= p90);
assertTrue("ordering of quantiles", p90 <= p95);
assertTrue("ordering of quantiles", p95 <= p99);

assertEquals("Extreme quantiles", x0, p10, 0);
assertEquals("Extreme quantiles", x2, p99, 0);

// System.out.println("digest: " + tdigest.getClass());
// System.out.println("p10: " + tdigest.quantile(0.1));
// System.out.println("p50: " + tdigest.quantile(0.5));
// System.out.println("p90: " + tdigest.quantile(0.9));
// System.out.println("p95: " + tdigest.quantile(0.95));
// System.out.println("p99: " + tdigest.quantile(0.99));
// System.out.println();
}

@Test
public void testIntEncoding() {
Random gen = getRandom();
Expand Down

0 comments on commit f2f6970

Please sign in to comment.