Add TestSingletonInACrowd
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
- Id
- 22fe92a220493fec8e38ee2354484223c4fbcf3d
- Author
- Caio
- Commit time
- 2017-10-25T11:16:42+02:00
Modified tdigest_test.go
}
}
+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)