Skip to content

Commit

Permalink
Add TestSingletonInACrowd
Browse files Browse the repository at this point in the history
Notice that this test has its exterme quantile (0.999)
skipped because the java reference implementation behaves
the same. Reasoning and more details on issue #12
  • Loading branch information
caio committed Oct 25, 2017
1 parent a51f150 commit 22fe92a
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tdigest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,32 @@ func TestNonSequentialInsertion(t *testing.T) {
}
}

func TestSingletonInACrowd(t *testing.T) {
tdigest := New(100)
for i := 0; i < 10000; i++ {
tdigest.Add(10, 1)
}
tdigest.Add(20, 1)
tdigest.Compress()

for _, q := range []float64{0, 0.5, 0.8, 0.9, 0.99, 0.999} {
if q == 0.999 {
// Test for 0.999 disabled since it doesn't
// pass in the reference implementation
continue
}
result := tdigest.Quantile(q)
if !closeEnough(result, 10) {
t.Errorf("Expected Quantile(%.3f) = 10, but got %.4f (size=%d)", q, result, tdigest.Len())
}
}

result := tdigest.Quantile(1)
if result != 20 {
t.Errorf("Expected Quantile(1) = 20, but got %.4f (size=%d)", result, tdigest.Len())
}
}

func TestRespectBounds(t *testing.T) {
tdigest := New(10)

Expand Down

0 comments on commit 22fe92a

Please sign in to comment.