Skip to content

Commit a5d981d

Browse files
authored
Merge pull request #80 from khabinov/khabinov/fix-histogram-boundaries
Histogram boundary value should be inclusive
2 parents b9906b5 + 4e2a19f commit a5d981d

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

lib/histogram.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ void Histogram::Observe(double value) {
1717
auto bucket_index = static_cast<std::size_t>(std::distance(
1818
bucket_boundaries_.begin(),
1919
std::find_if(bucket_boundaries_.begin(), bucket_boundaries_.end(),
20-
[value](double boundary) { return boundary > value; })));
20+
[value](double boundary) { return boundary >= value; })));
2121
sum_.Increment(value);
2222
bucket_counts_[bucket_index].Increment();
2323
}

tests/histogram_test.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,16 @@ TEST_F(HistogramTest, cumulative_bucket_count) {
7474
Histogram histogram{{1, 2}};
7575
histogram.Observe(0);
7676
histogram.Observe(0.5);
77+
histogram.Observe(1);
7778
histogram.Observe(1.5);
7879
histogram.Observe(1.5);
80+
histogram.Observe(2);
7981
histogram.Observe(3);
8082
auto metric = histogram.Collect();
8183
ASSERT_TRUE(metric.has_histogram());
8284
auto h = metric.histogram();
8385
ASSERT_EQ(h.bucket_size(), 3);
84-
EXPECT_EQ(h.bucket(0).cumulative_count(), 2);
85-
EXPECT_EQ(h.bucket(1).cumulative_count(), 4);
86-
EXPECT_EQ(h.bucket(2).cumulative_count(), 5);
86+
EXPECT_EQ(h.bucket(0).cumulative_count(), 3);
87+
EXPECT_EQ(h.bucket(1).cumulative_count(), 6);
88+
EXPECT_EQ(h.bucket(2).cumulative_count(), 7);
8789
}

0 commit comments

Comments
 (0)