From ed9b7a6dd4097f964f0fd3a824276db5fdb3fb3b Mon Sep 17 00:00:00 2001 From: levisyin Date: Fri, 24 May 2024 12:17:47 +0800 Subject: [PATCH] chore: add test for `sample.Sum` --- metrics/sample_test.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/metrics/sample_test.go b/metrics/sample_test.go index 29f3f0a363..14e8431620 100644 --- a/metrics/sample_test.go +++ b/metrics/sample_test.go @@ -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) }