Files
Jungfraujoch/tests/HistogramTest.cpp
Filip Leonarski e2b240356c
All checks were successful
Build Packages / build:rpm (rocky8_nocuda) (push) Successful in 9m28s
Build Packages / build:rpm (ubuntu2404_nocuda) (push) Successful in 8m25s
Build Packages / build:rpm (ubuntu2204_nocuda) (push) Successful in 9m4s
Build Packages / build:rpm (rocky9_nocuda) (push) Successful in 10m27s
Build Packages / build:rpm (rocky8_sls9) (push) Successful in 9m36s
Build Packages / Generate python client (push) Successful in 32s
Build Packages / Build documentation (push) Successful in 45s
Build Packages / Create release (push) Has been skipped
Build Packages / build:rpm (rocky8) (push) Successful in 8m45s
Build Packages / build:rpm (ubuntu2404) (push) Successful in 7m51s
Build Packages / build:rpm (ubuntu2204) (push) Successful in 8m57s
Build Packages / build:rpm (rocky9) (push) Successful in 9m35s
Build Packages / Unit tests (push) Successful in 1h13m45s
v1.0.0-rc.121 (#28)
This is an UNSTABLE release.

* jfjoch_broker: Report changes in the image buffer, so viewer doesn't reload constantly
* jfjoch_viewer: Improve performance of loading images
* jfjoch_viewer: Auto-throttle image loading in HTTP-sync / movie modes
* jfjoch_viewer: Auto-foreground calculated with histogram
* jfjoch_viewer: Fix rare segmentation fault

Reviewed-on: #28
Co-authored-by: Filip Leonarski <filip.leonarski@psi.ch>
Co-committed-by: Filip Leonarski <filip.leonarski@psi.ch>
2025-12-12 21:24:20 +01:00

86 lines
2.0 KiB
C++

// SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#include <catch2/catch_all.hpp>
#include "../common/Histogram.h"
TEST_CASE("SetAverage") {
SetAverage<float> h(100);
h.Add(80, 30.0);
h.Add(50, 20.0);
h.Add(50, 30.0);
h.Add(0, -2.0);
h.Add(100, 50.0);
auto p = h.GetPlot();
REQUIRE(p.GetPlots().size() == 1);
REQUIRE(p.GetPlots()[0].x.size() == 100);
REQUIRE(p.GetPlots()[0].y.size() == 100);
CHECK(p.GetPlots()[0].x[0] == 0.0);
CHECK(p.GetPlots()[0].x[80] == 80.0);
CHECK(p.GetPlots()[0].x[30] == 30.0);
CHECK(p.GetPlots()[0].x[99] == 99.0);
CHECK(p.GetPlots()[0].y[0] == -2.0);
CHECK(p.GetPlots()[0].y[50] == 25.0);
CHECK(p.GetPlots()[0].y[80] == 30.0);
CHECK(p.GetPlots()[0].y[99] == 0.0);
}
TEST_CASE("Histogram") {
Histogram h(200);
h.Add(150);
h.Add(100);
h.Add(100);
h.Add(100);
h.Add(100);
h.Add(101);
h.Add(199);
h.Add(200); // Outside or range
h.Add(-1); // Outside of range
CHECK(h.GetTotalCount() == 7);
auto p = h.GetCount();
REQUIRE(p.size() == 200);
CHECK(p[100] == 4);
CHECK(p[150] == 1);
CHECK(p[199] == 1);
CHECK(p[101] == 1);
CHECK(p[55] == 0);
}
TEST_CASE("Histogram_Percentile") {
Histogram h(500);
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) == 100);
CHECK(h.Percentile(30.0f).value_or(-1) == 100);
CHECK(h.Percentile(50.0f).value_or(-1) == 100);
CHECK(h.Percentile(80.0f).value_or(-1) == 100);
CHECK(h.Percentile(90.0f).value_or(-1) == 150);
CHECK(h.Percentile(100.0f).value_or(-1) == 200);
CHECK(h.GetTotalCount() == 10);
}
TEST_CASE("Histogram_Clear") {
Histogram h(300);
for (int i = 0; i < 8; i++)
h.Add(100);
h.Add(150);
h.Add(200);
CHECK(h.GetTotalCount() == 10);
h.clear();
CHECK(h.GetTotalCount() == 0);
h.Add(200.0f);
CHECK(h.GetTotalCount() == 1);
}