summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/beorn7/perks/histogram/histogram_test.go
blob: 0575ebeee5a9adf0f1f0ab095fef37dda4dd5dcf (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
30
31
32
33
34
35
36
37
38
package histogram

import (
	"math/rand"
	"testing"
)

func TestHistogram(t *testing.T) {
	const numPoints = 1e6
	const maxBins = 3

	h := New(maxBins)
	for i := 0; i < numPoints; i++ {
		f := rand.ExpFloat64()
		h.Insert(f)
	}

	bins := h.Bins()
	if g := len(bins); g > maxBins {
		t.Fatalf("got %d bins, wanted <= %d", g, maxBins)
	}

	for _, b := range bins {
		t.Logf("%+v", b)
	}

	if g := count(h.Bins()); g != numPoints {
		t.Fatalf("binned %d points, wanted %d", g, numPoints)
	}
}

func count(bins Bins) int {
	binCounts := 0
	for _, b := range bins {
		binCounts += b.Count
	}
	return binCounts
}