From 71c6d71ca2905258da6124513db62000c18a1b0b Mon Sep 17 00:00:00 2001 From: okay Date: Sun, 16 Oct 2016 14:21:37 -0700 Subject: [PATCH] add test for simple integer timestamps since epoch --- hdr_test.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/hdr_test.go b/hdr_test.go index 309f0ea..ec4fe6a 100644 --- a/hdr_test.go +++ b/hdr_test.go @@ -386,3 +386,37 @@ func TestEquals(t *testing.T) { t.Error("Expected Histograms to be equivalent") } } + +func TestTimeStamps(t *testing.T) { + // record 5 fake timestampey looking things + // we expect our histogram to return a number between any of these timestamps + input := []int64{ + 1476581605, + 1476582605, + 1476583605, + 1476584605, + 1476585605, + } + + hist := hdrhistogram.New(input[2] - 10000, input[2] + 10000, 3) + for _, sample := range input { + hist.RecordValue(sample) + } + + tolerable_delta := float64(input[2] / 1000.0) + if v, want := hist.ValueAtQuantile(50), int64(input[2],); math.Abs(float64(v - want)) > tolerable_delta { + t.Errorf("Median was %v, but expected %v +/- %v", v, want, tolerable_delta) + } + ms_hist := hdrhistogram.New(input[2] - 10000, input[2] + 10000, 5) + for i, sample := range input { + input[i] = sample * 1000; // convert to ms since epoch + ms_hist.RecordValue(input[i]) + } + + // verify actual value is not off by more than VAL / 1000 + ms_tolerable_delta := float64(input[2] / 1000.0) + if v, want := ms_hist.ValueAtQuantile(50), int64(input[2],); math.Abs(float64(v - want)) > ms_tolerable_delta { + t.Errorf("Median was %v, but expected %v +/- %v", v, want, ms_tolerable_delta) + } + +}