File: histogram_test.go

package info (click to toggle)
golang-github-beorn7-perks 0.0~git20160804.0.4c0e845-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, buster-backports, buster-backports-sloppy, stretch, stretch-backports
  • size: 108 kB
  • sloc: makefile: 3
file content (38 lines) | stat: -rw-r--r-- 607 bytes parent folder | download | duplicates (2)
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
}