summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/beorn7/perks/histogram/histogram_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/beorn7/perks/histogram/histogram_test.go')
-rw-r--r--vendor/github.com/beorn7/perks/histogram/histogram_test.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/vendor/github.com/beorn7/perks/histogram/histogram_test.go b/vendor/github.com/beorn7/perks/histogram/histogram_test.go
new file mode 100644
index 000000000..0575ebeee
--- /dev/null
+++ b/vendor/github.com/beorn7/perks/histogram/histogram_test.go
@@ -0,0 +1,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
+}