Skip to content

Commit 969b2ca

Browse files
authored
Merge pull request InsightSoftwareConsortium#5896 from hjmjohnson/convert-itkarray2dtest-to-gtest
2 parents 5c4c6db + 94e56b9 commit 969b2ca

3 files changed

Lines changed: 75 additions & 128 deletions

File tree

Modules/Core/Common/test/CMakeLists.txt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ set(
3535
itkSymmetricEllipsoidInteriorExteriorSpatialFunctionTest.cxx
3636
itkSymmetricSecondRankTensorImageReadTest.cxx
3737
itkSymmetricSecondRankTensorImageWriteReadTest.cxx
38-
itkArray2DTest.cxx
3938
itkFloatingPointExceptionsTest.cxx
4039
itkFixedArrayTest2.cxx
4140
itkNeighborhoodAlgorithmTest.cxx
@@ -429,12 +428,6 @@ itk_add_test(
429428
ITKCommon1TestDriver
430429
itkMersenneTwisterRandomVariateGeneratorTest
431430
)
432-
itk_add_test(
433-
NAME itkArray2DTest
434-
COMMAND
435-
ITKCommon1TestDriver
436-
itkArray2DTest
437-
)
438431
itk_add_test(
439432
NAME itkBSplineInterpolationWeightFunctionTest
440433
COMMAND

Modules/Core/Common/test/itkArray2DGTest.cxx

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
// First include the header file to be tested:
2020
#include "itkArray2D.h"
2121
#include <gtest/gtest.h>
22+
#include <iostream>
2223
#include <limits>
2324
#include <type_traits> // For is_nothrow_move_constructible_v and is_nothrow_move_assignable_v.
2425

@@ -110,3 +111,77 @@ TEST(Array2D, MoveAssign)
110111
checkMoveAssign(itk::Array2D<int>(1U, 1U));
111112
checkMoveAssign(itk::Array2D<double>(1U, 2U));
112113
}
114+
115+
116+
TEST(Array2D, ConvertedLegacyTest)
117+
{
118+
using ArrayType = itk::Array2D<double>;
119+
120+
using VnlMatrixType = vnl_matrix<double>;
121+
122+
constexpr unsigned int rows{ 3 };
123+
constexpr unsigned int cols{ 4 };
124+
125+
ArrayType a(rows, cols);
126+
VnlMatrixType vm(rows, cols);
127+
128+
for (unsigned int r = 0; r < rows; ++r)
129+
{
130+
for (unsigned int c = 0; c < cols; ++c)
131+
{
132+
const auto value = static_cast<double>(r + c);
133+
a.SetElement(r, c, value);
134+
vm(r, c) = value;
135+
}
136+
}
137+
138+
constexpr double tolerance{ 1e-6 };
139+
140+
// test copy constructor
141+
ArrayType b(a);
142+
143+
for (unsigned int r = 0; r < rows; ++r)
144+
{
145+
for (unsigned int c = 0; c < cols; ++c)
146+
{
147+
EXPECT_NEAR(b(r, c), a.GetElement(r, c), tolerance);
148+
}
149+
}
150+
151+
// test construction from vnl_matrix
152+
ArrayType d(vm);
153+
154+
for (unsigned int r = 0; r < rows; ++r)
155+
{
156+
for (unsigned int c = 0; c < cols; ++c)
157+
{
158+
EXPECT_NEAR(d(r, c), vm(r, c), tolerance);
159+
}
160+
}
161+
162+
// test for assignment from Array2D
163+
164+
ArrayType e = a;
165+
166+
for (unsigned int r = 0; r < rows; ++r)
167+
{
168+
for (unsigned int c = 0; c < cols; ++c)
169+
{
170+
EXPECT_NEAR(e(r, c), a(r, c), tolerance);
171+
}
172+
}
173+
174+
// test for assignment from vnl_matrix
175+
176+
ArrayType f = vm;
177+
178+
for (unsigned int r = 0; r < rows; ++r)
179+
{
180+
for (unsigned int c = 0; c < cols; ++c)
181+
{
182+
EXPECT_NEAR(f(r, c), vm(r, c), tolerance);
183+
}
184+
}
185+
186+
std::cout << "Test Passed ! " << std::endl;
187+
}

Modules/Core/Common/test/itkArray2DTest.cxx

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

0 commit comments

Comments
 (0)