summaryrefslogtreecommitdiffhomepage
path: root/prober/histogram_test.go
blob: 2c7deea354a89ee798adefc250fb915346cf750d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Copyright (c) Tailscale Inc & contributors
// SPDX-License-Identifier: BSD-3-Clause

package prober

import (
	"testing"

	"github.com/google/go-cmp/cmp"
)

func TestHistogram(t *testing.T) {
	h := newHistogram([]float64{1, 2})
	h.add(0.5)
	h.add(1)
	h.add(1.5)
	h.add(2)
	h.add(2.5)

	if diff := cmp.Diff(h.count, uint64(5)); diff != "" {
		t.Errorf("wrong count; (-got+want):%v", diff)
	}
	if diff := cmp.Diff(h.sum, 7.5); diff != "" {
		t.Errorf("wrong sum; (-got+want):%v", diff)
	}
	if diff := cmp.Diff(h.bucketedCounts, map[float64]uint64{1: 2, 2: 4}); diff != "" {
		t.Errorf("wrong bucketedCounts; (-got+want):%v", diff)
	}
}