fix #1 for good
Blake Mizerany
11 years ago
108 | 108 |
if s.flushed() {
|
109 | 109 |
// Fast path when there hasn't been enough data for a flush;
|
110 | 110 |
// this also yeilds better accuracy for small sets of data.
|
111 | |
i := int(float64(len(s.b)) * q)
|
|
111 |
l := len(s.b)
|
|
112 |
if l == 0 {
|
|
113 |
return 0
|
|
114 |
}
|
|
115 |
i := int(float64(l) * q)
|
112 | 116 |
if i > 0 {
|
113 | 117 |
i -= 1
|
114 | 118 |
}
|
97 | 97 |
}
|
98 | 98 |
}
|
99 | 99 |
|
|
100 |
func TestUncompressedOne(t *testing.T) {
|
|
101 |
q := NewTargeted(0.90)
|
|
102 |
q.Insert(3.14)
|
|
103 |
if g := q.Query(0.90); g != 3.14 {
|
|
104 |
t.Error("want PI, got", g)
|
|
105 |
}
|
|
106 |
}
|
|
107 |
|
|
108 |
func TestDefaults(t *testing.T) {
|
|
109 |
if g := NewTargeted(0.99).Query(0.99); g != 0 {
|
|
110 |
t.Errorf("want 0, got %f", g)
|
|
111 |
}
|
|
112 |
}
|
|
113 |
|
100 | 114 |
func getPerc(x []float64, p float64) float64 {
|
101 | 115 |
k := int(float64(len(x)) * p)
|
102 | 116 |
return x[k]
|