...
1 package histogram
2
3 import (
4 "math/rand"
5 "testing"
6 )
7
8 func TestHistogram(t *testing.T) {
9 const numPoints = 1000000
10 const maxBins = 3
11
12 h := New(maxBins)
13 for i := 0; i < numPoints; i++ {
14 f := rand.ExpFloat64()
15 h.Insert(f)
16 }
17
18 bins := h.Bins()
19 if g := len(bins); g > maxBins {
20 t.Fatalf("got %d bins, wanted <= %d", g, maxBins)
21 }
22
23 for _, b := range bins {
24 t.Logf("%+v", b)
25 }
26
27 if g := count(h.Bins()); g != numPoints {
28 t.Fatalf("binned %d points, wanted %d", g, numPoints)
29 }
30 }
31
32 func count(bins Bins) int {
33 binCounts := 0
34 for _, b := range bins {
35 binCounts += b.Count
36 }
37 return binCounts
38 }
39
View as plain text