Skip to content

Commit

Permalink
ENH: Increase coverage for miscellaneous classes
Browse files Browse the repository at this point in the history
Increase coverage for miscellaneous classes:
- Exercise the basic object methods using the
  `ITK_EXERCISE_BASIC_OBJECT_METHODS` macro.
- Test the Set/Get methods using the `ITK_TEST_SET_GET_VALUE` macro.
- Use other testing macros to check the expected value of a number of
  ivars and method return values.
- Test exceptions using the `ITK_TRY_EXPECT_EXCEPTION` macro.
- Remove explicit calls to the `Print` method and rely on the basic
  method exercising macro call.
  • Loading branch information
jhlegarreta authored and hjmjohnson committed Jan 16, 2022
1 parent 4db7880 commit e2511e7
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,17 @@ itkRayCastInterpolateImageFunctionTest(int itkNotUsed(argc), char * itkNotUsed(a
ITK_TEST_SET_GET_VALUE(threshold, interp->GetThreshold());

/* Evaluate the function */
double integral;
double integral;


// Evaluate the ray casting function at the same point as the focal point:
// - Allows to increase coverage.
// - Makes the ray be invalid.
// - Sets the traversal direction to TraversalDirectionEnum::UNDEFINED_DIRECTION
// - The integral should equal to 0.
integral = interp->Evaluate(focus);
ITK_TEST_EXPECT_TRUE(itk::Math::FloatAlmostEqual(integral, 0.0));

PointType query;
query[0] = 15.;
query[1] = 15.;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,11 @@ itkImageToHistogramFilterTest(int, char *[])
itk::SimpleFilterWatcher watcher(filter, "filter");

ITK_EXERCISE_BASIC_OBJECT_METHODS(filter, ImageToHistogramFilter, ImageSink);
// Exercise the method NameOfClass();
std::cout << filter->GetNameOfClass() << std::endl;


unsigned int numberOfStreamDivisions = 1;
filter->SetNumberOfStreamDivisions(numberOfStreamDivisions);
ITK_TEST_SET_GET_VALUE(numberOfStreamDivisions, filter->GetNumberOfStreamDivisions());

// Testing the settings of the BinMaximum and BinMinimum methods.
HistogramMeasurementVectorType histogramBinMinimum1(MeasurementVectorSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*
*=========================================================================*/
#include "itkMultiLabelSTAPLEImageFilter.h"
#include "itkTestingMacros.h"

int
itkMultiLabelSTAPLEImageFilterTest(int, char *[])
Expand Down Expand Up @@ -118,6 +119,8 @@ itkMultiLabelSTAPLEImageFilterTest(int, char *[])
// Create an LabelVoting Filter
myFilterTypePointer filter = myFilterType::New();

ITK_EXERCISE_BASIC_OBJECT_METHODS(filter, MultiLabelSTAPLEImageFilter, ImageToImageFilter);

// Get the Smart Pointer to the Filter Output
myImageTypePointer outputImage = filter->GetOutput();

Expand All @@ -127,19 +130,54 @@ itkMultiLabelSTAPLEImageFilterTest(int, char *[])
filter->SetInput(0, inputImageA);
filter->SetInput(1, inputImageB);

ITK_TEST_EXPECT_TRUE(!filter->GetHasMaximumNumberOfIterations());

unsigned int maximumNumberOfIterations = 0;
filter->SetMaximumNumberOfIterations(maximumNumberOfIterations);
ITK_TEST_SET_GET_VALUE(maximumNumberOfIterations, filter->GetMaximumNumberOfIterations());

ITK_TEST_EXPECT_TRUE(filter->GetHasMaximumNumberOfIterations());

ITK_TEST_EXPECT_TRUE(!filter->GetHasLabelForUndecidedPixels());

typename myFilterType::WeightsType terminationUpdateThreshold = 1e-5;
filter->SetTerminationUpdateThreshold(terminationUpdateThreshold);
ITK_TEST_SET_GET_VALUE(terminationUpdateThreshold, filter->GetTerminationUpdateThreshold());

// Set label for undecided pixels
filter->SetLabelForUndecidedPixels(255);
typename myFilterType::OutputPixelType labelForUndecidedPixels = 255;
filter->SetLabelForUndecidedPixels(labelForUndecidedPixels);
ITK_TEST_SET_GET_VALUE(labelForUndecidedPixels, filter->GetLabelForUndecidedPixels());

ITK_TEST_EXPECT_TRUE(filter->GetHasLabelForUndecidedPixels());

ITK_TEST_EXPECT_TRUE(!filter->GetHasPriorProbabilities());

typename myFilterType::PriorProbabilitiesType::ValueType priorProbabilitiesVal(0.0);
typename myFilterType::PriorProbabilitiesType priorProbabilities(1);
priorProbabilities.Fill(priorProbabilitiesVal);
filter->SetPriorProbabilities(priorProbabilities);
ITK_TEST_SET_GET_VALUE(priorProbabilities, filter->GetPriorProbabilities());

ITK_TEST_EXPECT_TRUE(filter->GetHasPriorProbabilities());

ITK_TRY_EXPECT_EXCEPTION(filter->Update());


filter->UnsetPriorProbabilities();

// Execute the filter
filter->Update();
ITK_TRY_EXPECT_NO_EXCEPTION(filter->Update());

std::cout << "ElapsedNumberOfIterations: " << filter->GetElapsedNumberOfIterations() << std::endl;

// compare to correct results
it = myIteratorType(outputImage, outputImage->GetBufferedRegion());
for (unsigned int i = 0; i < 8; ++i, ++it)
{
if (combinationABundecided255[i] != it.Get())
{
std::cout << "Incorrect result using images A,B and undecided=255: "
std::cout << "Incorrect result using images A,B and undecided=" << labelForUndecidedPixels << ": "
<< "i = " << i << ", correct = " << combinationABundecided255[i] << ", got = " << it.Get() << "\n";
return EXIT_FAILURE;
}
Expand Down Expand Up @@ -185,7 +223,6 @@ itkMultiLabelSTAPLEImageFilterTest(int, char *[])
}
}

filter->Print(std::cout, 3);

std::cout << "Prior probabilities: " << filter->GetPriorProbabilities() << std::endl;
std::cout << "Confusion matrix 0 " << std::endl << filter->GetConfusionMatrix(0) << std::endl;
Expand Down

0 comments on commit e2511e7

Please sign in to comment.