Skip to content

Commit 144cc73

Browse files
hjmjohnsonclaude
andcommitted
ENH: Convert itkBresenhamLineTest to itkBresenhamLineGTest
Replace legacy CTest driver test with GoogleTest framework. Splits into two test cases: BuildLineFromVector and BuildLineFromIndices. Replaces manual error-checking with EXPECT_EQ assertions on line length and per-element index values. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 67999b0 commit 144cc73

File tree

3 files changed

+67
-92
lines changed

3 files changed

+67
-92
lines changed

Modules/Core/Common/test/CMakeLists.txt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ set(
7373
itkPointSetTest.cxx
7474
itkPointSetToImageFilterTest1.cxx
7575
itkPointSetToImageFilterTest2.cxx
76-
itkBresenhamLineTest.cxx
7776
itkSparseFieldLayerTest.cxx
7877
itkDataObjectTest.cxx
7978
itkAtanRegularizedHeavisideStepFunctionTest1.cxx
@@ -783,12 +782,6 @@ itk_add_test(
783782
DATA{${ITK_DATA_ROOT}/Input/VascularTreePointSet.txt}
784783
${ITK_TEST_OUTPUT_DIR}/itkPointSetToImageFilterTest2.mha
785784
)
786-
itk_add_test(
787-
NAME itkBresenhamLineTest
788-
COMMAND
789-
ITKCommon1TestDriver
790-
itkBresenhamLineTest
791-
)
792785
itk_add_test(
793786
NAME itkSparseFieldLayerTest
794787
COMMAND
@@ -1768,6 +1761,7 @@ set(
17681761
itkStdStreamStateSaveGTest.cxx
17691762
itkDecoratorGTest.cxx
17701763
itkAbortProcessObjectGTest.cxx
1764+
itkBresenhamLineGTest.cxx
17711765
)
17721766
creategoogletestdriver(ITKCommon "${ITKCommon-Test_LIBRARIES}" "${ITKCommonGTests}")
17731767
# If `-static` was passed to CMAKE_EXE_LINKER_FLAGS, compilation fails. No need to
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*=========================================================================
2+
*
3+
* Copyright NumFOCUS
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0.txt
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*=========================================================================*/
18+
19+
#include "itkBresenhamLine.h"
20+
#include "itkGTest.h"
21+
22+
#include <iostream>
23+
24+
TEST(BresenhamLine, BuildLineFromVector)
25+
{
26+
// Test BuildLine(Vector, distance)
27+
itk::Vector<float, 2> v;
28+
v[0] = 1;
29+
v[1] = 1;
30+
31+
itk::BresenhamLine<2> line;
32+
std::vector<itk::Offset<2>> offsets = line.BuildLine(v, 4);
33+
34+
EXPECT_EQ(offsets.size(), 4u);
35+
36+
for (int i = 0; i < 4; ++i)
37+
{
38+
EXPECT_EQ(offsets[i][0], i) << "offsets[" << i << "][0] mismatch";
39+
EXPECT_EQ(offsets[i][1], i) << "offsets[" << i << "][1] mismatch";
40+
}
41+
}
42+
43+
TEST(BresenhamLine, BuildLineFromIndices)
44+
{
45+
// Test BuildLine(Index, Index)
46+
itk::Index<2> p0;
47+
p0[0] = 0;
48+
p0[1] = 0;
49+
50+
itk::Index<2> p1;
51+
p1[0] = 39;
52+
p1[1] = 39;
53+
54+
itk::BresenhamLine<2> line;
55+
std::vector<itk::Index<2>> indices = line.BuildLine(p0, p1);
56+
57+
EXPECT_EQ(indices.size(), 40u);
58+
59+
for (int i = 0; i < 40; ++i)
60+
{
61+
EXPECT_EQ(indices[i][0], i) << "indices[" << i << "][0] mismatch";
62+
EXPECT_EQ(indices[i][1], i) << "indices[" << i << "][1] mismatch";
63+
}
64+
65+
std::cout << "Test Passed !" << std::endl;
66+
}

Modules/Core/Common/test/itkBresenhamLineTest.cxx

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

0 commit comments

Comments
 (0)