@@ -386,3 +386,37 @@ func TestEquals(t *testing.T) {
386386 t .Error ("Expected Histograms to be equivalent" )
387387 }
388388}
389+
390+ func TestTimeStamps (t * testing.T ) {
391+ // record 5 fake timestampey looking things
392+ // we expect our histogram to return a number between any of these timestamps
393+ input := []int64 {
394+ 1476581605 ,
395+ 1476582605 ,
396+ 1476583605 ,
397+ 1476584605 ,
398+ 1476585605 ,
399+ }
400+
401+ hist := hdrhistogram .New (input [2 ] - 10000 , input [2 ] + 10000 , 3 )
402+ for _ , sample := range input {
403+ hist .RecordValue (sample )
404+ }
405+
406+ tolerable_delta := float64 (input [2 ] / 1000.0 )
407+ if v , want := hist .ValueAtQuantile (50 ), int64 (input [2 ],); math .Abs (float64 (v - want )) > tolerable_delta {
408+ t .Errorf ("Median was %v, but expected %v +/- %v" , v , want , tolerable_delta )
409+ }
410+ ms_hist := hdrhistogram .New (input [2 ] - 10000 , input [2 ] + 10000 , 5 )
411+ for i , sample := range input {
412+ input [i ] = sample * 1000 ; // convert to ms since epoch
413+ ms_hist .RecordValue (input [i ])
414+ }
415+
416+ // verify actual value is not off by more than VAL / 1000
417+ ms_tolerable_delta := float64 (input [2 ] / 1000.0 )
418+ if v , want := ms_hist .ValueAtQuantile (50 ), int64 (input [2 ],); math .Abs (float64 (v - want )) > ms_tolerable_delta {
419+ t .Errorf ("Median was %v, but expected %v +/- %v" , v , want , ms_tolerable_delta )
420+ }
421+
422+ }
0 commit comments