X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2Ftest%2FHistogramTest.cpp;h=c2997a35ecdf5e55a44d18e24924d47a6298d884;hb=fa172175980b13569ba42008202a857af6e959dd;hp=a5cfd95162d56be4ab72daa466fb286d42ccc4dc;hpb=27494a20393fa45072e7d526d358835f3abe312a;p=folly.git diff --git a/folly/test/HistogramTest.cpp b/folly/test/HistogramTest.cpp index a5cfd951..c2997a35 100644 --- a/folly/test/HistogramTest.cpp +++ b/folly/test/HistogramTest.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2012 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,10 +14,10 @@ * limitations under the License. */ -#include "folly/Histogram.h" +#include +#include -#include -#include +#include using folly::Histogram; @@ -202,3 +202,22 @@ TEST(Histogram, TestDoubleWidthTooBig) { EXPECT_EQ(1, h.getBucketByIndex(2).count); EXPECT_EQ(3.0, h.getPercentileEstimate(0.5)); } + +// Test that we get counts right +TEST(Histogram, Counts) { + Histogram h(1, 0, 10); + EXPECT_EQ(12, h.getNumBuckets()); + EXPECT_EQ(0, h.computeTotalCount()); + + // Add one to each bucket, make sure the counts match + for (int32_t i = 0; i < 10; i++) { + h.addValue(i); + EXPECT_EQ(i+1, h.computeTotalCount()); + } + + // Add a lot to one bucket, make sure the counts still make sense + for (int32_t i = 0; i < 100; i++) { + h.addValue(0); + } + EXPECT_EQ(110, h.computeTotalCount()); +}