Histogram: Add Percentile calculation
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user