Skip to content

Commit

Permalink
STYLE: Prefer using testing macros in miscellaneous tests
Browse files Browse the repository at this point in the history
Prefer using testing macros in miscellaneous tests:
- Use the `ITK_TRY_EXPECT_EXCEPTION` macro in lieu of `try/catch` blocks
  to check for expected exceptions for the sake of readability and
  compactness, and to save typing/avoid boilerplate code.
- Use the `ITK_TEST_SET_GET_VALUE``macro to check for expected values
  for the sake of readability and compactness, and to save typing/avoid
  boilerplate code. Take advantage of the commit to make testing the
  getter methods quantitative by checking their return value.
  • Loading branch information
jhlegarreta authored and dzenanz committed Nov 8, 2023
1 parent 45583cf commit 043b068
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,8 @@ itkDiscreteGaussianCurvatureQuadEdgeMeshFilterTest(int argc, char * argv[])

auto reader = ReaderType::New();
reader->SetFileName(argv[1]);
try
{
reader->Update();
}
catch (const itk::ExceptionObject & excp)
{
std::cerr << "Exception thrown while reading the input file " << std::endl;
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
ITK_TRY_EXPECT_NO_EXCEPTION(reader->Update());


MeshType::Pointer mesh = reader->GetOutput();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,19 +180,8 @@ itkAutoScaledGradientDescentRegistrationTestTemplated(int numberOfIterat
std::cout << "GetDoEstimateLearningRateAtEachIteration: " << optimizer->GetDoEstimateLearningRateAtEachIteration()
<< std::endl;

try
{
optimizer->StartOptimization();
}
catch (const itk::ExceptionObject & e)
{
std::cout << "Exception thrown ! " << std::endl;
std::cout << "An error occurred during Optimization:" << std::endl;
std::cout << e.GetLocation() << std::endl;
std::cout << e.GetDescription() << std::endl;
std::cout << e.what() << std::endl;
return EXIT_FAILURE;
}
ITK_TRY_EXPECT_NO_EXCEPTION(optimizer->StartOptimization());


std::cout << "...finished. " << std::endl
<< "StopCondition: " << optimizer->GetStopConditionDescription() << std::endl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,9 @@ itkGradientDescentOptimizerBasev4Test(int, char *[])

/* exercise some methods */
optimizer->SetMetric(metric);
if (optimizer->GetMetric() != metric)
{
std::cerr << "Set/GetMetric failed." << std::endl;
return EXIT_FAILURE;
}
ITK_TEST_SET_GET_VALUE(metric, optimizer->GetMetric());

std::cout << "value: " << optimizer->GetCurrentMetricValue() << std::endl;
ITK_TEST_SET_GET_VALUE(0.0, optimizer->GetCurrentMetricValue());

optimizer->SetNumberOfWorkUnits(2);

Expand Down

0 comments on commit 043b068

Please sign in to comment.