Skip to content

Commit 20a85b8

Browse files
committed
STYLE: Use std::array instead of std::vector for local variables in test
Declared those variables static constexpr.
1 parent 0c64ed9 commit 20a85b8

4 files changed

Lines changed: 15 additions & 49 deletions

File tree

Modules/Core/Common/test/itkConstNeighborhoodIteratorTest.cxx

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "itkNeighborhoodIteratorTestCommon.hxx"
2020
#include "itkConstNeighborhoodIterator.h"
21+
#include <array>
2122

2223
void
2324
println(const char * s)
@@ -356,17 +357,8 @@ itkConstNeighborhoodIteratorTest(int, char *[])
356357
using NeighborhoodIteratorType = itk::ConstNeighborhoodIterator<ChangeRegionTestImageType>;
357358
NeighborhoodIteratorType neighborhoodIterator(neighborhoodRadius, image, region1);
358359

359-
std::vector<int> expectedValuesRegion1(9);
360-
expectedValuesRegion1[0] = 0;
361-
expectedValuesRegion1[1] = 255;
362-
expectedValuesRegion1[2] = 255;
363-
expectedValuesRegion1[3] = 0;
364-
expectedValuesRegion1[4] = 255;
365-
expectedValuesRegion1[5] = 255;
366-
expectedValuesRegion1[6] = 0;
367-
expectedValuesRegion1[7] = 255;
368-
expectedValuesRegion1[8] = 255;
369-
unsigned int counter = 0;
360+
static constexpr std::array<int, 9> expectedValuesRegion1{ 0, 255, 255, 0, 255, 255, 0, 255, 255 };
361+
unsigned int counter = 0;
370362

371363
for (NeighborhoodIteratorType::ConstIterator pixelIterator = neighborhoodIterator.Begin();
372364
pixelIterator < neighborhoodIterator.End();
@@ -387,16 +379,7 @@ itkConstNeighborhoodIteratorTest(int, char *[])
387379
neighborhoodIterator.SetRegion(region2);
388380
neighborhoodIterator.GoToBegin();
389381

390-
std::vector<int> expectedValuesRegion2(9);
391-
expectedValuesRegion2[0] = 255;
392-
expectedValuesRegion2[1] = 255;
393-
expectedValuesRegion2[2] = 255;
394-
expectedValuesRegion2[3] = 255;
395-
expectedValuesRegion2[4] = 255;
396-
expectedValuesRegion2[5] = 255;
397-
expectedValuesRegion2[6] = 255;
398-
expectedValuesRegion2[7] = 255;
399-
expectedValuesRegion2[8] = 255;
382+
static constexpr std::array<int, 9> expectedValuesRegion2{ 255, 255, 255, 255, 255, 255, 255, 255, 255 };
400383
counter = 0;
401384
for (NeighborhoodIteratorType::ConstIterator pixelIterator = neighborhoodIterator.Begin();
402385
pixelIterator < neighborhoodIterator.End();

Modules/Core/Common/test/itkConstShapedNeighborhoodIteratorTest.cxx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "itkNeighborhoodIteratorTestCommon.hxx"
2020
#include "itkConstShapedNeighborhoodIterator.h"
21+
#include <array>
2122

2223
void
2324
PrintShapedNeighborhood(const itk::ConstShapedNeighborhoodIterator<TestImageType> & n)
@@ -470,9 +471,7 @@ itkConstShapedNeighborhoodIteratorTest(int, char *[])
470471
shapedNeighborhoodIterator.ActivateOffset(offset_item);
471472
}
472473

473-
std::vector<int> expectedValuesRegion1(2);
474-
expectedValuesRegion1[0] = 0;
475-
expectedValuesRegion1[1] = 255;
474+
static constexpr std::array<int, 2> expectedValuesRegion1{ 0, 255 };
476475

477476
unsigned int counter = 0;
478477
// while(!shapedNeighborhoodIterator.IsAtEnd()) // no need for this loop as we are only iterating over a 1x1 region
@@ -500,9 +499,7 @@ itkConstShapedNeighborhoodIteratorTest(int, char *[])
500499
shapedNeighborhoodIterator.SetRegion(region2);
501500
shapedNeighborhoodIterator.GoToBegin();
502501

503-
std::vector<int> expectedValuesRegion2(2);
504-
expectedValuesRegion2[0] = 255;
505-
expectedValuesRegion2[1] = 255;
502+
static constexpr std::array<int, 2> expectedValuesRegion2{ 255, 255 };
506503

507504
counter = 0;
508505
// while(!shapedNeighborhoodIterator.IsAtEnd()) // no need for this loop as we are only iterating over a 1x1 region

Modules/Core/Common/test/itkImageRegionIteratorTest.cxx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <iostream>
2020

2121
#include "itkImageRegionIterator.h"
22+
#include <array>
2223

2324

2425
// This routine is used to make sure that we call the "const" version
@@ -172,12 +173,8 @@ itkImageRegionIteratorTest(int, char *[])
172173

173174
itk::ImageRegionConstIterator<TestImageType> imageIterator(image, region1);
174175

175-
std::vector<int> expectedValuesRegion1(4);
176-
expectedValuesRegion1[0] = 0;
177-
expectedValuesRegion1[1] = 255;
178-
expectedValuesRegion1[2] = 0;
179-
expectedValuesRegion1[3] = 255;
180-
unsigned int counter = 0;
176+
static constexpr std::array<int, 4> expectedValuesRegion1{ 0, 255, 0, 255 };
177+
unsigned int counter = 0;
181178
while (!imageIterator.IsAtEnd())
182179
{
183180
if (imageIterator.Get() != expectedValuesRegion1[counter])
@@ -196,11 +193,7 @@ itkImageRegionIteratorTest(int, char *[])
196193
imageIterator.SetRegion(region2);
197194
imageIterator.GoToBegin();
198195

199-
std::vector<int> expectedValuesRegion2(4);
200-
expectedValuesRegion2[0] = 255;
201-
expectedValuesRegion2[1] = 255;
202-
expectedValuesRegion2[2] = 255;
203-
expectedValuesRegion2[3] = 255;
196+
static constexpr std::array<int, 4> expectedValuesRegion2{ 255, 255, 255, 255 };
204197
counter = 0;
205198
while (!imageIterator.IsAtEnd())
206199
{

Modules/Core/Common/test/itkImageScanlineIteratorTest1.cxx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <iostream>
2020

2121
#include "itkImageScanlineIterator.h"
22+
#include <array>
2223

2324

2425
// This routine is used to make sure that we call the "const" version
@@ -188,12 +189,8 @@ itkImageScanlineIteratorTest1(int, char *[])
188189

189190
itk::ImageScanlineConstIterator<TestImageType> imageIterator(image, region1);
190191

191-
std::vector<int> expectedValuesRegion1(4);
192-
expectedValuesRegion1[0] = 0;
193-
expectedValuesRegion1[1] = 255;
194-
expectedValuesRegion1[2] = 0;
195-
expectedValuesRegion1[3] = 255;
196-
unsigned int counter = 0;
192+
static constexpr std::array<int, 4> expectedValuesRegion1{ 0, 255, 0, 255 };
193+
unsigned int counter = 0;
197194
while (!imageIterator.IsAtEnd())
198195
{
199196
while (!imageIterator.IsAtEndOfLine())
@@ -216,11 +213,7 @@ itkImageScanlineIteratorTest1(int, char *[])
216213
imageIterator.SetRegion(region2);
217214
imageIterator.GoToBegin();
218215

219-
std::vector<int> expectedValuesRegion2(4);
220-
expectedValuesRegion2[0] = 255;
221-
expectedValuesRegion2[1] = 255;
222-
expectedValuesRegion2[2] = 255;
223-
expectedValuesRegion2[3] = 255;
216+
static constexpr std::array<int, 4> expectedValuesRegion2{ 255, 255, 255, 255 };
224217
counter = 0;
225218
while (!imageIterator.IsAtEnd())
226219
{

0 commit comments

Comments
 (0)