Skip to content

Commit 4eb443a

Browse files
committed
[add] increased coverage and updated year license
1 parent 6360d17 commit 4eb443a

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

LICENSE

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
The MIT License (MIT)
22

33
Copyright (c) 2014 Coda Hale
4+
Copyright (c) 2020 Filipe Oliveira
45

56
Permission is hereby granted, free of charge, to any person obtaining a copy
67
of this software and associated documentation files (the "Software"), to deal

hdr_test.go

+62
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package hdrhistogram_test
22

33
import (
4+
"github.com/stretchr/testify/assert"
45
"math"
56
"reflect"
67
"testing"
@@ -33,6 +34,15 @@ func TestValueAtQuantile(t *testing.T) {
3334
}
3435
}
3536

37+
// assert the upper bound limit
38+
v100 := h.ValueAtQuantile(100.0)
39+
v101 := h.ValueAtQuantile(101.0)
40+
assert.Equal(t, v100, v101)
41+
42+
// assert the lower bound limit
43+
v0 := h.ValueAtQuantile(0.0)
44+
assert.Equal(t, v0, int64(0))
45+
3646
data := []struct {
3747
q float64
3848
v int64
@@ -339,11 +349,18 @@ func TestExportImport(t *testing.T) {
339349

340350
func TestEquals(t *testing.T) {
341351
h1 := hdrhistogram.New(1, 10000000, 3)
352+
h11 := hdrhistogram.New(1, 10000000, 3)
342353
for i := 0; i < 1000000; i++ {
343354
if err := h1.RecordValue(int64(i)); err != nil {
344355
t.Fatal(err)
345356
}
346357
}
358+
for i := 0; i < 999999; i++ {
359+
if err := h11.RecordValue(int64(i)); err != nil {
360+
t.Fatal(err)
361+
}
362+
}
363+
assert.False(t, h1.Equals(h11))
347364

348365
h2 := hdrhistogram.New(1, 10000000, 3)
349366
for i := 0; i < 10000; i++ {
@@ -363,3 +380,48 @@ func TestEquals(t *testing.T) {
363380
t.Error("Expected Histograms to be equivalent")
364381
}
365382
}
383+
384+
func TestNew_Negative(t *testing.T) {
385+
assert.Panics(t, func() {
386+
hdrhistogram.New(1, 10000000, 6)
387+
}, "The code did not panic")
388+
}
389+
390+
func TestHistogram_CountsLen(t *testing.T) {
391+
hdr1 := hdrhistogram.New(1, 10000000, 1)
392+
assert.Equal(t, hdr1.CountsLen(), int32(336))
393+
hdr2 := hdrhistogram.New(1, 10000000, 2)
394+
assert.Equal(t, hdr2.CountsLen(), int32(2304))
395+
hdr3 := hdrhistogram.New(1, 10000000, 3)
396+
assert.Equal(t, hdr3.CountsLen(), int32(15360))
397+
hdr4 := hdrhistogram.New(1, 10000000, 4)
398+
assert.Equal(t, hdr4.CountsLen(), int32(180224))
399+
hdr5 := hdrhistogram.New(1, 10000000, 5)
400+
assert.Equal(t, hdr5.CountsLen(), int32(1048576))
401+
}
402+
403+
func TestHistogram_RecordValues_Negative(t *testing.T) {
404+
hdr1 := hdrhistogram.New(1, 10000000, 1)
405+
err := hdr1.RecordValues(10000000, 10)
406+
assert.Nil(t, err)
407+
err = hdr1.RecordValues(20000000, 10)
408+
assert.NotNil(t, err)
409+
}
410+
411+
func TestHistogram_CumulativeDistributionWithTicks(t *testing.T) {
412+
minv := 0
413+
maxv := 100
414+
h1 := hdrhistogram.New(int64(minv), int64(maxv), 5)
415+
cdfvals := make([]int64, maxv-minv+1, maxv-minv+1)
416+
for i := minv; i <= maxv; i++ {
417+
if err := h1.RecordValue(int64(i)); err != nil {
418+
t.Fatal(err)
419+
}
420+
cdfvals[i] += int64(i)
421+
}
422+
cdf := h1.CumulativeDistributionWithTicks(1)
423+
assert.Equal(t, int64(0), cdf[0].ValueAt)
424+
assert.Equal(t, int64(maxv), cdf[len(cdf)-1].ValueAt)
425+
assert.Equal(t, float64(0), cdf[0].Quantile)
426+
assert.Equal(t, float64(100), cdf[len(cdf)-1].Quantile)
427+
}

0 commit comments

Comments
 (0)