Skip to content

Commit c932d19

Browse files
jhlegarretahjmjohnson
authored andcommitted
ENH: Increase coverage for miscellaneous classes
Increase coverage for miscellaneous classes: - Exercise basic object methods using the `ITK_EXERCISE_BASIC_OBJECT_METHODS` macro. Remove redundant calls to print the filter or its class name. - Test the Set/Get methods using the `ITK_TEST_SET_GET_VALUE` macro. - Test the boolean ivars using the `ITK_TEST_SET_GET_BOOLEAN` macro. - Refactor the tests to accept (more) input parameters to allow checking the classes under a broader range of conditions. - Fix a bug in the `itkOpeningByReconstructionImageFilterTest2.cxx` file where the argument checking related to the optional output difference image was using a smaller value than the correct one for the comparison. The bug had gone unnoticed because all related tests in the `CMakeLists.txt` file had a value for the optional difference image argument. - Fix a bug in `itkCollidingFrontsImageFilterTest.cxx` file where no input image file is being allowed in practice, and the output image file argument was using the wrong argument index. The bug had gone unnoticed because no output filename is being provided in the `CMakeLists.txt` tests.
1 parent f9e6ca6 commit c932d19

18 files changed

+152
-42
lines changed

Modules/Core/Mesh/test/itkSphereMeshSourceTest.cxx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*=========================================================================*/
1818

1919
#include "itkSphereMeshSource.h"
20+
#include "itkTestingMacros.h"
2021
#include <iostream>
2122

2223
int
@@ -25,7 +26,11 @@ itkSphereMeshSourceTest(int, char *[])
2526

2627
using fPointType = itk::Point<float, 3>;
2728
using fSphereMeshSourceType = itk::SphereMeshSource<itk::Mesh<float>>;
28-
auto mySphereMeshSource = fSphereMeshSourceType::New();
29+
auto mySphereMeshSource = fSphereMeshSourceType::New();
30+
31+
ITK_EXERCISE_BASIC_OBJECT_METHODS(mySphereMeshSource, SphereMeshSource, MeshSource);
32+
33+
2934
fPointType center;
3035
center.Fill(0);
3136
fPointType::ValueType scaleInit[3] = { 1, 1, 1 };
@@ -36,11 +41,15 @@ itkSphereMeshSourceTest(int, char *[])
3641
mySphereMeshSource->SetResolutionY(10);
3742
mySphereMeshSource->SetScale(scale);
3843

44+
double squareness1 = 1.0;
45+
mySphereMeshSource->SetSquareness1(squareness1);
46+
47+
double squareness2 = 1.0;
48+
mySphereMeshSource->SetSquareness2(squareness2);
49+
3950
mySphereMeshSource->Modified();
4051
mySphereMeshSource->Update();
4152

42-
std::cout << "mySphereMeshSource: " << mySphereMeshSource;
43-
4453
using IPT = itk::Mesh<float>::PointType;
4554
// itk::Mesh<float>::PointsContainerPointer myoutput = mySphereMeshSource->GetOutput()->GetPoints();
4655
// itk::Mesh<float>::PointsContainer::Iterator m_output = myoutput->Begin();

Modules/Core/SpatialObjects/test/itkMeshSpatialObjectTest.cxx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ itkMeshSpatialObjectTest(int, char *[])
6161
ITK_EXERCISE_BASIC_OBJECT_METHODS(meshSO, MeshSpatialObject, SpatialObject);
6262

6363

64+
double isInsidePrecisionInObjectSpace = 1;
65+
meshSO->SetIsInsidePrecisionInObjectSpace(isInsidePrecisionInObjectSpace);
66+
ITK_TEST_SET_GET_VALUE(isInsidePrecisionInObjectSpace, meshSO->GetIsInsidePrecisionInObjectSpace());
67+
6468
meshSO->SetMesh(mesh);
6569
ITK_TEST_SET_GET_VALUE(mesh, meshSO->GetMesh());
6670

Modules/Filtering/AnisotropicSmoothing/test/itkVectorAnisotropicDiffusionImageFilterTest.cxx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ itkVectorAnisotropicDiffusionImageFilterTest(int itkNotUsed(argc), char * itkNot
6767
// Set up Curvature diffusion filter
6868
itk::VectorCurvatureAnisotropicDiffusionImageFilter<ImageType, ImageType>::Pointer filter2 =
6969
itk::VectorCurvatureAnisotropicDiffusionImageFilter<ImageType, ImageType>::New();
70+
71+
ITK_EXERCISE_BASIC_OBJECT_METHODS(
72+
filter2, VectorCurvatureAnisotropicDiffusionImageFilter, AnisotropicDiffusionImageFilter);
73+
74+
7075
filter2->SetNumberOfIterations(1);
7176
filter2->SetConductanceParameter(3.0f);
7277
filter2->SetTimeStep(0.1f);

Modules/Filtering/DiffusionTensorImage/test/itkDiffusionTensor3DReconstructionImageFilterTest.cxx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,33 @@ itkDiffusionTensor3DReconstructionImageFilterTest(int argc, char * argv[])
118118
gradientDirection[2] = gradientDirections[i][2];
119119
tensorReconstructionFilter->AddGradientImage(gradientDirection, gradientImage);
120120
std::cout << "Gradient directions: " << gradientDirection << std::endl;
121+
122+
const TensorReconstructionImageFilterType::GradientDirectionType::element_type epsilon = 1e-3;
123+
TensorReconstructionImageFilterType::GradientDirectionType output =
124+
tensorReconstructionFilter->GetGradientDirection(i);
125+
for (unsigned int j = 0; j < gradientDirection.size(); ++j)
126+
{
127+
TensorReconstructionImageFilterType::GradientDirectionType::element_type gradientDirectionComponent =
128+
gradientDirection[j];
129+
TensorReconstructionImageFilterType::GradientDirectionType::element_type outputComponent = output[j];
130+
if (!itk::Math::FloatAlmostEqual(gradientDirectionComponent, outputComponent, 10, epsilon))
131+
{
132+
std::cerr.precision(static_cast<int>(itk::Math::abs(std::log10(epsilon))));
133+
std::cerr << "Test failed!" << std::endl;
134+
std::cerr << "Error in gradientDirection [" << i << "]"
135+
<< "[" << j << "]" << std::endl;
136+
std::cerr << "Expected value " << gradientDirectionComponent << std::endl;
137+
std::cerr << " differs from " << outputComponent;
138+
std::cerr << " by more than " << epsilon << std::endl;
139+
return EXIT_FAILURE;
140+
}
141+
}
121142
}
143+
144+
// Test gradient direction index exception
145+
unsigned int idx = numberOfGradientImages + 1;
146+
ITK_TRY_EXPECT_EXCEPTION(tensorReconstructionFilter->GetGradientDirection(idx));
147+
122148
//
123149
// second time through test, use the mask image
124150
if (pass == 1)

Modules/Filtering/DisplacementField/test/itkDisplacementFieldTransformTest.cxx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,12 @@ itkDisplacementFieldTransformTest(int argc, char * argv[])
178178
ITK_EXERCISE_BASIC_OBJECT_METHODS(displacementTransform, DisplacementFieldTransform, Transform);
179179

180180

181+
// Test exceptions
182+
DisplacementTransformType::InputVnlVectorType::element_type vectorValue = 1.0;
183+
DisplacementTransformType::InputVnlVectorType vector;
184+
vector.fill(vectorValue);
185+
ITK_TRY_EXPECT_EXCEPTION(displacementTransform->TransformVector(vector));
186+
181187
DisplacementTransformType::DisplacementFieldType::Pointer displacementField =
182188
DisplacementTransformType::DisplacementFieldType::New();
183189
displacementTransform->SetDisplacementField(displacementField);

Modules/Filtering/FFT/test/itkFullToHalfHermitianImageFilterTest.cxx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,14 @@ itkFullToHalfHermitianImageFilterTest(int argc, char * argv[])
7575

7676
using FullToHalfFilterType = itk::FullToHalfHermitianImageFilter<ComplexImageType>;
7777
auto fullToHalfFilter = FullToHalfFilterType::New();
78+
79+
ITK_EXERCISE_BASIC_OBJECT_METHODS(fullToHalfFilter, FullToHalfHermitianImageFilter, ImageToImageFilter);
80+
81+
7882
fullToHalfFilter->SetInput(halfToFullFilter->GetOutput());
7983
fullToHalfFilter->Update();
80-
fullToHalfFilter->Print(std::cout);
84+
85+
std::cout << "ActualXDimensionIsOdd: " << fullToHalfFilter->GetActualXDimensionIsOdd() << std::endl;
8186

8287
// Check that the output of the full-to-half filter has the same
8388
// size as the output of the FFT filter.

Modules/Filtering/ImageStatistics/test/itkImagePCADecompositionCalculatorTest.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ itkImagePCADecompositionCalculatorTest(int, char *[])
322322
ImagePCAShapeModelEstimatorType::BasisVectorType proj3_3, proj4_3;
323323
// now test it with a mean image set
324324
decomposer->SetMeanImage(image8);
325+
ITK_TEST_SET_GET_VALUE(image8, decomposer->GetMeanImage());
325326

326327
decomposer->SetImage(image3);
327328
decomposer->Compute();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
92e736905e044fa0a29ace07cce3175e14a15959c69c595b3a9059d218f01fc755f8a1ce1ed8d036743331b06ee6c3d05ffff45fe20631778b4e851ebc96a227
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
171ca81f508d58809aa9b8323de9f9d7cab85a5059a7663417a0a32ae2a732f947f30a5b43b5e4f623f33bcb9d9212a9c66c18a69a506d4caa264155c362758a

Modules/Filtering/MathematicalMorphology/test/CMakeLists.txt

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,17 @@ itk_add_test(NAME itkClosingByReconstructionImageFilterTest
6464
COMMAND ITKMathematicalMorphologyTestDriver
6565
--compare DATA{${ITK_DATA_ROOT}/Baseline/BasicFilters/ClosingByReconstructionImageFilterTest.png}
6666
${ITK_TEST_OUTPUT_DIR}/ClosingByReconstructionImageFilterTest.png
67-
itkClosingByReconstructionImageFilterTest DATA{${ITK_DATA_ROOT}/Input/closerec1.jpg} ${ITK_TEST_OUTPUT_DIR}/ClosingByReconstructionImageFilterTest.png 4 0 ${ITK_TEST_OUTPUT_DIR}/ClosingByReconstructionImageFilterTestSubtract.png)
67+
itkClosingByReconstructionImageFilterTest DATA{${ITK_DATA_ROOT}/Input/closerec1.jpg} ${ITK_TEST_OUTPUT_DIR}/ClosingByReconstructionImageFilterTest.png 4 0 0 ${ITK_TEST_OUTPUT_DIR}/ClosingByReconstructionImageFilterTestSubtract.png)
6868
itk_add_test(NAME itkClosingByReconstructionImageFilterTest2
6969
COMMAND ITKMathematicalMorphologyTestDriver
7070
--compare DATA{${ITK_DATA_ROOT}/Baseline/BasicFilters/ClosingByReconstructionImageFilterTest2.png}
7171
${ITK_TEST_OUTPUT_DIR}/ClosingByReconstructionImageFilterTest2.png
72-
itkClosingByReconstructionImageFilterTest DATA{${ITK_DATA_ROOT}/Input/closerec1.jpg} ${ITK_TEST_OUTPUT_DIR}/ClosingByReconstructionImageFilterTest2.png 4 1 ${ITK_TEST_OUTPUT_DIR}/ClosingByReconstructionImageFilterTestSubtract2.png)
72+
itkClosingByReconstructionImageFilterTest DATA{${ITK_DATA_ROOT}/Input/closerec1.jpg} ${ITK_TEST_OUTPUT_DIR}/ClosingByReconstructionImageFilterTest2.png 4 1 0 ${ITK_TEST_OUTPUT_DIR}/ClosingByReconstructionImageFilterTestSubtract2.png)
73+
itk_add_test(NAME itkClosingByReconstructionImageFilterTestFullyConnected
74+
COMMAND ITKMathematicalMorphologyTestDriver
75+
--compare DATA{Baseline/ClosingByReconstructionImageFilterTestFullyConnected.png}
76+
${ITK_TEST_OUTPUT_DIR}/ClosingByReconstructionImageFilterTestFullyConnected.png
77+
itkClosingByReconstructionImageFilterTest DATA{${ITK_DATA_ROOT}/Input/closerec1.jpg} ${ITK_TEST_OUTPUT_DIR}/ClosingByReconstructionImageFilterTestFullyConnected.png 4 1 1 ${ITK_TEST_OUTPUT_DIR}/ClosingByReconstructionImageFilterTestSubtractFullyConnected.png)
7378
itk_add_test(NAME itkFlatStructuringElementTest
7479
COMMAND ITKMathematicalMorphologyTestDriver
7580
--redirectOutput ${ITK_TEST_OUTPUT_DIR}/itkFlatStructuringElementTest.txt
@@ -226,22 +231,27 @@ itk_add_test(NAME itkOpeningByReconstructionImageFilterTest
226231
COMMAND ITKMathematicalMorphologyTestDriver
227232
--compare DATA{${ITK_DATA_ROOT}/Baseline/BasicFilters/OpeningByReconstructionImageFilterTest.png}
228233
${ITK_TEST_OUTPUT_DIR}/OpeningByReconstructionImageFilterTest.png
229-
itkOpeningByReconstructionImageFilterTest DATA{${ITK_DATA_ROOT}/Input/chondt.png} ${ITK_TEST_OUTPUT_DIR}/OpeningByReconstructionImageFilterTest.png 4 0 ${ITK_TEST_OUTPUT_DIR}/OpeningByReconstructionImageFilterTestSubtract.png)
234+
itkOpeningByReconstructionImageFilterTest DATA{${ITK_DATA_ROOT}/Input/chondt.png} ${ITK_TEST_OUTPUT_DIR}/OpeningByReconstructionImageFilterTest.png 4 0 0 ${ITK_TEST_OUTPUT_DIR}/OpeningByReconstructionImageFilterTestSubtract.png)
230235
itk_add_test(NAME itkOpeningByReconstructionImageFilterTest2
231236
COMMAND ITKMathematicalMorphologyTestDriver
232237
--compare DATA{${ITK_DATA_ROOT}/Baseline/BasicFilters/OpeningByReconstructionImageFilterTest2.png}
233238
${ITK_TEST_OUTPUT_DIR}/OpeningByReconstructionImageFilterTest2.png
234-
itkOpeningByReconstructionImageFilterTest DATA{${ITK_DATA_ROOT}/Input/chondt.png} ${ITK_TEST_OUTPUT_DIR}/OpeningByReconstructionImageFilterTest2.png 4 1 ${ITK_TEST_OUTPUT_DIR}/OpeningByReconstructionImageFilterTestSubtract2.png)
239+
itkOpeningByReconstructionImageFilterTest DATA{${ITK_DATA_ROOT}/Input/chondt.png} ${ITK_TEST_OUTPUT_DIR}/OpeningByReconstructionImageFilterTest2.png 4 1 0 ${ITK_TEST_OUTPUT_DIR}/OpeningByReconstructionImageFilterTestSubtract2.png)
240+
itk_add_test(NAME itkOpeningByReconstructionImageFilterTestFullyConnected
241+
COMMAND ITKMathematicalMorphologyTestDriver
242+
--compare DATA{Baseline/OpeningByReconstructionImageFilterTestFullyConnected.png}
243+
${ITK_TEST_OUTPUT_DIR}/OpeningByReconstructionImageFilterTestFullyConnected.png
244+
itkOpeningByReconstructionImageFilterTest DATA{${ITK_DATA_ROOT}/Input/chondt.png} ${ITK_TEST_OUTPUT_DIR}/OpeningByReconstructionImageFilterTestFullyConnected.png 4 1 1 ${ITK_TEST_OUTPUT_DIR}/OpeningByReconstructionImageFilterTestSubtractFullyConnected.png)
235245
itk_add_test(NAME itkOpeningByReconstructionImageFilterTestNoInput
236246
COMMAND ITKMathematicalMorphologyTestDriver
237247
--compare DATA{Baseline/OpeningByReconstructionImageFilterTestNoInput.png}
238248
${ITK_TEST_OUTPUT_DIR}/OpeningByReconstructionImageFilterTestNoInput.png
239-
itkOpeningByReconstructionImageFilterTest2 ${ITK_TEST_OUTPUT_DIR}/OpeningByReconstructionImageFilterTestNoInput.png 4 0 0 0 0.5 0.5 ${ITK_TEST_OUTPUT_DIR}/OpeningByReconstructionImageFilterTestSubtractNoInput.png)
249+
itkOpeningByReconstructionImageFilterTest2 ${ITK_TEST_OUTPUT_DIR}/OpeningByReconstructionImageFilterTestNoInput.png 4 0 0 0 0 0.5 0.5 ${ITK_TEST_OUTPUT_DIR}/OpeningByReconstructionImageFilterTestSubtractNoInput.png)
240250
itk_add_test(NAME itkOpeningByReconstructionImageFilterTestNoInput2
241251
COMMAND ITKMathematicalMorphologyTestDriver
242252
--compare DATA{Baseline/OpeningByReconstructionImageFilterTestNoInput2.png}
243253
${ITK_TEST_OUTPUT_DIR}/OpeningByReconstructionImageFilterTestNoInput2.png
244-
itkOpeningByReconstructionImageFilterTest2 ${ITK_TEST_OUTPUT_DIR}/OpeningByReconstructionImageFilterTestNoInput2.png 4 1 0 0 0.5 0.5 ${ITK_TEST_OUTPUT_DIR}/OpeningByReconstructionImageFilterTestSubtractNoInput2.png)
254+
itkOpeningByReconstructionImageFilterTest2 ${ITK_TEST_OUTPUT_DIR}/OpeningByReconstructionImageFilterTestNoInput2.png 4 1 0 0 0 0.5 0.5 ${ITK_TEST_OUTPUT_DIR}/OpeningByReconstructionImageFilterTestSubtractNoInput2.png)
245255
itk_add_test(NAME itkDoubleThresholdImageFilterTest
246256
COMMAND ITKMathematicalMorphologyTestDriver
247257
--compare DATA{${ITK_DATA_ROOT}/Baseline/BasicFilters/DoubleThresholdImageFilterTest.png}

0 commit comments

Comments
 (0)