BUG FIXED: RoundRobinCounter.Add will cause a out of range crash

when index >= len(rrc.Values)
This commit is contained in:
yanyiwu
2015-04-20 22:05:20 +08:00
parent c65b9588e2
commit eaad4fa3c4
2 changed files with 23 additions and 7 deletions

View File

@@ -0,0 +1,19 @@
package stats
import "testing"
func TestRobinCounter(t *testing.T) {
rrc := NewRoundRobinCounter(60)
rrc.Add(0, 1)
rrc.Add(50, 2)
if rrc.Count() != 2 {
t.Fatal()
}
if rrc.Sum() != 3 {
t.Fatal()
}
/*
index out of range
*/
rrc.Add(61, 1)
}