Codebase list golang-github-beorn7-perks / 32e80b9
Expose bug for small samples beorn7 7 years ago
1 changed file(s) with 27 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
3232 for quantile, epsilon := range Targets {
3333 n := float64(len(a))
3434 k := int(quantile * n)
35 if k < 1 {
36 k = 1
37 }
3538 lower := int((quantile - epsilon) * n)
3639 if lower < 1 {
3740 lower = 1
98101 verifyPercsWithAbsoluteEpsilon(t, a, s)
99102 }
100103
104 func TestTargetedQuerySmallSampleSize(t *testing.T) {
105 rand.Seed(42)
106 s := NewTargeted(TargetsSmallEpsilon)
107 a := []float64{1, 2, 3, 4, 5}
108 for _, v := range a {
109 s.Insert(v)
110 }
111 verifyPercsWithAbsoluteEpsilon(t, a, s)
112 // If not yet flushed, results should be precise:
113 if !s.flushed() {
114 for φ, want := range map[float64]float64{
115 0.01: 1,
116 0.10: 1,
117 0.50: 3,
118 0.90: 5,
119 0.99: 5,
120 } {
121 if got := s.Query(φ); got != want {
122 t.Errorf("want %f for φ=%f, got %f", want, φ, got)
123 }
124 }
125 }
126 }
127
101128 func TestLowBiasedQuery(t *testing.T) {
102129 rand.Seed(42)
103130 s := NewLowBiased(RelativeEpsilon)