Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/build-linux-QT5.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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::"

9 changes: 8 additions & 1 deletion .github/workflows/build-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
- run: cd qwt-${{env.QWT_version}} ; /usr/lib/qt6/bin/qmake
Expand All @@ -47,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)
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
74 changes: 74 additions & 0 deletions docs/testing.md
Original file line number Diff line number Diff line change
@@ -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.
15 changes: 15 additions & 0 deletions tests/tests.pro
Original file line number Diff line number Diff line change
@@ -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
69 changes: 69 additions & 0 deletions tests/tst_circlefit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include <QtTest>
Comment thread
atsju marked this conversation as resolved.
Resolved
#include "circlefit.h"

#include <algorithm>
#include <array>
#include <cmath>

class CircleFitTest : public QObject
{
Q_OBJECT

private slots:
void exactCircle_data();
void exactCircle();
};

void CircleFitTest::exactCircle_data()
{
QTest::addColumn<double>("centerX");
QTest::addColumn<double>("centerY");
QTest::addColumn<double>("radius");
QTest::addColumn<double>("startAngle");
QTest::addColumn<double>("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<double, count> x;
std::array<double, count> 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"
Loading