Skip to content

Commit

Permalink
STYLE: Replace (*p).member with p->member in unit tests
Browse files Browse the repository at this point in the history
Simplified code of unit tests ("itk*Test.cxx" files) by using the arrow
operator, instead of using parentheses, asterisk and dot operators.
  • Loading branch information
N-Dekker authored and hjmjohnson committed Jul 31, 2022
1 parent d90e635 commit 8aa5bd4
Show file tree
Hide file tree
Showing 16 changed files with 215 additions and 220 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,19 @@ itkVtkConnectedComponentImageFilterTest(int argc, char * argv[])
auto it = filterContainer.begin();
for (it = filterContainer.begin(); it != filterContainer.end(); ++it)
{
(*it).second->SetInsideValue(255);
(*it).second->SetOutsideValue(0);
(*it).second->SetNumberOfHistogramBins(256);
(*it).second->SetInput(reader->GetOutput());
(*it).second->Update();
it->second->SetInsideValue(255);
it->second->SetOutsideValue(0);
it->second->SetNumberOfHistogramBins(256);
it->second->SetInput(reader->GetOutput());
it->second->Update();

auto connected = ConnectedComponentImageFilterType::New();
connected->SetInput((*it).second->GetOutput());
connected->SetInput(it->second->GetOutput());

auto rgbFilter = RGBFilterType::New();
rgbFilter->SetInput(connected->GetOutput());
std::stringstream desc;
desc << (*it).first << " threshold = " << (*it).second->GetThreshold();
desc << it->first << " threshold = " << it->second->GetThreshold();
viewer.AddRGBImage(rgbFilter->GetOutput(), true, desc.str());
}

Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/test/itkNeighborhoodAlgorithmTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ImageBoundaryFaceCalculatorTest(TImage * image,
{
std::cout << "Number of pixels : " << fit->GetNumberOfPixels() << std::endl;
std::cout << *fit << std::endl;
if (!region.IsInside(*fit) && (*fit).GetNumberOfPixels() > 0)
if (!region.IsInside(*fit) && fit->GetNumberOfPixels() > 0)
{
std::cerr << "face region is outside of requestToProcessRegion " << std::endl;
return false;
Expand Down
8 changes: 4 additions & 4 deletions Modules/Core/Common/test/itkSparseFieldLayerTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ itkSparseFieldLayerTest(int, char *[])
i = 3999;
while (cit != layer->End())
{
if ((*cit).value != i || cit->value != i)
if (cit->value != i || cit->value != i)
return EXIT_FAILURE;
++cit;
--i;
Expand All @@ -77,10 +77,10 @@ itkSparseFieldLayerTest(int, char *[])
i = 3999;
while (it != layer->End())
{
if ((*it).value != i || it->value != i)
if (it->value != i || it->value != i)
return EXIT_FAILURE;
(*it).value = 32567;
if ((*it).value != 32567 || it->value != 32567)
it->value = 32567;
if (it->value != 32567 || it->value != 32567)
return EXIT_FAILURE;
++it;
--i;
Expand Down
10 changes: 5 additions & 5 deletions Modules/Core/SpatialObjects/test/itkBlobSpatialObjectTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ itkBlobSpatialObjectTest(int, char *[])
{
for (unsigned int d = 0; d < 3; ++d)
{
if (itk::Math::NotExactlyEquals((*it).GetPositionInObjectSpace()[d], i + d))
if (itk::Math::NotExactlyEquals(it->GetPositionInObjectSpace()[d], i + d))
{
std::cout << "[FAILED]" << std::endl;
return EXIT_FAILURE;
Expand Down Expand Up @@ -139,24 +139,24 @@ itkBlobSpatialObjectTest(int, char *[])
{
for (unsigned int d = 0; d < 3; ++d)
{
if (itk::Math::NotExactlyEquals((*it).GetBlue(), i))
if (itk::Math::NotExactlyEquals(it->GetBlue(), i))
{
std::cout << "[FAILED]" << std::endl;
return EXIT_FAILURE;
}
if (itk::Math::NotExactlyEquals((*it).GetGreen(), i + 1))
if (itk::Math::NotExactlyEquals(it->GetGreen(), i + 1))
{
std::cout << "[FAILED]" << std::endl;
return EXIT_FAILURE;
}

if (itk::Math::NotExactlyEquals((*it).GetRed(), i + 2))
if (itk::Math::NotExactlyEquals(it->GetRed(), i + 2))
{
std::cout << "[FAILED]" << std::endl;
return EXIT_FAILURE;
}

if (itk::Math::NotExactlyEquals((*it).GetAlpha(), i + 3))
if (itk::Math::NotExactlyEquals(it->GetAlpha(), i + 3))
{
std::cout << "[FAILED]" << std::endl;
return EXIT_FAILURE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ itkCastSpatialObjectFilterTest(int, char *[])

std::unique_ptr<TubeListType> tList(caster->GetTubes());

TubeType::Pointer tListTube = (*tList).begin()->GetPointer();
TubeType::Pointer tListTube = tList->begin()->GetPointer();

bool found = false;
if (!strcmp(tListTube->GetTypeName().c_str(), "TubeSpatialObject"))
Expand All @@ -88,9 +88,9 @@ itkCastSpatialObjectFilterTest(int, char *[])
{
for (unsigned int d = 0; d < 3; ++d)
{
if (itk::Math::NotAlmostEquals((*pnt).GetPositionInWorldSpace()[d], value * tListTube->GetId()))
if (itk::Math::NotAlmostEquals(pnt->GetPositionInWorldSpace()[d], value * tListTube->GetId()))
{
std::cout << " [FAILED] (Position is: " << (*pnt).GetPositionInWorldSpace()[d]
std::cout << " [FAILED] (Position is: " << pnt->GetPositionInWorldSpace()[d]
<< " expected : " << value * tListTube->GetId() << " ) " << std::endl;
return EXIT_FAILURE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ itkLandmarkSpatialObjectTest(int, char *[])
{
for (unsigned int d = 0; d < 3; ++d)
{
if (itk::Math::NotExactlyEquals((*it).GetPositionInObjectSpace()[d], i + d))
if (itk::Math::NotExactlyEquals(it->GetPositionInObjectSpace()[d], i + d))
{
std::cout << "[FAILED]" << std::endl;
return EXIT_FAILURE;
Expand Down Expand Up @@ -133,24 +133,24 @@ itkLandmarkSpatialObjectTest(int, char *[])
{
for (unsigned int d = 0; d < 3; ++d)
{
if (itk::Math::NotExactlyEquals((*it).GetBlue(), i))
if (itk::Math::NotExactlyEquals(it->GetBlue(), i))
{
std::cout << "[FAILED]" << std::endl;
return EXIT_FAILURE;
}
if (itk::Math::NotExactlyEquals((*it).GetGreen(), i + 1))
if (itk::Math::NotExactlyEquals(it->GetGreen(), i + 1))
{
std::cout << "[FAILED]" << std::endl;
return EXIT_FAILURE;
}

if (itk::Math::NotExactlyEquals((*it).GetRed(), i + 2))
if (itk::Math::NotExactlyEquals(it->GetRed(), i + 2))
{
std::cout << "[FAILED]" << std::endl;
return EXIT_FAILURE;
}

if (itk::Math::NotExactlyEquals((*it).GetAlpha(), i + 3))
if (itk::Math::NotExactlyEquals(it->GetAlpha(), i + 3))
{
std::cout << "[FAILED]" << std::endl;
return EXIT_FAILURE;
Expand Down
6 changes: 3 additions & 3 deletions Modules/Core/SpatialObjects/test/itkLineSpatialObjectTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,19 @@ itkLineSpatialObjectTest(int, char *[])
{
for (unsigned int d = 0; d < 3; ++d)
{
if (itk::Math::NotExactlyEquals((*it).GetPositionInWorldSpace()[d], i + d))
if (itk::Math::NotExactlyEquals(it->GetPositionInWorldSpace()[d], i + d))
{
std::cout << "[FAILED]" << std::endl;
return EXIT_FAILURE;
}

if (itk::Math::NotExactlyEquals(((*it).GetNormalInObjectSpace(0))[d], d))
if (itk::Math::NotExactlyEquals((it->GetNormalInObjectSpace(0))[d], d))
{
std::cout << "[FAILED]" << std::endl;
return EXIT_FAILURE;
}

if (itk::Math::NotExactlyEquals(((*it).GetNormalInObjectSpace(1))[d], 2 * d))
if (itk::Math::NotExactlyEquals((it->GetNormalInObjectSpace(1))[d], 2 * d))
{
std::cout << "[FAILED]" << std::endl;
return EXIT_FAILURE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ itkNewMetaObjectTypeTest(int, char *[])
delete mySceneChildren;
return EXIT_FAILURE;
}
DummyType::Pointer p = dynamic_cast<DummyType *>((*obj).GetPointer());
DummyType::Pointer p = dynamic_cast<DummyType *>(obj->GetPointer());
if (p.IsNull())
{
std::cout << "Unable to downcast child SpatialObject to DummySpatialObject"
Expand Down
50 changes: 25 additions & 25 deletions Modules/Core/SpatialObjects/test/itkSpatialObjectDuplicatorTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -130,83 +130,83 @@ itkSpatialObjectDuplicatorTest(int, char *[])
{
for (unsigned int d = 0; d < 3; ++d)
{
if (itk::Math::NotAlmostEquals((*jdti).GetPositionInWorldSpace()[d], value * dtiTube_copy->GetId()))
if (itk::Math::NotAlmostEquals(jdti->GetPositionInWorldSpace()[d], value * dtiTube_copy->GetId()))
{
std::cout << " [FAILED] (Position is: " << (*jdti).GetPositionInWorldSpace()[d]
std::cout << " [FAILED] (Position is: " << jdti->GetPositionInWorldSpace()[d]
<< " expected : " << value * dtiTube_copy->GetId() << " ) " << std::endl;
return EXIT_FAILURE;
}
}
// Testing the color of the tube points
if (itk::Math::NotExactlyEquals((*jdti).GetRed(), value))
if (itk::Math::NotExactlyEquals(jdti->GetRed(), value))
{
std::cout << " [FAILED] : RGBColormapFilterEnum::Red : found " << (*jdti).GetRed() << " instead of " << value
std::cout << " [FAILED] : RGBColormapFilterEnum::Red : found " << jdti->GetRed() << " instead of " << value
<< std::endl;
return EXIT_FAILURE;
}

if (itk::Math::NotExactlyEquals((*jdti).GetGreen(), value + 1))
if (itk::Math::NotExactlyEquals(jdti->GetGreen(), value + 1))
{
std::cout << " [FAILED] : RGBColormapFilterEnum::Green : found " << (*jdti).GetGreen() << " instead of "
std::cout << " [FAILED] : RGBColormapFilterEnum::Green : found " << jdti->GetGreen() << " instead of "
<< value + 1 << std::endl;
return EXIT_FAILURE;
}

if (itk::Math::NotExactlyEquals((*jdti).GetBlue(), value + 2))
if (itk::Math::NotExactlyEquals(jdti->GetBlue(), value + 2))
{
std::cout << "[FAILED] : RGBColormapFilterEnum::Blue : found " << (*jdti).GetBlue() << " instead of "
<< value + 2 << std::endl;
std::cout << "[FAILED] : RGBColormapFilterEnum::Blue : found " << jdti->GetBlue() << " instead of " << value + 2
<< std::endl;
return EXIT_FAILURE;
}

if (itk::Math::NotExactlyEquals((*jdti).GetAlpha(), value + 3))
if (itk::Math::NotExactlyEquals(jdti->GetAlpha(), value + 3))
{
std::cout << " [FAILED] : Alpha : found " << (*jdti).GetAlpha() << " instead of " << value + 3 << std::endl;
std::cout << " [FAILED] : Alpha : found " << jdti->GetAlpha() << " instead of " << value + 3 << std::endl;
return EXIT_FAILURE;
}

if (itk::Math::NotExactlyEquals(
(*jdti).GetField(itk::DTITubeSpatialObjectPointEnums::DTITubeSpatialObjectPointField::FA), value))
jdti->GetField(itk::DTITubeSpatialObjectPointEnums::DTITubeSpatialObjectPointField::FA), value))
{
std::cout << " [FAILED] : FA : found " << (*jdti).GetField("FA") << " instead of " << value << std::endl;
std::cout << " [FAILED] : FA : found " << jdti->GetField("FA") << " instead of " << value << std::endl;
return EXIT_FAILURE;
}
if (itk::Math::NotExactlyEquals(
(*jdti).GetField(itk::DTITubeSpatialObjectPointEnums::DTITubeSpatialObjectPointField::ADC), value * 2))
jdti->GetField(itk::DTITubeSpatialObjectPointEnums::DTITubeSpatialObjectPointField::ADC), value * 2))
{
std::cout << " [FAILED] : ADC : found " << (*jdti).GetField("ADC") << " instead of " << value * 2 << std::endl;
std::cout << " [FAILED] : ADC : found " << jdti->GetField("ADC") << " instead of " << value * 2 << std::endl;
return EXIT_FAILURE;
}
if (itk::Math::NotExactlyEquals(
(*jdti).GetField(itk::DTITubeSpatialObjectPointEnums::DTITubeSpatialObjectPointField::GA), value * 3))
jdti->GetField(itk::DTITubeSpatialObjectPointEnums::DTITubeSpatialObjectPointField::GA), value * 3))
{
std::cout << " [FAILED] : GA : found " << (*jdti).GetField("FA") << " instead of " << value * 3 << std::endl;
std::cout << " [FAILED] : GA : found " << jdti->GetField("FA") << " instead of " << value * 3 << std::endl;
return EXIT_FAILURE;
}
if (itk::Math::NotExactlyEquals((*jdti).GetField("Lambda1"), value * 4))
if (itk::Math::NotExactlyEquals(jdti->GetField("Lambda1"), value * 4))
{
std::cout << " [FAILED] : GetLambda1 : found " << (*jdti).GetField("Lambda1") << " instead of " << value * 4
std::cout << " [FAILED] : GetLambda1 : found " << jdti->GetField("Lambda1") << " instead of " << value * 4
<< std::endl;
return EXIT_FAILURE;
}
if (itk::Math::NotExactlyEquals((*jdti).GetField("Lambda2"), value * 5))
if (itk::Math::NotExactlyEquals(jdti->GetField("Lambda2"), value * 5))
{
std::cout << " [FAILED] : GetLambda2 : found " << (*jdti).GetField("Lambda2") << " instead of " << value * 5
std::cout << " [FAILED] : GetLambda2 : found " << jdti->GetField("Lambda2") << " instead of " << value * 5
<< std::endl;
return EXIT_FAILURE;
}
if (itk::Math::NotExactlyEquals((*jdti).GetField("Lambda3"), value * 6))
if (itk::Math::NotExactlyEquals(jdti->GetField("Lambda3"), value * 6))
{
std::cout << " [FAILED] : GetLambda3 : found " << (*jdti).GetField("Lambda3") << " instead of " << value * 6
std::cout << " [FAILED] : GetLambda3 : found " << jdti->GetField("Lambda3") << " instead of " << value * 6
<< std::endl;
return EXIT_FAILURE;
}
int ind;
for (ind = 0; ind < 6; ++ind)
{
if (itk::Math::NotExactlyEquals((*jdti).GetTensorMatrix()[ind], ind))
if (itk::Math::NotExactlyEquals(jdti->GetTensorMatrix()[ind], ind))
{
std::cout << " [FAILED] : GetTensorMatrix : found " << (*jdti).GetTensorMatrix()[ind] << " instead of " << ind
std::cout << " [FAILED] : GetTensorMatrix : found " << jdti->GetTensorMatrix()[ind] << " instead of " << ind
<< std::endl;
return EXIT_FAILURE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,19 @@ itkSurfaceSpatialObjectTest(int, char *[])
{
for (unsigned int d = 0; d < 3; ++d)
{
if (itk::Math::NotExactlyEquals((*it).GetPositionInWorldSpace()[d], i + d))
if (itk::Math::NotExactlyEquals(it->GetPositionInWorldSpace()[d], i + d))
{
std::cout << "[FAILED]" << std::endl;
return EXIT_FAILURE;
}

if (itk::Math::NotExactlyEquals((*it).GetNormalInObjectSpace()[d], d))
if (itk::Math::NotExactlyEquals(it->GetNormalInObjectSpace()[d], d))
{
std::cout << "[FAILED]" << std::endl;
return EXIT_FAILURE;
}

if (itk::Math::NotExactlyEquals((*it).GetNormalInWorldSpace()[d], d))
if (itk::Math::NotExactlyEquals(it->GetNormalInWorldSpace()[d], d))
{
std::cout << "[FAILED]" << std::endl;
return EXIT_FAILURE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ LabelOverlapMeasures(int, char * argv[])
int label = 0;
for (it = labelMap.begin(); it != labelMap.end(); ++it)
{
if ((*it).first == 0)
if (it->first == 0)
{
continue;
}

label = (*it).first;
label = it->first;

std::cout << std::setw(10) << label;
std::cout << std::setw(17) << filter->GetTargetOverlap(label);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ itkArchetypeSeriesFileNamesTest(int argc, char * argv[])
std::cout << "List of returned filenames: " << std::endl;
for (nit = names.begin(); nit != names.end(); ++nit)
{
std::cout << "File: " << (*nit).c_str() << std::endl;
std::cout << "File: " << nit->c_str() << std::endl;
}

std::cout << fit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ itkNumericSeriesFileNamesTest(int, char *[])
<< " and may have been truncated." << std::endl;
return EXIT_FAILURE;
}
std::cout << "File: " << (*nit).c_str() << std::endl;
std::cout << "File: " << nit->c_str() << std::endl;
}

// Exercise the PrintSelf method to print the filenames for coverage purposes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ itkRegularExpressionSeriesFileNamesTest(int argc, char * argv[])
std::cout << "Normal Sort--------" << std::endl;
for (nit = names.begin(); nit != names.end(); ++nit)
{
std::cout << "File: " << (*nit).c_str() << std::endl;
std::cout << "File: " << nit->c_str() << std::endl;
}

// Show only those files with numbers in the names
Expand All @@ -73,7 +73,7 @@ itkRegularExpressionSeriesFileNamesTest(int argc, char * argv[])
std::cout << "Numeric sort on only files with numbers in the names--------" << std::endl;
for (nit = names.begin(); nit != names.end(); ++nit)
{
std::cout << "File: " << (*nit).c_str() << std::endl;
std::cout << "File: " << nit->c_str() << std::endl;
}


Expand All @@ -92,7 +92,7 @@ itkRegularExpressionSeriesFileNamesTest(int argc, char * argv[])
<< std::endl;
for (nit = names.begin(); nit != names.end(); ++nit)
{
std::cout << "File: " << (*nit).c_str() << std::endl;
std::cout << "File: " << nit->c_str() << std::endl;
}

// Show only those files with numbers in the names followed by other
Expand All @@ -109,7 +109,7 @@ itkRegularExpressionSeriesFileNamesTest(int argc, char * argv[])
<< std::endl;
for (nit = names.begin(); nit != names.end(); ++nit)
{
std::cout << "File: " << (*nit).c_str() << std::endl;
std::cout << "File: " << nit->c_str() << std::endl;
}


Expand Down
Loading

0 comments on commit 8aa5bd4

Please sign in to comment.