Skip to content

ENH: Convert 10 Numerics/Statistics tests to GoogleTest#6200

Merged
dzenanz merged 10 commits intoInsightSoftwareConsortium:mainfrom
hjmjohnson:convert-statistics-gtest-batch1
May 4, 2026
Merged

ENH: Convert 10 Numerics/Statistics tests to GoogleTest#6200
dzenanz merged 10 commits intoInsightSoftwareConsortium:mainfrom
hjmjohnson:convert-statistics-gtest-batch1

Conversation

@hjmjohnson
Copy link
Copy Markdown
Member

Mechanical conversion of 10 no-argument legacy CTests in Modules/Numerics/Statistics/test/ to GoogleTest, per the convert-to-gtest skill workflow ("one commit, one change" — N-Dekker).

Test Commit
itkNormalVariateGeneratorTest1 5ece62b3
itkStatisticsTypesTest 3680b32b
itkMaximumDecisionRuleTest f325aba3
itkRandomVariateGeneratorBaseTest 98fee239
itkMinimumDecisionRuleTest c7f02fa8
itkHistogramToTextureFeaturesFilterNaNTest 033d5edc
itkMaximumRatioDecisionRuleTest 3b4c7868
itkMixtureModelComponentBaseTest f422ac51
itkVectorContainerToListSampleAdaptorTest 669e61f0
itkMembershipFunctionBaseTest fad64f08

Each is a single commit with git mv rename (70-96% similarity, history preserved through git log --follow), ITK_EXERCISE_BASIC_OBJECT_METHODSITK_GTEST_EXERCISE_BASIC_OBJECT_METHODS, return-on-failure → EXPECT_EQ / EXPECT_THROW, no logic refactoring, no comment removal.

Verification
  • All 10 GTests build and pass locally (combined run: 10 / 10 pass in 6 ms)
  • pre-commit run --all-files exit 0 on the final tip
  • CMakeLists alphabetic ordering preserved on both ITKStatisticsTests (legacy) and ITKStatisticsGTests sets

Build verification used a dedicated ~/src/ITK-build-test-tree/build-standard/ (separate detached worktree, fully ccache-warm) per the new "one test tree, many configs" architecture — git reset --hard between conversions, ~5-15 s incremental rebuild per commit, no source-mirror drift across worktrees.

Net diff: +81 / -211 (conversion strips boilerplate if (status == EXIT_FAILURE) { std::cout << "[FAILED]"; return EXIT_FAILURE; } blocks).

Backlog progress
Module group Easy backlog After this PR
Numerics/Statistics 76 66
ITK-wide easy backlog 457 447

Followup batches will continue with the same module first (66 remaining → ~7 more PRs to clear it).

@github-actions github-actions Bot added type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots type:Enhancement Improvement of existing methods or implementation type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct area:Numerics Issues affecting the Numerics module labels May 3, 2026
@hjmjohnson hjmjohnson marked this pull request as ready for review May 4, 2026 00:45
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 4, 2026

Greptile Summary

This PR mechanically converts 10 legacy no-argument CTests in Modules/Numerics/Statistics/test/ to GoogleTest format. Each file is renamed (TestGTest), main() is replaced with a TEST() macro, ITK legacy assertion macros are swapped for their GTest equivalents (EXPECT_EQ, EXPECT_THROW, EXPECT_FALSE), and the old itk_add_test registrations are removed in favour of the new ITKStatisticsGTests list fed to creategoogletestdriver. The conversion is faithful — no test logic, comments, or assertions were dropped.

Confidence Score: 5/5

Safe to merge — purely mechanical conversion with no logic changes, all 10 tests verified locally.

All changes are straightforward rename-and-adapt conversions. The assertion macro substitutions are semantically equivalent, CMakeLists changes are structurally correct, and no test logic was altered or dropped. No P0/P1 findings.

No files require special attention.

Important Files Changed

Filename Overview
Modules/Numerics/Statistics/test/CMakeLists.txt Removes 10 legacy source files and their itk_add_test registrations; adds all 10 GTest files to ITKStatisticsGTests in alphabetical order and feeds them to creategoogletestdriver — structurally correct.
Modules/Numerics/Statistics/test/itkHistogramToTextureFeaturesFilterNaNGTest.cxx NaN guard converted from if/return to EXPECT_FALSE(isnan(correlation)); clean rename and include reorder.
Modules/Numerics/Statistics/test/itkMaximumDecisionRuleGTest.cxx Two if/return guards converted to EXPECT_EQ; boilerplate removed; no logic change.
Modules/Numerics/Statistics/test/itkMaximumRatioDecisionRuleGTest.cxx ITK_EXERCISE/SET_GET_VALUE macros swapped for GTest equivalents; the empty-aPrioris for-loop was already a no-op in the original, not introduced here.
Modules/Numerics/Statistics/test/itkMembershipFunctionBaseGTest.cxx try-catch block correctly collapsed to EXPECT_THROW with itk::ExceptionObject; EXPECT_EQ for size check preserved.
Modules/Numerics/Statistics/test/itkMinimumDecisionRuleGTest.cxx Three if/return guards converted to EXPECT_EQ; clean conversion.
Modules/Numerics/Statistics/test/itkMixtureModelComponentBaseGTest.cxx ITK_TRY_EXPECT_EXCEPTION replaced by EXPECT_THROW; itkTestingMacros.h correctly dropped in favour of itkGTest.h.
Modules/Numerics/Statistics/test/itkNormalVariateGeneratorGTest1.cxx Smoke/execution-only test with pre-existing FIXME; faithfully converted — no assertions to migrate.
Modules/Numerics/Statistics/test/itkRandomVariateGeneratorBaseGTest.cxx Simple smoke test; only boilerplate and return removed; no assertion conversion needed.
Modules/Numerics/Statistics/test/itkStatisticsTypesGTest.cxx Print/compilation test with no assertion macros to migrate; declareType macro unchanged; clean conversion.
Modules/Numerics/Statistics/test/itkVectorContainerToListSampleAdaptorGTest.cxx All ITK_TRY_EXPECT_EXCEPTION, ITK_TEST_EXPECT_EQUAL, and ITK_EXERCISE macros correctly replaced with GTest equivalents.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["Legacy CTest file\n(itkFooTest.cxx)"] -->|"git mv"| B["GTest file\n(itkFooGTest.cxx)"]
    B --> C["Remove from ITKStatisticsTests\nlist in CMakeLists.txt"]
    B --> D["Add to ITKStatisticsGTests\nlist in CMakeLists.txt"]
    C --> E["Remove itk_add_test() block"]
    D --> F["creategoogletestdriver()\nauto-registers all GTests"]
    B --> G["Conversion changes"]
    G --> G1["main() → TEST(Suite, ConvertedLegacyTest)"]
    G --> G2["ITK_EXERCISE_BASIC_OBJECT_METHODS\n→ ITK_GTEST_EXERCISE_BASIC_OBJECT_METHODS"]
    G --> G3["if/return EXIT_FAILURE → EXPECT_EQ / EXPECT_FALSE"]
    G --> G4["ITK_TRY_EXPECT_EXCEPTION → EXPECT_THROW"]
    G --> G5["#include itkTestingMacros.h\n→ #include itkGTest.h"]
Loading

Reviews (1): Last reviewed commit: "ENH: Convert itkMembershipFunctionBaseTe..." | Re-trigger Greptile

@dzenanz dzenanz merged commit 3e58a84 into InsightSoftwareConsortium:main May 4, 2026
16 checks passed
@hjmjohnson hjmjohnson added this to the ITK 6.0.0 milestone May 5, 2026
hjmjohnson pushed a commit to hjmjohnson/ITK that referenced this pull request May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Numerics Issues affecting the Numerics module type:Enhancement Improvement of existing methods or implementation type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants