Skip to content

Commit 6a66f93

Browse files
authored
Merge pull request #4912 from N-Dekker/PointSet-GraftDoesShallowCopy-GTest
ENH: Add `PointSet.GraftDoesShallowCopy` GoogleTest unit test
2 parents faa80fd + de0bc38 commit 6a66f93

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

Modules/Core/Common/test/itkPointSetGTest.cxx

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

1919
// First include the header file to be tested:
2020
#include "itkPointSet.h"
21+
#include "itkDeref.h"
2122
#include "../../QuadEdgeMesh/include/itkQuadEdgeMeshTraits.h"
2223
#include <gtest/gtest.h>
2324
#include <algorithm> // For equal.
@@ -80,3 +81,35 @@ TEST(PointSet, SetPointsByCoordinates)
8081
TestSetPointsByCoordinates(*itk::PointSet<int>::New());
8182
TestSetPointsByCoordinates(*itk::PointSet<double, 2, itk::QuadEdgeMeshTraits<double, 2, bool, bool>>::New());
8283
}
84+
85+
86+
// Tests that `PointSet::Graft` just copies the *pointers* to the points and the data. It does not do a "deep copy".
87+
TEST(PointSet, GraftDoesShallowCopy)
88+
{
89+
const auto check = [](const auto & pointSet) {
90+
const auto clone = pointSet.Clone();
91+
92+
// Check that Clone() did not return null, by using itk::Deref(ptr).
93+
const auto & constClone = itk::Deref(clone.get());
94+
95+
clone->Graft(&pointSet);
96+
97+
// Expect that the pointers to the points and the data of the clone are equal to those of the original.
98+
EXPECT_EQ(constClone.GetPoints(), pointSet.GetPoints());
99+
EXPECT_EQ(constClone.GetPointData(), pointSet.GetPointData());
100+
};
101+
102+
// First check an empty point set:
103+
check(*itk::PointSet<int>::New());
104+
105+
// Then check a non-empty 2-D point set with `double` data:
106+
using PixelType = double;
107+
using PointSetType = itk::PointSet<PixelType, 2>;
108+
using PointType = PointSetType::PointType;
109+
110+
const auto pointSet = PointSetType::New();
111+
pointSet->SetPoints(itk::MakeVectorContainer<PointType>({ PointType(), itk::MakeFilled<PointType>(1.0f) }));
112+
pointSet->SetPointData(itk::MakeVectorContainer<PixelType>({ 0.0, 1.0, 2.0 }));
113+
114+
check(*pointSet);
115+
}

0 commit comments

Comments
 (0)