Skip to content

Commit 89f1bca

Browse files
committed
STYLE: Address clang-tidy warnings in itkNumericTraitsTest.cxxv
Compiletime evaluated always true if statements were converted to compiletime static_asserts. Unused value settings were removed. Constant values were varied from zero to avoid warning caused by using value to select template type.
1 parent e32e05a commit 89f1bca

File tree

1 file changed

+28
-44
lines changed

1 file changed

+28
-44
lines changed

Modules/Core/Common/test/itkNumericTraitsTest.cxx

Lines changed: 28 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,6 @@ CheckSignedAndIntegerTraitsForComplexTypes(const char * const name)
259259
std::cout << "\tERROR: NumericTraits< " << name << " >::IsInteger definition is true." << std::endl;
260260
std::cout << "\tComplex types are not integers" << std::endl;
261261
}
262-
else
263-
{
264-
didTestPass = true;
265-
}
266262

267263
// IsSigned same for complex and basic types??
268264
if (itk::NumericTraits<T>::IsSigned != itk::NumericTraits<typename itk::NumericTraits<T>::ValueType>::IsSigned)
@@ -283,7 +279,6 @@ CheckSignedAndIntegerTraitsForComplexTypes(const char * const name)
283279
std::cout << "\tSUCCESS: IsSigned definition for complex type matches value of basic type" << std::endl;
284280
std::cout << "\tSigned Value for:\t< " << name << " >\tis:\t"
285281
<< (itk::NumericTraits<T>::IsSigned ? "true" : "false") << std::endl;
286-
didTestPass = true;
287282
}
288283
std::cout << std::endl;
289284
return didTestPass;
@@ -338,7 +333,7 @@ CheckAllSignedAndIntegerTraits()
338333

339334
if (didAllTestsPass)
340335
{
341-
std::cout << "SUCESS!!: All IsSigned and IsInteger tests Passed!!!" << std::endl;
336+
std::cout << "SUCCESS!!: All IsSigned and IsInteger tests Passed!!!" << std::endl;
342337
}
343338
else
344339
{
@@ -350,38 +345,27 @@ CheckAllSignedAndIntegerTraits()
350345
}
351346

352347
// Check a few types and make sure that they have the correct value for IsComplex
353-
bool
348+
void
354349
CheckIsComplexTraits()
355350
{
356-
bool didTestsPass = true;
357-
std::cout << "Testing non complex types for IsComplex trait" << std::endl;
358-
if (itk::NumericTraits<float>::IsComplex || itk::NumericTraits<double>::IsComplex ||
359-
itk::NumericTraits<char>::IsComplex || itk::NumericTraits<int>::IsComplex ||
360-
itk::NumericTraits<unsigned long>::IsComplex)
361-
{
362-
std::cout << "Test FAILED!!\n" << std::endl;
363-
std::cout << "Not all non complex types have the correct IsComplex trait" << std::endl;
364-
didTestsPass = false;
365-
}
366-
else
367-
{
368-
std::cout << "Test Passed\n" << std::endl;
369-
}
370-
371-
std::cout << "Testing complex types for IsComplex trait" << std::endl;
372-
if (!itk::NumericTraits<std::complex<float>>::IsComplex || !itk::NumericTraits<std::complex<double>>::IsComplex ||
373-
!itk::NumericTraits<std::complex<char>>::IsComplex || !itk::NumericTraits<std::complex<int>>::IsComplex ||
374-
!itk::NumericTraits<std::complex<unsigned long>>::IsComplex)
375-
{
376-
std::cout << "Test FAILED!!\n" << std::endl;
377-
std::cout << "Not all complex types have the correct IsComplex trait" << std::endl;
378-
didTestsPass = false;
379-
}
380-
else
381-
{
382-
std::cout << "Test Passed\n" << std::endl;
383-
}
384-
return didTestsPass;
351+
// Use static asserts to do compile-time testing of traits
352+
// std::cout << "Testing non complex types for IsComplex trait" << std::endl;
353+
static_assert(!itk::NumericTraits<float>::IsComplex, "float is not complex");
354+
static_assert(!itk::NumericTraits<double>::IsComplex, "double is not complex");
355+
static_assert(!itk::NumericTraits<char>::IsComplex, "char is not complex");
356+
static_assert(!itk::NumericTraits<int>::IsComplex, "int is not complex");
357+
static_assert(!itk::NumericTraits<unsigned long>::IsComplex, "unsigned long is not complex");
358+
359+
static_assert(itk::NumericTraits<std::complex<float>>::IsComplex,
360+
"std::complex<float> does not have the correct IsComplex trait");
361+
static_assert(itk::NumericTraits<std::complex<double>>::IsComplex,
362+
"std::complex<double> does not have the correct IsComplex trait");
363+
static_assert(itk::NumericTraits<std::complex<char>>::IsComplex,
364+
"std::complex<char> does not have the correct IsComplex trait");
365+
static_assert(itk::NumericTraits<std::complex<int>>::IsComplex,
366+
"std::complex<int> does not have the correct IsComplex trait");
367+
static_assert(itk::NumericTraits<std::complex<unsigned long>>::IsComplex,
368+
"std::complex<unsigned long> does not have the correct IsComplex trait");
385369
} // End CheckIsComplexTraits()
386370

387371
} // end anonymous namespace
@@ -391,13 +375,13 @@ itkNumericTraitsTest(int, char *[])
391375
{
392376
bool testPassedStatus = true;
393377

394-
CheckTraits("char", static_cast<char>(0));
395-
CheckTraits("signed char", static_cast<signed char>(0));
396-
CheckTraits("unsigned char", static_cast<unsigned char>(0));
378+
CheckTraits("char", static_cast<char>('a'));
379+
CheckTraits("signed char", static_cast<signed char>('a'));
380+
CheckTraits("unsigned char", static_cast<unsigned char>('a'));
397381

398-
CheckTraits("short", static_cast<short>(0));
399-
CheckTraits("signed short", static_cast<signed short>(0));
400-
CheckTraits("unsigned short", static_cast<unsigned short>(0));
382+
CheckTraits("short", static_cast<short>(-1));
383+
CheckTraits("signed short", static_cast<signed short>(-1));
384+
CheckTraits("unsigned short", static_cast<unsigned short>(1));
401385

402386
CheckTraits("int", static_cast<int>(0));
403387
CheckTraits("signed int", static_cast<signed int>(0));
@@ -1272,8 +1256,8 @@ itkNumericTraitsTest(int, char *[])
12721256
// check the new Integer and Signed traits
12731257
testPassedStatus &= CheckAllSignedAndIntegerTraits();
12741258

1275-
// Check IsComplex traits
1276-
testPassedStatus &= CheckIsComplexTraits();
1259+
// CompileTime Checks IsComplex traits does not return
1260+
CheckIsComplexTraits();
12771261

12781262
return (testPassedStatus) ? EXIT_SUCCESS : EXIT_FAILURE;
12791263
}

0 commit comments

Comments
 (0)