Histogram: Add Percentile calculation

This commit is contained in:
2025-12-12 14:28:06 +01:00
parent e03d0677ba
commit 0de70dde7e
2 changed files with 68 additions and 8 deletions

View File

@@ -53,3 +53,20 @@ TEST_CASE("FloatHistogram") {
CHECK(p.GetPlots()[0].y[50] == 1.0);
CHECK(p.GetPlots()[0].y[99] == 0.0);
}
TEST_CASE("FloatHistogram_Percentile") {
FloatHistogram h(111, 89.5, 200.5);
for (int i = 0; i < 8; i++)
h.Add(100.0f);
h.Add(150.0f);
h.Add(200.0f);
CHECK(h.Percentile(0.0f).value_or(-1) == Catch::Approx(100.0f));
CHECK(h.Percentile(30.0f).value_or(-1) == Catch::Approx(100.0f));
CHECK(h.Percentile(50.0f).value_or(-1) == Catch::Approx(100.0f));
CHECK(h.Percentile(80.0f).value_or(-1) == Catch::Approx(100.0f));
CHECK(h.Percentile(90.0f).value_or(-1) == Catch::Approx(150.0f));
CHECK(h.Percentile(100.0f).value_or(-1) == Catch::Approx(200.0f));
CHECK(h.TotalCount() == 10);
}