histogram_test.go 632 B

1234567891011121314151617181920212223242526272829
  1. // Copyright (c) Tailscale Inc & AUTHORS
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. package prober
  4. import (
  5. "testing"
  6. "github.com/google/go-cmp/cmp"
  7. )
  8. func TestHistogram(t *testing.T) {
  9. h := newHistogram([]float64{1, 2})
  10. h.add(0.5)
  11. h.add(1)
  12. h.add(1.5)
  13. h.add(2)
  14. h.add(2.5)
  15. if diff := cmp.Diff(h.count, uint64(5)); diff != "" {
  16. t.Errorf("wrong count; (-got+want):%v", diff)
  17. }
  18. if diff := cmp.Diff(h.sum, 7.5); diff != "" {
  19. t.Errorf("wrong sum; (-got+want):%v", diff)
  20. }
  21. if diff := cmp.Diff(h.bucketedCounts, map[float64]uint64{1: 2, 2: 4}); diff != "" {
  22. t.Errorf("wrong bucketedCounts; (-got+want):%v", diff)
  23. }
  24. }