chore: add test for sample.Sum

This commit is contained in:
levisyin 2024-05-24 12:17:47 +08:00
parent cc792610f4
commit ed9b7a6dd4

View file

@ -112,16 +112,11 @@ func TestExpDecaySample(t *testing.T) {
if have, want := len(values), min(tc.updates, tc.reservoirSize); have != want {
t.Errorf("unexpected values length: have %d want %d", have, want)
}
sum := int64(0)
for _, v := range values {
sum += v
if v > int64(tc.updates) || v < 0 {
t.Errorf("out of range [0, %d]: %v", tc.updates, v)
}
}
if have, want := snap.Sum(), sum; have != want {
t.Errorf("unexpected sum: have %d want %d", have, want)
}
}
}
@ -256,6 +251,9 @@ func benchmarkSample(b *testing.B, s Sample) {
}
func testExpDecaySampleStatistics(t *testing.T, s SampleSnapshot) {
if sum := s.Sum(); sum != 496598 {
t.Errorf("s.Sum(): 496598 != %v\n", sum)
}
if count := s.Count(); count != 10000 {
t.Errorf("s.Count(): 10000 != %v\n", count)
}