Codebase list golang-github-beorn7-perks / upstream/0.0_git20160804.0.4c0e845
New upstream version 0.0~git20160804.0.4c0e845 Martín Ferrari 7 years ago
4 changed file(s) with 50 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
0 *.test
1 *.prof
0 Copyright (C) 2013 Blake Mizerany
1
2 Permission is hereby granted, free of charge, to any person obtaining
3 a copy of this software and associated documentation files (the
4 "Software"), to deal in the Software without restriction, including
5 without limitation the rights to use, copy, modify, merge, publish,
6 distribute, sublicense, and/or sell copies of the Software, and to
7 permit persons to whom the Software is furnished to do so, subject to
8 the following conditions:
9
10 The above copyright notice and this permission notice shall be
11 included in all copies or substantial portions of the Software.
12
13 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
15 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
17 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
19 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
132132 if l == 0 {
133133 return 0
134134 }
135 i := int(float64(l) * q)
135 i := int(math.Ceil(float64(l) * q))
136136 if i > 0 {
137137 i -= 1
138138 }
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)