mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
chore: add test case for SampleSnapshot.Sum
This commit is contained in:
parent
61b3d93bb0
commit
cc792610f4
1 changed files with 8 additions and 3 deletions
|
|
@ -103,20 +103,25 @@ func TestExpDecaySample(t *testing.T) {
|
|||
}
|
||||
snap := sample.Snapshot()
|
||||
if have, want := int(snap.Count()), tc.updates; have != want {
|
||||
t.Errorf("have %d want %d", have, want)
|
||||
t.Errorf("unexpected count: have %d want %d", have, want)
|
||||
}
|
||||
if have, want := snap.Size(), min(tc.updates, tc.reservoirSize); have != want {
|
||||
t.Errorf("have %d want %d", have, want)
|
||||
t.Errorf("unexpected size: have %d want %d", have, want)
|
||||
}
|
||||
values := snap.(*sampleSnapshot).values
|
||||
if have, want := len(values), min(tc.updates, tc.reservoirSize); have != want {
|
||||
t.Errorf("have %d want %d", 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue