Skip to content

Commit 905c9f9

Browse files
committed
ENH: Add GTest unit test FrequencyIterators, AreConstructedAtBegin
- Follow-up to pull request InsightSoftwareConsortium#4815 commit 66e6d8b "ENH: Add GoogleTest unit test `ImageRegionIterator.IsConstructedAtBegin`"
1 parent 9eb1359 commit 905c9f9

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

Modules/Filtering/ImageFrequency/test/itkFrequencyIteratorsGTest.cxx

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@
2727
#include "itkFFTShiftImageFilter.h"
2828
#include "itkFrequencyBandImageFilter.h" // Simplest of frequency filters for testing
2929
#include "itkFrequencyFFTLayoutImageRegionConstIteratorWithIndex.h"
30-
#include "itkFrequencyShiftedFFTLayoutImageRegionIteratorWithIndex.h"
30+
#include "itkFrequencyFFTLayoutImageRegionIteratorWithIndex.h"
31+
#include "itkFrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex.h"
3132
#include "itkFrequencyHalfHermitianFFTLayoutImageRegionIteratorWithIndex.h"
33+
#include "itkFrequencyShiftedFFTLayoutImageRegionConstIteratorWithIndex.h"
34+
#include "itkFrequencyShiftedFFTLayoutImageRegionIteratorWithIndex.h"
3235
#include "itkImage.h"
3336
#include "itkImageFileWriter.h"
3437
#include "itkTestingComparisonImageFilter.h"
@@ -51,6 +54,49 @@ class FrequencyIterators : public ::testing::Test
5154
RegisterRequiredFactories();
5255
}
5356
};
57+
58+
59+
template <typename TIterator>
60+
void
61+
CheckConstructedAtBegin()
62+
{
63+
using ImageType = typename TIterator::ImageType;
64+
using IndexType = typename TIterator::IndexType;
65+
using SizeType = typename TIterator::SizeType;
66+
using RegionType = typename TIterator::RegionType;
67+
68+
const auto image = ImageType::New();
69+
70+
// Use a small image size, so that the unit test won't take a long time.
71+
static constexpr itk::SizeValueType imageSizeValue{ 4 };
72+
73+
image->SetRegions(SizeType::Filled(imageSizeValue));
74+
image->Allocate();
75+
76+
// Check various regions, specified by the following `indexValue` and `sizeValue` combinations:
77+
for (const itk::IndexValueType indexValue : { 0, 1 })
78+
{
79+
for (const auto sizeValue : { itk::SizeValueType{ 1 }, imageSizeValue - 1 })
80+
{
81+
const RegionType imageRegion(IndexType::Filled(indexValue), SizeType::Filled(sizeValue));
82+
83+
const TIterator iterator(image, imageRegion);
84+
TIterator iteratorThatGoesToBegin = iterator;
85+
iteratorThatGoesToBegin.GoToBegin();
86+
EXPECT_EQ(iterator, iteratorThatGoesToBegin);
87+
}
88+
}
89+
}
90+
91+
92+
template <template <typename> typename... TIteratorTemplate>
93+
void
94+
CheckIteratorsConstructedAtBegin()
95+
{
96+
(CheckConstructedAtBegin<TIteratorTemplate<itk::Image<int>>>(), ...);
97+
(CheckConstructedAtBegin<TIteratorTemplate<itk::Image<double, 3>>>(), ...);
98+
}
99+
54100
} // namespace
55101

56102
template <typename TOutputImageType>
@@ -214,6 +260,19 @@ compareAllTypesOfIterators(typename TImageType::Pointer image, double difference
214260
EXPECT_TRUE(fullAndHermitian);
215261
}
216262

263+
264+
// Checks that an iterator that is just constructed by `IteratorType(image, region)` is at the begin.
265+
TEST_F(FrequencyIterators, AreConstructedAtBegin)
266+
{
267+
CheckIteratorsConstructedAtBegin<itk::FrequencyFFTLayoutImageRegionConstIteratorWithIndex,
268+
itk::FrequencyFFTLayoutImageRegionIteratorWithIndex,
269+
itk::FrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex,
270+
itk::FrequencyHalfHermitianFFTLayoutImageRegionIteratorWithIndex,
271+
itk::FrequencyShiftedFFTLayoutImageRegionConstIteratorWithIndex,
272+
itk::FrequencyShiftedFFTLayoutImageRegionIteratorWithIndex>();
273+
}
274+
275+
217276
TEST_F(FrequencyIterators, Even3D)
218277
{
219278
constexpr unsigned int ImageDimension = 3;

0 commit comments

Comments
 (0)