Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3
Medical Imaging Interaction Toolkit
mitkEqualTest.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include "mitkTestingMacros.h"
14 #include <mitkNumericTypes.h>
15 #include <mitkTestFixture.h>
16 
17 class mitkEqualTestSuite : public mitk::TestFixture
18 {
19  CPPUNIT_TEST_SUITE(mitkEqualTestSuite);
20  MITK_TEST(Equal_SameMitkVector3D_ReturnTrue);
21  MITK_TEST(Equal_SameMitkVector2D_ReturnTrue);
22  MITK_TEST(Equal_DifferentMitkVector3D_ReturnFalse);
23  MITK_TEST(Equal_DifferentMitkVector2D_ReturnFalse);
24  MITK_TEST(Equal_SameMitkVnlVector_ReturnTrue);
25  MITK_TEST(Equal_DifferentMitkVnlVector_ReturnFalse);
26  MITK_TEST(Equal_SameVnlVector_ReturnTrue);
27  MITK_TEST(Equal_DifferentVnlVector_ReturnFalse);
28  MITK_TEST(Equal_SameItkVector_ReturnTrue);
29  MITK_TEST(Equal_DifferentItkVector_ReturnFalse);
30  MITK_TEST(Equal_SameScalar_ReturnTrue);
31  MITK_TEST(Equal_DifferentScalar_ReturnFalse);
32  MITK_TEST(Equal_SameItkPoint_ReturnTrue);
33  MITK_TEST(Equal_DifferentItkPoint_ReturnFalse);
34  CPPUNIT_TEST_SUITE_END();
35 
36 public:
37  void Equal_SameMitkVector3D_ReturnTrue()
38  {
39  mitk::Vector3D v1;
40  v1.Fill(1);
41  mitk::Vector3D v2;
42  v2.Fill(1);
43  CPPUNIT_ASSERT(mitk::Equal(v1, v2));
44  }
45 
46  void Equal_SameMitkVector2D_ReturnTrue()
47  {
48  mitk::Vector2D v1;
49  v1.Fill(2);
50  mitk::Vector2D v2;
51  v2.Fill(2);
52  CPPUNIT_ASSERT(mitk::Equal(v1, v2));
53  }
54 
55  void Equal_DifferentMitkVector3D_ReturnFalse()
56  {
57  mitk::Vector3D v1;
58  v1.SetElement(0, 1);
59  v1.SetElement(1, 1);
60  v1.SetElement(2, 1);
61  mitk::Vector3D v2;
62  v2.SetElement(0, 2);
63  v2.SetElement(1, 1);
64  v2.SetElement(2, 1);
65  CPPUNIT_ASSERT_EQUAL_MESSAGE(
66  "Coparison of 2 different 3D MITK vectors (first element). Result should be false.", mitk::Equal(v1, v2), false);
67  mitk::Vector3D v3;
68  v3.SetElement(0, 1);
69  v3.SetElement(1, 2);
70  v3.SetElement(2, 1);
71  CPPUNIT_ASSERT_EQUAL_MESSAGE(
72  "Coparison of 2 different 3D MITK vectors (second element). Result should be false.", mitk::Equal(v1, v3), false);
73  mitk::Vector3D v4;
74  v4.SetElement(0, 1);
75  v4.SetElement(1, 1);
76  v4.SetElement(2, 2);
77  CPPUNIT_ASSERT_EQUAL_MESSAGE(
78  "Coparison of 2 different 3D MITK vectors (third element). Result should be false.", mitk::Equal(v1, v4), false);
79  }
80 
81  void Equal_DifferentMitkVector2D_ReturnFalse()
82  {
83  mitk::Vector2D v1;
84  v1.SetElement(0, 1);
85  v1.SetElement(1, 1);
86  mitk::Vector2D v2;
87  v2.SetElement(0, 2);
88  v2.SetElement(1, 1);
89  CPPUNIT_ASSERT_EQUAL_MESSAGE(
90  "Coparison of 2 different 2D MITK vectors (first element). Result should be false.", mitk::Equal(v1, v2), false);
91  mitk::Vector2D v3;
92  v3.SetElement(0, 1);
93  v3.SetElement(1, 2);
94  CPPUNIT_ASSERT_EQUAL_MESSAGE(
95  "Coparison of 2 different 2D MITK vectors (second element). Result should be false.", mitk::Equal(v1, v3), false);
96  }
97 
98  void Equal_SameMitkVnlVector_ReturnTrue()
99  {
100  mitk::VnlVector v1(2);
101  v1.fill(8);
102  mitk::VnlVector v2(2);
103  v2.fill(8);
104  CPPUNIT_ASSERT(mitk::Equal(v1, v2));
105  }
106 
107  void Equal_DifferentMitkVnlVector_ReturnFalse()
108  {
109  mitk::VnlVector v1(3);
110  v1.fill(9.2);
111  mitk::VnlVector v2(3);
112  v2.fill(9.2);
113  v2[0] = 6;
114  CPPUNIT_ASSERT_EQUAL_MESSAGE(
115  "Comparison of 2 different MITK VNL vectors. Result should be false.", mitk::Equal(v1, v2), false);
116  }
117 
118  void Equal_SameVnlVector_ReturnTrue()
119  {
120  vnl_vector_fixed<mitk::ScalarType, 4u> v1;
121  v1.fill(3.0);
122  vnl_vector_fixed<mitk::ScalarType, 4u> v2;
123  v2.fill(3.0);
124  CPPUNIT_ASSERT(mitk::Equal(v1, v2));
125  }
126 
127  void Equal_DifferentVnlVector_ReturnFalse()
128  {
129  vnl_vector_fixed<mitk::ScalarType, 2u> v1;
130  v1.fill(8.231);
131  vnl_vector_fixed<mitk::ScalarType, 2u> v2;
132  v2[0] = 3.1;
133  v2[1] = 8.231;
134  CPPUNIT_ASSERT_EQUAL_MESSAGE(
135  "Comparison of 2 different VNL vectors (first element). Result should be false.", mitk::Equal(v1, v2), false);
136  vnl_vector_fixed<mitk::ScalarType, 2u> v3;
137  v3[0] = 8.231;
138  v3[1] = 2.14;
139  CPPUNIT_ASSERT_EQUAL_MESSAGE(
140  "Comparison of 2 different VNL vectors (first element). Result should be false.", mitk::Equal(v1, v3), false);
141  }
142 
143  void Equal_SameItkVector_ReturnTrue()
144  {
145  itk::Vector<mitk::ScalarType, 3u> v1;
146  v1.Fill(1.32);
147  itk::Vector<mitk::ScalarType, 3u> v2;
148  v2.Fill(1.32);
149  mitk::Equal(v1, v2);
150  CPPUNIT_ASSERT(mitk::Equal(v1, v2));
151  }
152 
153  void Equal_DifferentItkVector_ReturnFalse()
154  {
155  itk::Vector<mitk::ScalarType, 3u> v1;
156  v1.Fill(5.2);
157  itk::Vector<mitk::ScalarType, 3u> v2;
158  v2.Fill(5.2);
159  v2.SetElement(0, 1.4);
160  CPPUNIT_ASSERT_EQUAL_MESSAGE(
161  "Coparison of 2 different ITK vectors (first element). Result should be false.", mitk::Equal(v1, v2), false);
162  itk::Vector<mitk::ScalarType, 3u> v3;
163  v3.Fill(5.2);
164  v3.SetElement(1, 1.4);
165  CPPUNIT_ASSERT_EQUAL_MESSAGE(
166  "Coparison of 2 different ITK vectors (second element). Result should be false.", mitk::Equal(v1, v3), false);
167  itk::Vector<mitk::ScalarType, 3u> v4;
168  v4.Fill(5.2);
169  v4.SetElement(2, 1.4);
170  CPPUNIT_ASSERT_EQUAL_MESSAGE(
171  "Coparison of 2 different ITK vectors (third element). Result should be false.", mitk::Equal(v1, v4), false);
172  }
173 
174  void Equal_SameScalar_ReturnTrue()
175  {
176  mitk::ScalarType a = 6.432;
177  mitk::ScalarType b = 6.432;
178  CPPUNIT_ASSERT(mitk::Equal(a, b));
179  }
180 
181  void Equal_DifferentScalar_ReturnFalse()
182  {
183  mitk::ScalarType a = 0.6;
184  mitk::ScalarType b = 0.6 + 1.01 * mitk::eps;
185  CPPUNIT_ASSERT_EQUAL_MESSAGE("Comparison of 2 different scalars. Result should be false", mitk::Equal(a, b), false);
186  }
187 
188  void Equal_SameItkPoint_ReturnTrue()
189  {
190  itk::Point<mitk::ScalarType, 2> p1;
191  p1.Fill(3.21);
192  itk::Point<mitk::ScalarType, 2> p2;
193  p2.Fill(3.21);
194  CPPUNIT_ASSERT(mitk::Equal(p1, p2));
195  }
196 
197  void Equal_DifferentItkPoint_ReturnFalse()
198  {
199  itk::Point<mitk::ScalarType, 2> p1;
200  p1.Fill(2.1);
201  itk::Point<mitk::ScalarType, 2> p2;
202  p2[0] = 1;
203  p2[1] = 2.1;
204  CPPUNIT_ASSERT_EQUAL_MESSAGE(
205  "Comparison of 2 different points (first element). Result should be false.", mitk::Equal(p1, p2), false);
206  itk::Point<mitk::ScalarType, 2> p3;
207  p3[0] = 2.1;
208  p3[1] = 2.1 + 1.01 * mitk::eps;
209  CPPUNIT_ASSERT_EQUAL_MESSAGE(
210  "Comparison of 2 different points (second element). Result should be false.", mitk::Equal(p1, p3), false);
211  }
212 };
213 
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
vnl_vector< ScalarType > VnlVector
Definition: mitkVector.h:134
double ScalarType
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
Test fixture for parameterized tests.
MITKNEWMODULE_EXPORT bool Equal(mitk::ExampleDataStructure *leftHandSide, mitk::ExampleDataStructure *rightHandSide, mitk::ScalarType eps, bool verbose)
Returns true if the example data structures are considered equal.
MITKCORE_EXPORT const ScalarType eps