Repository navigation
add standalone circle-fit tests #407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
atsju
wants to merge
2
commits into
master
Choose a base branch
from
JST/circlefit-tests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| #include <QtTest> | ||
| #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" | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.