Skip to content

Commit f704b5f

Browse files
jhlegarretadzenanz
authored andcommitted
ENH: Increase code coverage
Increase the code coverage: - Exercise the basic object methods using the `ITK_EXERCISE_BASIC_OBJECT_METHODS` macro. - Remove explicit calls to the `Print` method and rely on the basic method exercising macro call. Take advantage of the commit to: - Define as a constant expression the image dimensionality. - Capitalize comment sentences. in the `itkHausdorffDistanceImageFilterTest.cxx` file
1 parent b2c3042 commit f704b5f

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed

Modules/Filtering/DistanceMap/test/itkHausdorffDistanceImageFilterTest.cxx

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,16 @@
1818

1919
#include "itkHausdorffDistanceImageFilter.h"
2020
#include "itkSimpleFilterWatcher.h"
21+
#include "itkTestingMacros.h"
2122

2223
int
2324
itkHausdorffDistanceImageFilterTest(int, char *[])
2425
{
2526

27+
constexpr unsigned int ImageDimension = 3;
28+
2629
using Pixel1Type = unsigned int;
2730
using Pixel2Type = float;
28-
enum
29-
{
30-
ImageDimension = 3
31-
};
3231

3332
using Image1Type = itk::Image<Pixel1Type, ImageDimension>;
3433
using Image2Type = itk::Image<Pixel2Type, ImageDimension>;
@@ -80,8 +79,10 @@ itkHausdorffDistanceImageFilterTest(int, char *[])
8079
++it2;
8180
}
8281

83-
int exit_status = EXIT_SUCCESS; // If no failures detected, then EXIT_SUCCESS
84-
// compute the directed Hausdorff distance h(image1,image2)
82+
// If no failures detected, then EXIT_SUCCESS
83+
int exit_status = EXIT_SUCCESS;
84+
85+
// Compute the directed Hausdorff distance h(image1,image2)
8586
{
8687
using FilterType = itk::DirectedHausdorffDistanceImageFilter<Image1Type, Image2Type>;
8788
FilterType::Pointer filter = FilterType::New();
@@ -90,9 +91,8 @@ itkHausdorffDistanceImageFilterTest(int, char *[])
9091
filter->SetInput1(image1);
9192
filter->SetInput2(image2);
9293
filter->Update();
93-
filter->Print(std::cout);
9494

95-
// check results
95+
// Check results
9696
const FilterType::RealType trueDistance = 10 * std::sqrt(static_cast<double>(ImageDimension));
9797
const FilterType::RealType distance = filter->GetDirectedHausdorffDistance();
9898

@@ -111,7 +111,7 @@ itkHausdorffDistanceImageFilterTest(int, char *[])
111111
}
112112
}
113113

114-
// compute the directed Hausdorff distance h(image2,image1)
114+
// Compute the directed Hausdorff distance h(image2,image1)
115115
{
116116
using FilterType = itk::DirectedHausdorffDistanceImageFilter<Image2Type, Image1Type>;
117117
FilterType::Pointer filter = FilterType::New();
@@ -120,7 +120,7 @@ itkHausdorffDistanceImageFilterTest(int, char *[])
120120
filter->SetInput2(image1);
121121
filter->Update();
122122

123-
// check results
123+
// Check results
124124
const FilterType::RealType trueDistance = 5 * std::sqrt(static_cast<double>(ImageDimension));
125125
const FilterType::RealType distance = filter->GetDirectedHausdorffDistance();
126126

@@ -140,16 +140,19 @@ itkHausdorffDistanceImageFilterTest(int, char *[])
140140
}
141141
}
142142

143-
// compute the Hausdorff distance H(image1,image2)
143+
// Compute the Hausdorff distance H(image1,image2)
144144
{
145145
using FilterType = itk::HausdorffDistanceImageFilter<Image1Type, Image2Type>;
146146
FilterType::Pointer filter = FilterType::New();
147147

148+
ITK_EXERCISE_BASIC_OBJECT_METHODS(filter, HausdorffDistanceImageFilter, ImageToImageFilter);
149+
150+
148151
filter->SetInput1(image1);
149152
filter->SetInput2(image2);
150153
filter->Update();
151154

152-
// check results
155+
// Check results
153156
const FilterType::RealType trueDistance = 10 * std::sqrt(static_cast<double>(ImageDimension));
154157
const FilterType::RealType distance = filter->GetHausdorffDistance();
155158

@@ -169,7 +172,7 @@ itkHausdorffDistanceImageFilterTest(int, char *[])
169172
}
170173
}
171174

172-
// compute the Hausdorff distance H(image2,image1)
175+
// Compute the Hausdorff distance H(image2,image1)
173176
{
174177
using FilterType = itk::HausdorffDistanceImageFilter<Image2Type, Image1Type>;
175178
FilterType::Pointer filter = FilterType::New();
@@ -178,7 +181,7 @@ itkHausdorffDistanceImageFilterTest(int, char *[])
178181
filter->SetInput2(image1);
179182
filter->Update();
180183

181-
// check results
184+
// Check results
182185
const FilterType::RealType trueDistance = 10 * std::sqrt(static_cast<double>(ImageDimension));
183186
const FilterType::RealType distance = filter->GetHausdorffDistance();
184187

@@ -198,7 +201,7 @@ itkHausdorffDistanceImageFilterTest(int, char *[])
198201
}
199202
}
200203

201-
// compute the Hausdorff distance H(image2,image1)
204+
// Compute the Hausdorff distance H(image2,image1)
202205
{
203206
Image1Type::SpacingType spacing1 = image1->GetSpacing();
204207
spacing1[0] = spacing1[0] / 2;
@@ -210,6 +213,7 @@ itkHausdorffDistanceImageFilterTest(int, char *[])
210213
spacing2[1] = spacing2[1] / 2;
211214
spacing2[2] = spacing2[2] / 2;
212215
image2->SetSpacing(spacing2);
216+
213217
using FilterType = itk::HausdorffDistanceImageFilter<Image2Type, Image1Type>;
214218
FilterType::Pointer filter = FilterType::New();
215219

@@ -218,7 +222,7 @@ itkHausdorffDistanceImageFilterTest(int, char *[])
218222
filter->SetUseImageSpacing(true);
219223
filter->Update();
220224

221-
// check results
225+
// Check results
222226
const FilterType::RealType trueDistance =
223227
10 * std::sqrt(spacing1[0] * spacing1[0] + spacing1[1] * spacing1[1] + spacing1[2] * spacing1[2]);
224228
const FilterType::RealType trueAverageDistance = 4.5 * spacing1[0];

Modules/Nonunit/Review/test/itkScalarChanAndVeseSparseLevelSetImageFilterTest1.cxx

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

1919
#include "itkScalarChanAndVeseSparseLevelSetImageFilter.h"
20+
#include "itkTestingMacros.h"
2021

2122
int
2223
itkScalarChanAndVeseSparseLevelSetImageFilterTest1(int, char *[])
@@ -50,8 +51,10 @@ itkScalarChanAndVeseSparseLevelSetImageFilterTest1(int, char *[])
5051

5152
FilterType::Pointer filter = FilterType::New();
5253

53-
std::cout << "GetNameOfClass() = " << filter->GetNameOfClass() << std::endl;
54-
filter->Print(std::cout);
54+
ITK_EXERCISE_BASIC_OBJECT_METHODS(
55+
filter, ScalarChanAndVeseSparseLevelSetImageFilter, MultiphaseSparseFiniteDifferenceImageFilter);
5556

57+
58+
std::cout << "Test finished. " << std::endl;
5659
return EXIT_SUCCESS;
5760
}

0 commit comments

Comments
 (0)