From 37213b87ec0e9bb475d48881e51e36af995730f4 Mon Sep 17 00:00:00 2001 From: Julien STAUB Date: Thu, 5 Nov 2026 13:11:46 +0100 Subject: [PATCH 1/2] add standalone circle-fit tests Related to #405. --- .github/workflows/build-linux-QT5.yml | 8 ++- .github/workflows/build-linux.yml | 7 +++ README.md | 6 +++ docs/testing.md | 74 +++++++++++++++++++++++++++ tests/tests.pro | 15 ++++++ tests/tst_circlefit.cpp | 69 +++++++++++++++++++++++++ 6 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 docs/testing.md create mode 100644 tests/tests.pro create mode 100644 tests/tst_circlefit.cpp diff --git a/.github/workflows/build-linux-QT5.yml b/.github/workflows/build-linux-QT5.yml index 78b23431..a12ce690 100644 --- a/.github/workflows/build-linux-QT5.yml +++ b/.github/workflows/build-linux-QT5.yml @@ -18,9 +18,15 @@ jobs: - uses: actions/checkout@v6 - run: sudo apt update - run: sudo apt install -y apt-utils build-essential wget qt5-qmake qt5-qmake-bin qt5-assistant qtbase5-dev qtmultimedia5-dev libqt5charts5 libqt5charts5-dev libqt5multimedia* libqt5datavisualization5-dev libqt5datavisualization5 libopencv-core-dev libopencv-dev libqwt-qt5-6 libqwt-qt5-dev libarmadillo-dev + - name: Run focused numerical tests + run: | + mkdir -p build/tests + cd build/tests + qmake ../../tests/tests.pro CONFIG+=release + make -j4 + ./tst_circlefit - run: qmake DFTFringe_QT5.pro #- uses: ammaraskar/gcc-problem-matcher@master #- run: echo "::add-matcher::.github/matcher/uic_matcher.json" - run: make -j4 #- run: echo "::remove-matcher owner=uic-problem-matcher::" - diff --git a/.github/workflows/build-linux.yml b/.github/workflows/build-linux.yml index c0cba1dc..be0e9aaa 100644 --- a/.github/workflows/build-linux.yml +++ b/.github/workflows/build-linux.yml @@ -24,6 +24,13 @@ jobs: - uses: actions/checkout@v6 - run: sudo apt update - run: sudo apt install -y apt-utils build-essential wget qt6-base-dev-tools qt6-declarative-dev qt6-multimedia-dev libqt6charts6-dev libqt6datavisualization6-dev libqt6svg6-dev libopencv-core-dev libopencv-dev libarmadillo-dev libgl1-mesa-dev libglu1-mesa-dev bear imagemagick file libfuse2 + - name: Run focused numerical tests + run: | + mkdir -p build/tests + cd build/tests + /usr/lib/qt6/bin/qmake ../../tests/tests.pro CONFIG+=release + make -j4 + ./tst_circlefit - run: wget -O qwt-${{env.QWT_version}}.zip https://sourceforge.net/projects/qwt/files/qwt/${{env.QWT_version}}/qwt-${{env.QWT_version}}.zip/download?use_mirror=pilotfiber - run: 7z x qwt-${{env.QWT_version}}.zip - run: cd qwt-${{env.QWT_version}} ; /usr/lib/qt6/bin/qmake diff --git a/README.md b/README.md index 05832394..a239dc7b 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,12 @@ chmod +x DFTFringe-*-x86_64.AppImage ./DFTFringe-*-x86_64.AppImage ``` +# Testing + +See the [testing guidance](docs/testing.md) for standalone circle-fit tests and +focused application checks. The test target can run without OpenCV or Qwt; +it does not replace a full application build or user-workflow validation. + # How to build DFTFringe on Linux diff --git a/docs/testing.md b/docs/testing.md new file mode 100644 index 00000000..8fa2a701 --- /dev/null +++ b/docs/testing.md @@ -0,0 +1,74 @@ +# Testing and validation + +## Focused numerical tests + +[tests.pro](../tests/tests.pro) builds a standalone Qt Test executable against the +actual [circle-fit implementation](../circlefit.cpp), without the application or +OpenCV/Qwt dependencies. Use a matching Qt/compiler pair. Qt Test is part of the +Qt base development packages already used by CI. + +The data-driven checks cover the Hyper fit of exact unit, translated, +small-radius, and partial-arc circles. They check finite center/radius/residual, +absolute parameter tolerance of `1e-9 * max(1, radius)`, a non-negative residual +within that tolerance, and unchanged input coordinates and point count. These +are deterministic baseline tests, not evidence that noisy, degenerate, GUI, or +complete optical-analysis workflows are validated. + +From the repository root, using an out-of-source build: + +### Windows PowerShell (Qt 6) + +Put the matching MinGW and Qt `bin` directories first on PATH, rather than a +different installed make/compiler. For example, with the paths from the +[Windows setup instructions](../README.md#how-to-build-dftfringe-on-windows): + +```powershell +$env:Path = "C:\buildingDFTFringe\Tools\mingw1310_64\bin;C:\buildingDFTFringe\6.8.3\mingw_64\bin;$env:Path" +New-Item -ItemType Directory -Force build\tests | Out-Null +Push-Location build\tests +qmake.exe ..\..\tests\tests.pro CONFIG+=release +mingw32-make -j4 +.\release\tst_circlefit.exe +Pop-Location +``` + +### Linux (Qt 6) + +```sh +mkdir -p build/tests +cd build/tests +/usr/lib/qt6/bin/qmake ../../tests/tests.pro CONFIG+=release +make -j4 +./tst_circlefit +``` + +For Qt 5, use the Qt 5 qmake instead; the test project selects C++14 rather than +C++17. On macOS use the matching Qt qmake and `make`. The Linux Qt 5 and Qt 6 +build workflows include this target; Windows and macOS CI do not run it. +The tests do not create a GUI or need a display server. + +Add focused cases for fixes and known numerical results with explicit units and +tolerances. Avoid random fixtures, unsupported degenerate-input expectations, +and copying implementation logic to manufacture expected results. + +## Application checks + +Use [README](../README.md) and the existing [CI workflows](../.github/workflows) +for the relevant full application build. Passing the standalone tests does not +replace a build of changed application code. + +For affected behavior, record input, environment, steps, expected result, and +observed result for relevant checks: + +- Startup and loading an existing input. +- User edits and programmatic initialization. +- Accept versus cancel. +- Save/reload and restart, using temporary copies of user data. +- Single, multiple, and mixed selections. +- Equivalent commands such as recompute and update-selected. +- Numerical output with defined tolerances. +- Axis-aligned and oblique views for geometry changes. +- Qt variants, supported platforms, and packaged asset lookup when affected. + +Run only checks relevant to the change, explaining omissions. Never report this +checklist as executed merely because it exists. diff --git a/tests/tests.pro b/tests/tests.pro new file mode 100644 index 00000000..e775871f --- /dev/null +++ b/tests/tests.pro @@ -0,0 +1,15 @@ +TEMPLATE = app +TARGET = tst_circlefit +QT = core testlib +CONFIG += console testcase +CONFIG -= app_bundle +greaterThan(QT_MAJOR_VERSION, 5) { + CONFIG += c++17 +} else { + CONFIG += c++14 +} + +INCLUDEPATH += .. +HEADERS += ../circlefit.h +SOURCES += ../circlefit.cpp \ + tst_circlefit.cpp diff --git a/tests/tst_circlefit.cpp b/tests/tst_circlefit.cpp new file mode 100644 index 00000000..fac9750a --- /dev/null +++ b/tests/tst_circlefit.cpp @@ -0,0 +1,69 @@ +#include +#include "circlefit.h" + +#include +#include +#include + +class CircleFitTest : public QObject +{ + Q_OBJECT + +private slots: + void exactCircle_data(); + void exactCircle(); +}; + +void CircleFitTest::exactCircle_data() +{ + QTest::addColumn("centerX"); + QTest::addColumn("centerY"); + QTest::addColumn("radius"); + QTest::addColumn("startAngle"); + QTest::addColumn("sweep"); + + QTest::newRow("unit") << 0.0 << 0.0 << 1.0 << 0.0 << 6.0; + QTest::newRow("translated") << 12.0 << -7.0 << 4.0 << 0.3 << 6.0; + QTest::newRow("small-radius") << -0.5 << 0.25 << 0.01 << 0.7 << 6.0; + QTest::newRow("partial-arc") << -3.0 << 5.0 << 2.0 << 0.4 << 1.5; +} + +void CircleFitTest::exactCircle() +{ + QFETCH(double, centerX); + QFETCH(double, centerY); + QFETCH(double, radius); + QFETCH(double, startAngle); + QFETCH(double, sweep); + + constexpr int count = 24; + std::array x; + std::array y; + for (int i = 0; i < count; ++i) { + const double angle = startAngle + sweep * i / (count - 1); + x[i] = centerX + radius * std::cos(angle); + y[i] = centerY + radius * std::sin(angle); + } + + CircleData data(count, x.data(), y.data()); + const Circle fitted = CircleFitByHyper(data); + const double tolerance = 1e-9 * std::max(1.0, radius); + + QVERIFY(std::isfinite(fitted.a)); + QVERIFY(std::isfinite(fitted.b)); + QVERIFY(std::isfinite(fitted.r)); + QVERIFY(std::isfinite(fitted.s)); + QVERIFY(std::abs(fitted.a - centerX) <= tolerance); + QVERIFY(std::abs(fitted.b - centerY) <= tolerance); + QVERIFY(std::abs(fitted.r - radius) <= tolerance); + QVERIFY(fitted.s >= 0.0); + QVERIFY(fitted.s <= tolerance); + QCOMPARE(data.n, count); + for (int i = 0; i < count; ++i) { + QVERIFY(data.X[i] == x[i]); + QVERIFY(data.Y[i] == y[i]); + } +} + +QTEST_APPLESS_MAIN(CircleFitTest) +#include "tst_circlefit.moc" From b31d1874afd3a34d7d683c1adcf70e3975c4fa59 Mon Sep 17 00:00:00 2001 From: Julien STAUB Date: Thu, 5 Nov 2026 14:42:31 +0100 Subject: [PATCH 2/2] fix clang --- .github/workflows/build-linux.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-linux.yml b/.github/workflows/build-linux.yml index be0e9aaa..91492000 100644 --- a/.github/workflows/build-linux.yml +++ b/.github/workflows/build-linux.yml @@ -29,7 +29,7 @@ jobs: mkdir -p build/tests cd build/tests /usr/lib/qt6/bin/qmake ../../tests/tests.pro CONFIG+=release - make -j4 + bear --output ../../compile_commands.json -- make -j4 ./tst_circlefit - run: wget -O qwt-${{env.QWT_version}}.zip https://sourceforge.net/projects/qwt/files/qwt/${{env.QWT_version}}/qwt-${{env.QWT_version}}.zip/download?use_mirror=pilotfiber - run: 7z x qwt-${{env.QWT_version}}.zip @@ -54,7 +54,7 @@ jobs: - run: echo "::add-matcher::.github/matcher/uic_matcher.json" - name: capture compile_commands.json from build - run: bear -- make -j4 + run: bear --append -- make -j4 - run: echo "::remove-matcher owner=uic-problem-matcher::" - name: Run C++ Linter (clang-tidy)