1 /*=========================================================================
2  *
3  *  Copyright Insight Software Consortium
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  *         http://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 "itkGTest.h"
20 #include "itkMath.h"
21 
22 // Minimal test to verify Google Test works
TEST(GoogleTest,t1)23 TEST(GoogleTest,t1) {
24   void *ptr = nullptr;
25   ASSERT_TRUE((ptr == nullptr));
26   EXPECT_TRUE((ptr == nullptr));
27 }
28 
29 // cover ITK Google testing utilities
TEST(GoogleTest,TypedefsAndConstructors_Dimension2)30 TEST(GoogleTest,TypedefsAndConstructors_Dimension2) {
31 
32   using namespace itk::GTest::TypedefsAndConstructors::Dimension2;
33 
34   PointType pt1;
35   pt1[0] = 1.1;
36   pt1[1] = 2.2;
37   const PointType pt2 = MakePoint(1.1, 2.2);
38   EXPECT_TRUE(pt1 == pt2);
39   ITK_EXPECT_VECTOR_NEAR(pt1, pt2, 1e-10);
40   ITK_EXPECT_VECTOR_NEAR(pt1, MakePoint(1.1, 2.2), 1e-10);
41 
42   VectorType vec1;
43   vec1[0] = 1.1;
44   vec1[1] = 2.2;
45   const VectorType vec2 = MakeVector(1.1, 2.2);
46   EXPECT_TRUE(vec1 == vec2);
47   ITK_EXPECT_VECTOR_NEAR(vec1, vec2, 1e-10);
48   ITK_EXPECT_VECTOR_NEAR(vec1, MakeVector(1.1, 2.2), 1e-10);
49 
50   const IndexType idx1 = {{0,1}};
51   const IndexType idx2 = MakeIndex(0,1);
52   EXPECT_TRUE(idx1 == idx2);
53   ITK_EXPECT_VECTOR_NEAR(idx1, idx2, 1e-10);
54   ITK_EXPECT_VECTOR_NEAR(idx1, MakeIndex(0,1), 1e-10);
55 
56   const SizeType sz1 = {{0u,1u}};
57   const SizeType sz2 = MakeSize(0u,1u);
58   EXPECT_TRUE(sz1 == sz2);
59   ITK_EXPECT_VECTOR_NEAR(sz1, sz2, 1e-10);
60   ITK_EXPECT_VECTOR_NEAR(sz1, MakeSize(0u,1u), 1e-10);
61 }
62 
63 
64 // cover ITK Google testing utilities
TEST(GoogleTest,TypedefsAndConstructors_Dimension3)65 TEST(GoogleTest,TypedefsAndConstructors_Dimension3) {
66 
67   using namespace itk::GTest::TypedefsAndConstructors::Dimension3;
68 
69   PointType pt1;
70   pt1[0] = 1.1;
71   pt1[1] = 2.2;
72   pt1[2] = 3.3;
73   const PointType pt2 = MakePoint(1.1, 2.2, 3.3);
74   EXPECT_TRUE(pt1 == pt2);
75   ITK_EXPECT_VECTOR_NEAR(pt1, pt2, 1e-10);
76   ITK_EXPECT_VECTOR_NEAR(pt1,  MakePoint(1.1, 2.2, 3.3), 1e-10);
77 
78   VectorType vec1;
79   vec1[0] = 1.1;
80   vec1[1] = 2.2;
81   vec1[2] = 3.3;
82   const VectorType vec2 = MakeVector(1.1, 2.2, 3.3);
83   EXPECT_TRUE(vec1 == vec2);
84   ITK_EXPECT_VECTOR_NEAR(vec1, vec2, 1e-10);
85   ITK_EXPECT_VECTOR_NEAR(vec1, MakeVector(1.1, 2.2, 3.3), 1e-10);
86 
87   const IndexType idx1 = {{0,1,2}};
88   const IndexType idx2 = MakeIndex(0,1,2);
89   EXPECT_TRUE(idx1 == idx2);
90   ITK_EXPECT_VECTOR_NEAR(idx1, idx2, 1e-10);
91 
92   const SizeType sz1 = {{0u,1u,2u}};
93   const SizeType sz2 = MakeSize(0u,1u,2u);
94   EXPECT_TRUE(sz1 == sz2);
95   ITK_EXPECT_VECTOR_NEAR(sz1, MakeSize(0u,1u,2u), 1e-10);
96 }
97