Skip to content

Commit

Permalink
STYLE: Replace T var; var = x with T var = x for scalars in tests
Browse files Browse the repository at this point in the history
Following C++ Core Guidelines, Oct 3, 2024, "Always initialize an object",
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Res-always

Using Notepad++, Replace in Files, doing:

    Find what: ^( [ ]+)([a-z][a-z ]*[a-z])([ ]+)(\w+);[\r\n]+\1\4\ =
    Replace with: $1$2$3$4 =
    Filters: itk*Test*.*
    [v] Match case
    (*) Regular expression
  • Loading branch information
N-Dekker committed Nov 4, 2024
1 parent 17270fd commit 1666742
Show file tree
Hide file tree
Showing 27 changed files with 80 additions and 121 deletions.
3 changes: 1 addition & 2 deletions Modules/Core/Common/test/itkIteratorTests.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ itkIteratorTests(int, char *[])
start = clock();
itk::ImageRegionIterator<ScalarImage> it(o3, region);

unsigned short scalar;
scalar = 5;
unsigned short scalar = 5;

i = 0;
for (; !it.IsAtEnd(); ++it)
Expand Down
6 changes: 3 additions & 3 deletions Modules/Core/ImageAdaptors/test/itkVectorImageTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,9 @@ itkVectorImageTest(int, char * argv[])
std::cerr << "[FAILED]" << std::endl;
failed = true;
}
bool adaptorTestResult;
adaptorTestResult = testVectorImageAdaptor<PixelType, Dimension, VectorImageToImageAdaptorType, VectorLength>(
vectorImageToImageAdaptor, vectorImage, region, componentToExtract);
bool adaptorTestResult =
testVectorImageAdaptor<PixelType, Dimension, VectorImageToImageAdaptorType, VectorLength>(
vectorImageToImageAdaptor, vectorImage, region, componentToExtract);
if (adaptorTestResult)
{
failed = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -687,9 +687,7 @@ itkBSplineDeformableTransformTest3()
int
itkBSplineDeformableTransformTest(int, char *[])
{
bool failed;

failed = itkBSplineDeformableTransformTest1();
bool failed = itkBSplineDeformableTransformTest1();
if (failed)
{
return EXIT_FAILURE;
Expand Down
4 changes: 1 addition & 3 deletions Modules/Core/Transform/test/itkBSplineTransformTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -715,9 +715,7 @@ itkBSplineTransformTest3()
int
itkBSplineTransformTest(int, char *[])
{
bool failed;

failed = itkBSplineTransformTest1();
bool failed = itkBSplineTransformTest1();
if (failed)
{
return EXIT_FAILURE;
Expand Down
3 changes: 1 addition & 2 deletions Modules/Core/Transform/test/itkTestTransformGetInverse.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ TransformTest()
int
itkTestTransformGetInverse(int, char *[])
{
unsigned int errorCount;
errorCount = TransformTest<itk::AffineTransform<double, 3>>();
unsigned int errorCount = TransformTest<itk::AffineTransform<double, 3>>();
errorCount += TransformTest<itk::AzimuthElevationToCartesianTransform<double, 3>>();
errorCount += TransformTest<itk::BSplineTransform<double, 3>>();
errorCount += TransformTest<itk::CenteredAffineTransform<double, 3>>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,12 @@ constexpr int V_DEPTH = 64;
float
sphere(float x, float y, float z)
{
float dis;
dis = (x - static_cast<float>(V_WIDTH) / 2.0) * (x - static_cast<float>(V_WIDTH) / 2.0) /
((0.2f * V_WIDTH) * (0.2f * V_WIDTH)) +
(y - static_cast<float>(V_HEIGHT) / 2.0) * (y - static_cast<float>(V_HEIGHT) / 2.0) /
((0.2f * V_HEIGHT) * (0.2f * V_HEIGHT)) +
(z - static_cast<float>(V_DEPTH) / 2.0) * (z - static_cast<float>(V_DEPTH) / 2.0) /
((0.2f * V_DEPTH) * (0.2f * V_DEPTH));
float dis = (x - static_cast<float>(V_WIDTH) / 2.0) * (x - static_cast<float>(V_WIDTH) / 2.0) /
((0.2f * V_WIDTH) * (0.2f * V_WIDTH)) +
(y - static_cast<float>(V_HEIGHT) / 2.0) * (y - static_cast<float>(V_HEIGHT) / 2.0) /
((0.2f * V_HEIGHT) * (0.2f * V_HEIGHT)) +
(z - static_cast<float>(V_DEPTH) / 2.0) * (z - static_cast<float>(V_DEPTH) / 2.0) /
((0.2f * V_DEPTH) * (0.2f * V_DEPTH));
return (1.0f - dis);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,7 @@ test3DInterpolateImagePointsFilter()
using OutputIterator = itk::ImageRegionIterator<CoordImageType3D>;
InputIterator inIter(image, region);
OutputIterator outIter(outputImage, region);
double rmse;
rmse = 0.0;
double rmse = 0.0;
while (!outIter.IsAtEnd())
{
double temp = inIter.Get() - outIter.Get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ itkLabelImageToLabelMapFilterTest(int, char *[])
IndexType index;
index[0] = ctrI;
index[1] = ctrJ;
unsigned long val;
val = map->GetPixel(index);
unsigned long val = map->GetPixel(index);
std::cout << "Pixel[" << ctrI << ',' << ctrJ << "]: " << val << std::endl;
if (((ctrI == 5) || (ctrJ == 5)) && (ctrI != 7) && (ctrJ != 7))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ itkLabelMapToLabelImageFilterTest(int argc, char * argv[])
IndexType index;
index[0] = ctrI;
index[1] = ctrJ;
unsigned char val;
val = image->GetPixel(index);
unsigned char val = image->GetPixel(index);
if ((ctrI == 5) || (ctrJ == 5))
{
itkAssertOrThrowMacro((val == 1), "Error in Label Image.");
Expand Down
3 changes: 1 addition & 2 deletions Modules/Filtering/LabelMap/test/itkShiftLabelObjectTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ itkShiftLabelObjectTest(int argc, char * argv[])
IndexType index;
index[0] = ctrI;
index[1] = ctrJ;
unsigned long val;
val = map->GetPixel(index);
unsigned long val = map->GetPixel(index);
std::cout << "Pixel[" << ctrI << ',' << ctrJ << "]: " << val << std::endl;
if ((ctrI == 5) || (ctrJ == 5))
{
Expand Down
3 changes: 1 addition & 2 deletions Modules/IO/NIFTI/test/itkNiftiImageIOTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ itkNiftiImageIOTest(int argc, char * argv[])
}
else // This is the mechanism for doing internal testing of all data types.
{
int cur_return;
cur_return = MakeNiftiImage<char>(testFileName);
int cur_return = MakeNiftiImage<char>(testFileName);
if (cur_return != 0)
{
std::cerr << "Error writing Nifti file type char" << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,13 @@ itkMaximumDecisionRuleTest(int, char *[])

MembershipVectorType membershipScoreVector;

double membershipScore1;
membershipScore1 = 0.1;
double membershipScore1 = 0.1;
membershipScoreVector.push_back(membershipScore1);

double membershipScore2;
membershipScore2 = 0.5;
double membershipScore2 = 0.5;
membershipScoreVector.push_back(membershipScore2);

double membershipScore3;
membershipScore3 = 1.9;
double membershipScore3 = 1.9;
membershipScoreVector.push_back(membershipScore3);

// the maximum score is the third component. The decision rule should
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,17 @@ itkMaximumRatioDecisionRuleTest(int, char *[])

MembershipVectorType membershipScoreVector;

double membershipScore1;
membershipScore1 = 0.1;
double membershipScore1 = 0.1;
membershipScoreVector.push_back(membershipScore1);

double membershipScore2;
membershipScore2 = 0.5;
double membershipScore2 = 0.5;
membershipScoreVector.push_back(membershipScore2);

double membershipScore3;
membershipScore3 = 1.9;
double membershipScore3 = 1.9;
membershipScoreVector.push_back(membershipScore3);

// add discriminantscore with a value of zero
double membershipScore4;
membershipScore4 = 0.0;
double membershipScore4 = 0.0;
membershipScoreVector.push_back(membershipScore4);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,13 @@ itkMinimumDecisionRuleTest(int, char *[])

MembershipVectorType membershipScoreVector;

double membershipScore1;
membershipScore1 = 1.1;
double membershipScore1 = 1.1;
membershipScoreVector.push_back(membershipScore1);

double membershipScore2;
membershipScore2 = 0.5;
double membershipScore2 = 0.5;
membershipScoreVector.push_back(membershipScore2);

double membershipScore3;
membershipScore3 = 1.9;
double membershipScore3 = 1.9;
membershipScoreVector.push_back(membershipScore3);

// the minimum score is the third component. The decision rule should
Expand Down
9 changes: 3 additions & 6 deletions Modules/Numerics/Statistics/test/itkDecisionRuleTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,13 @@ itkDecisionRuleTest(int, char *[])

MembershipVectorType membershipScoreVector;

double membershipScore1;
membershipScore1 = 0.1;
double membershipScore1 = 0.1;
membershipScoreVector.push_back(membershipScore1);

double membershipScore2;
membershipScore2 = 0.5;
double membershipScore2 = 0.5;
membershipScoreVector.push_back(membershipScore2);

double membershipScore3;
membershipScore3 = 1.9;
double membershipScore3 = 1.9;
membershipScoreVector.push_back(membershipScore3);

// the maximum score is the third component. The decision rule should
Expand Down
6 changes: 2 additions & 4 deletions Modules/Numerics/Statistics/test/itkDistanceMetricTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,14 @@ class MyDistanceMetric : public DistanceMetric<TMeasurementVector>
double
Evaluate(const TMeasurementVector &) const override
{
double score;
score = 1;
double score = 1;
return score;
}

double
Evaluate(const TMeasurementVector &, const TMeasurementVector &) const override
{
double score;
score = 1;
double score = 1;
return score;
}
};
Expand Down
6 changes: 2 additions & 4 deletions Modules/Numerics/Statistics/test/itkDistanceMetricTest2.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,14 @@ class MyDistanceMetric : public DistanceMetric<TMeasurementVector>
double
Evaluate(const TMeasurementVector &) const override
{
double score;
score = 1;
double score = 1;
return score;
}

double
Evaluate(const TMeasurementVector &, const TMeasurementVector &) const override
{
double score;
score = 1;
double score = 1;
return score;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ class MyMembershipFunctionBase : public MembershipFunctionBase<TMeasurementVecto
double
Evaluate(const TMeasurementVector &) const override
{
double score;
score = 1;
double score = 1;
return score;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ class MyMembershipFunctionBase : public MembershipFunctionBase<TMeasurementVecto
double
Evaluate(const TMeasurementVector &) const override
{
double score;
score = 1;
double score = 1;
return score;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,7 @@ itkScalarImageToCooccurrenceMatrixFilterTest(int, char *[])
zero_zero[0] = 0;
zero_zero[1] = 0;

float zzF;
zzF = hist2->GetFrequency(zero_zero);
float zzF = hist2->GetFrequency(zero_zero);
totalF = hist2->GetTotalFrequency();

if (itk::Math::NotAlmostEquals(zzF, 40.0f) || itk::Math::NotAlmostEquals(zzF, totalF))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ itkSampleClassifierFilterTest7(int argc, char * argv[])
const unsigned int measurementVectorSize = sample->GetMeasurementVectorSize();
for (unsigned int j = 0; j < measurementVectorSize; ++j)
{
double temp;
temp = (components[i])->GetFullParameters()[j] - trueParameters[i][j];
double temp = (components[i])->GetFullParameters()[j] - trueParameters[i][j];
displacement += (temp * temp);
}
displacement = std::sqrt(displacement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,24 @@ constexpr int V_DEPTH = 64;
float
sphere(float x, float y, float z)
{
float dis;
dis = (x - static_cast<float>(V_WIDTH) / 2.0) * (x - static_cast<float>(V_WIDTH) / 2.0) /
((0.2f * V_WIDTH) * (0.2f * V_WIDTH)) +
(y - static_cast<float>(V_HEIGHT) / 2.0) * (y - static_cast<float>(V_HEIGHT) / 2.0) /
((0.2f * V_HEIGHT) * (0.2f * V_HEIGHT)) +
(z - static_cast<float>(V_DEPTH) / 2.0) * (z - static_cast<float>(V_DEPTH) / 2.0) /
((0.2f * V_DEPTH) * (0.2f * V_DEPTH));
float dis = (x - static_cast<float>(V_WIDTH) / 2.0) * (x - static_cast<float>(V_WIDTH) / 2.0) /
((0.2f * V_WIDTH) * (0.2f * V_WIDTH)) +
(y - static_cast<float>(V_HEIGHT) / 2.0) * (y - static_cast<float>(V_HEIGHT) / 2.0) /
((0.2f * V_HEIGHT) * (0.2f * V_HEIGHT)) +
(z - static_cast<float>(V_DEPTH) / 2.0) * (z - static_cast<float>(V_DEPTH) / 2.0) /
((0.2f * V_DEPTH) * (0.2f * V_DEPTH));
return (1.0f - dis);
}

float
sphere2(float x, float y, float z)
{
float dis;
dis = (x - static_cast<float>(V_WIDTH) / 2.1) * (x - static_cast<float>(V_WIDTH) / 2.1) /
((0.2f * V_WIDTH) * (0.2f * V_WIDTH)) +
(y - static_cast<float>(V_HEIGHT) / 2.0) * (y - static_cast<float>(V_HEIGHT) / 2.0) /
((0.2f * V_HEIGHT) * (0.2f * V_HEIGHT)) +
(z - static_cast<float>(V_DEPTH) / 2.0) * (z - static_cast<float>(V_DEPTH) / 2.0) /
((0.2f * V_DEPTH) * (0.2f * V_DEPTH));
float dis = (x - static_cast<float>(V_WIDTH) / 2.1) * (x - static_cast<float>(V_WIDTH) / 2.1) /
((0.2f * V_WIDTH) * (0.2f * V_WIDTH)) +
(y - static_cast<float>(V_HEIGHT) / 2.0) * (y - static_cast<float>(V_HEIGHT) / 2.0) /
((0.2f * V_HEIGHT) * (0.2f * V_HEIGHT)) +
(z - static_cast<float>(V_DEPTH) / 2.0) * (z - static_cast<float>(V_DEPTH) / 2.0) /
((0.2f * V_DEPTH) * (0.2f * V_DEPTH));
return (1.0f - dis);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,24 @@ constexpr int V_DEPTH = 64;
float
sphere(float x, float y, float z)
{
float dis;
dis = (x - static_cast<float>(V_WIDTH) / 2.0) * (x - static_cast<float>(V_WIDTH) / 2.0) /
((0.2f * V_WIDTH) * (0.2f * V_WIDTH)) +
(y - static_cast<float>(V_HEIGHT) / 2.0) * (y - static_cast<float>(V_HEIGHT) / 2.0) /
((0.2f * V_HEIGHT) * (0.2f * V_HEIGHT)) +
(z - static_cast<float>(V_DEPTH) / 2.0) * (z - static_cast<float>(V_DEPTH) / 2.0) /
((0.2f * V_DEPTH) * (0.2f * V_DEPTH));
float dis = (x - static_cast<float>(V_WIDTH) / 2.0) * (x - static_cast<float>(V_WIDTH) / 2.0) /
((0.2f * V_WIDTH) * (0.2f * V_WIDTH)) +
(y - static_cast<float>(V_HEIGHT) / 2.0) * (y - static_cast<float>(V_HEIGHT) / 2.0) /
((0.2f * V_HEIGHT) * (0.2f * V_HEIGHT)) +
(z - static_cast<float>(V_DEPTH) / 2.0) * (z - static_cast<float>(V_DEPTH) / 2.0) /
((0.2f * V_DEPTH) * (0.2f * V_DEPTH));
return (1.0f - dis);
}

float
sphere2(float x, float y, float z)
{
float dis;
dis = (x - static_cast<float>(V_WIDTH) / 2.1) * (x - static_cast<float>(V_WIDTH) / 2.1) /
((0.2f * V_WIDTH) * (0.2f * V_WIDTH)) +
(y - static_cast<float>(V_HEIGHT) / 2.0) * (y - static_cast<float>(V_HEIGHT) / 2.0) /
((0.2f * V_HEIGHT) * (0.2f * V_HEIGHT)) +
(z - static_cast<float>(V_DEPTH) / 2.0) * (z - static_cast<float>(V_DEPTH) / 2.0) /
((0.2f * V_DEPTH) * (0.2f * V_DEPTH));
float dis = (x - static_cast<float>(V_WIDTH) / 2.1) * (x - static_cast<float>(V_WIDTH) / 2.1) /
((0.2f * V_WIDTH) * (0.2f * V_WIDTH)) +
(y - static_cast<float>(V_HEIGHT) / 2.0) * (y - static_cast<float>(V_HEIGHT) / 2.0) /
((0.2f * V_HEIGHT) * (0.2f * V_HEIGHT)) +
(z - static_cast<float>(V_DEPTH) / 2.0) * (z - static_cast<float>(V_DEPTH) / 2.0) /
((0.2f * V_DEPTH) * (0.2f * V_DEPTH));
return (1.0f - dis);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ const unsigned int WIDTH = (256);
float
circle(unsigned int x, unsigned int y)
{
float dis;
dis = (x - static_cast<float>(WIDTH) / 2.0) * (x - static_cast<float>(WIDTH) / 2.0) +
(y - static_cast<float>(HEIGHT) / 2.0) * (y - static_cast<float>(HEIGHT) / 2.0);
float dis = (x - static_cast<float>(WIDTH) / 2.0) * (x - static_cast<float>(WIDTH) / 2.0) +
(y - static_cast<float>(HEIGHT) / 2.0) * (y - static_cast<float>(HEIGHT) / 2.0);
dis = RADIUS - std::sqrt(dis);
return dis;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,12 @@ constexpr int V_DEPTH = 64;
float
sphere(float x, float y, float z)
{
float dis;
dis = (x - static_cast<float>(V_WIDTH) / 2.0) * (x - static_cast<float>(V_WIDTH) / 2.0) /
((0.2f * V_WIDTH) * (0.2f * V_WIDTH)) +
(y - static_cast<float>(V_HEIGHT) / 2.0) * (y - static_cast<float>(V_HEIGHT) / 2.0) /
((0.2f * V_HEIGHT) * (0.2f * V_HEIGHT)) +
(z - static_cast<float>(V_DEPTH) / 2.0) * (z - static_cast<float>(V_DEPTH) / 2.0) /
((0.2f * V_DEPTH) * (0.2f * V_DEPTH));
float dis = (x - static_cast<float>(V_WIDTH) / 2.0) * (x - static_cast<float>(V_WIDTH) / 2.0) /
((0.2f * V_WIDTH) * (0.2f * V_WIDTH)) +
(y - static_cast<float>(V_HEIGHT) / 2.0) * (y - static_cast<float>(V_HEIGHT) / 2.0) /
((0.2f * V_HEIGHT) * (0.2f * V_HEIGHT)) +
(z - static_cast<float>(V_DEPTH) / 2.0) * (z - static_cast<float>(V_DEPTH) / 2.0) /
((0.2f * V_DEPTH) * (0.2f * V_DEPTH));
return (1.0f - dis);
}

Expand Down
Loading

0 comments on commit 1666742

Please sign in to comment.