1
1
package hdrhistogram_test
2
2
3
3
import (
4
+ "github.com/stretchr/testify/assert"
4
5
"math"
5
6
"reflect"
6
7
"testing"
@@ -33,6 +34,15 @@ func TestValueAtQuantile(t *testing.T) {
33
34
}
34
35
}
35
36
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
+
36
46
data := []struct {
37
47
q float64
38
48
v int64
@@ -339,11 +349,18 @@ func TestExportImport(t *testing.T) {
339
349
340
350
func TestEquals (t * testing.T ) {
341
351
h1 := hdrhistogram .New (1 , 10000000 , 3 )
352
+ h11 := hdrhistogram .New (1 , 10000000 , 3 )
342
353
for i := 0 ; i < 1000000 ; i ++ {
343
354
if err := h1 .RecordValue (int64 (i )); err != nil {
344
355
t .Fatal (err )
345
356
}
346
357
}
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 ))
347
364
348
365
h2 := hdrhistogram .New (1 , 10000000 , 3 )
349
366
for i := 0 ; i < 10000 ; i ++ {
@@ -363,3 +380,48 @@ func TestEquals(t *testing.T) {
363
380
t .Error ("Expected Histograms to be equivalent" )
364
381
}
365
382
}
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