Skip to content

Commit d7bdae9

Browse files
authored
Merge pull request InsightSoftwareConsortium#5897 from hjmjohnson/convert-itkfixedarraytest-to-gtest
ENH: Convert itkFixedArrayTest to GTest
2 parents 005e9b2 + a9c0fba commit d7bdae9

3 files changed

Lines changed: 59 additions & 181 deletions

File tree

Modules/Core/Common/test/CMakeLists.txt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ set(
144144
itkMinimumMaximumImageCalculatorTest.cxx
145145
itkSliceIteratorTest.cxx
146146
itkImageRegionExclusionIteratorWithIndexTest.cxx
147-
itkFixedArrayTest.cxx
148147
itkImageTransformTest.cxx
149148
itkImageFillBufferTest.cxx
150149
itkMemoryLeakTest.cxx
@@ -385,12 +384,6 @@ itk_add_test(
385384
itkMultipleLogOutputTest
386385
${TEMP}/test_multi.txt
387386
)
388-
itk_add_test(
389-
NAME itkFixedArrayTest
390-
COMMAND
391-
ITKCommon2TestDriver
392-
itkFixedArrayTest
393-
)
394387
itk_add_test(
395388
NAME itkImageTransformTest
396389
COMMAND

Modules/Core/Common/test/itkFixedArrayGTest.cxx

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,3 +377,62 @@ TEST(FixedArray, CheckFrontAndBack)
377377
itk::RangeGTestUtilities::CheckFrontAndBack(itk::FixedArray<int>({ 0, 1, 2 }));
378378
itk::RangeGTestUtilities::CheckFrontAndBack(itk::FixedArray<double>::Filled(std::numeric_limits<double>::max()));
379379
}
380+
381+
382+
// Tests interop with c-style arrays, equality, Set/GetElement, and various index types.
383+
TEST(FixedArray, CArrayInteropAndIndexTypes)
384+
{
385+
// Explicit instantiation to ensure all methods are compiled.
386+
(void)itk::FixedArray<float, 3>{};
387+
388+
// Test equality operators
389+
constexpr itk::FixedArray<int, 3> array4{};
390+
EXPECT_EQ(array4, array4);
391+
EXPECT_FALSE(array4 != array4);
392+
393+
// Test Set/GetElement
394+
constexpr unsigned int n{ 20 };
395+
itk::FixedArray<unsigned int, n> array20;
396+
for (unsigned int i = 0; i < n; ++i)
397+
{
398+
array20.SetElement(i, i);
399+
}
400+
for (unsigned int k = 0; k < n; ++k)
401+
{
402+
EXPECT_EQ(array20.GetElement(k), k);
403+
}
404+
405+
// Test various index types (const access)
406+
#define TRY_INDEX_CONST(T) \
407+
{ \
408+
T in = 10; \
409+
EXPECT_EQ(array20[in], 10u); \
410+
} \
411+
ITK_MACROEND_NOOP_STATEMENT
412+
413+
TRY_INDEX_CONST(short);
414+
TRY_INDEX_CONST(unsigned short);
415+
TRY_INDEX_CONST(int);
416+
TRY_INDEX_CONST(unsigned int);
417+
TRY_INDEX_CONST(long);
418+
TRY_INDEX_CONST(unsigned long);
419+
TRY_INDEX_CONST(long long);
420+
TRY_INDEX_CONST(unsigned long long);
421+
422+
// Test various index types (non-const access)
423+
#define TRY_INDEX(T) \
424+
{ \
425+
T in = 10; \
426+
array20[in] = 10; \
427+
} \
428+
ITK_MACROEND_NOOP_STATEMENT
429+
430+
TRY_INDEX(short);
431+
TRY_INDEX(unsigned short);
432+
TRY_INDEX(int);
433+
TRY_INDEX(unsigned int);
434+
TRY_INDEX(long);
435+
TRY_INDEX(unsigned long);
436+
TRY_INDEX(long long);
437+
TRY_INDEX(unsigned long long);
438+
}

Modules/Core/Common/test/itkFixedArrayTest.cxx

Lines changed: 0 additions & 174 deletions
This file was deleted.

0 commit comments

Comments
 (0)