~juju-qa/ubuntu/yakkety/juju/2.0-beta17

« back to all changes in this revision

Viewing changes to src/github.com/beorn7/perks/histogram/histogram_test.go

  • Committer: Nicholas Skaggs
  • Date: 2016-08-26 19:28:00 UTC
  • mfrom: (1.5.1)
  • Revision ID: nicholas.skaggs@canonical.com-20160826192800-b2rgj3da7tgfdca4
* New upstream release 2.0-beta16
* Remove all quilt patches
* Ensure autopkgtests run on LXD upload (LP: #1614724)
* Update debian/copyrights

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package histogram
 
2
 
 
3
import (
 
4
        "math/rand"
 
5
        "testing"
 
6
)
 
7
 
 
8
func TestHistogram(t *testing.T) {
 
9
        const numPoints = 1e6
 
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
}