Medical Imaging Interaction Toolkit  2016.11.0
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,
6  Division of Medical and Biological Informatics.
7  All rights reserved.
8 
9  This software is distributed WITHOUT ANY WARRANTY; without
10  even the implied warranty of MERCHANTABILITY or FITNESS FOR
11  A PARTICULAR PURPOSE.
12 
13  See LICENSE.txt or http://www.mitk.org for details.
14 
15  ===================================================================*/
16 
17 #include "mitkTestingMacros.h"
18 #include <mitkNumericTypes.h>
19 #include <mitkTestFixture.h>
20 
21 class mitkEqualTestSuite : public mitk::TestFixture
22 {
23  CPPUNIT_TEST_SUITE(mitkEqualTestSuite);
24  MITK_TEST(Equal_SameMitkVector3D_ReturnTrue);
25  MITK_TEST(Equal_SameMitkVector2D_ReturnTrue);
26  MITK_TEST(Equal_DifferentMitkVector3D_ReturnFalse);
27  MITK_TEST(Equal_DifferentMitkVector2D_ReturnFalse);
28  MITK_TEST(Equal_SameMitkVnlVector_ReturnTrue);
29  MITK_TEST(Equal_DifferentMitkVnlVector_ReturnFalse);
30  MITK_TEST(Equal_SameVnlVector_ReturnTrue);
31  MITK_TEST(Equal_DifferentVnlVector_ReturnFalse);
32  MITK_TEST(Equal_SameItkVector_ReturnTrue);
33  MITK_TEST(Equal_DifferentItkVector_ReturnFalse);
34  MITK_TEST(Equal_SameScalar_ReturnTrue);
35  MITK_TEST(Equal_DifferentScalar_ReturnFalse);
36  MITK_TEST(Equal_SameItkPoint_ReturnTrue);
37  MITK_TEST(Equal_DifferentItkPoint_ReturnFalse);
38  CPPUNIT_TEST_SUITE_END();
39 
40 public:
41  void Equal_SameMitkVector3D_ReturnTrue()
42  {
43  mitk::Vector3D v1;
44  v1.Fill(1);
45  mitk::Vector3D v2;
46  v2.Fill(1);
47  CPPUNIT_ASSERT(mitk::Equal(v1, v2));
48  }
49 
50  void Equal_SameMitkVector2D_ReturnTrue()
51  {
52  mitk::Vector2D v1;
53  v1.Fill(2);
54  mitk::Vector2D v2;
55  v2.Fill(2);
56  CPPUNIT_ASSERT(mitk::Equal(v1, v2));
57  }
58 
59  void Equal_DifferentMitkVector3D_ReturnFalse()
60  {
61  mitk::Vector3D v1;
62  v1.SetElement(0, 1);
63  v1.SetElement(1, 1);
64  v1.SetElement(2, 1);
65  mitk::Vector3D v2;
66  v2.SetElement(0, 2);
67  v2.SetElement(1, 1);
68  v2.SetElement(2, 1);
69  CPPUNIT_ASSERT_EQUAL_MESSAGE(
70  "Coparison of 2 different 3D MITK vectors (first element). Result should be false.", mitk::Equal(v1, v2), false);
71  mitk::Vector3D v3;
72  v3.SetElement(0, 1);
73  v3.SetElement(1, 2);
74  v3.SetElement(2, 1);
75  CPPUNIT_ASSERT_EQUAL_MESSAGE(
76  "Coparison of 2 different 3D MITK vectors (second element). Result should be false.", mitk::Equal(v1, v3), false);
77  mitk::Vector3D v4;
78  v4.SetElement(0, 1);
79  v4.SetElement(1, 1);
80  v4.SetElement(2, 2);
81  CPPUNIT_ASSERT_EQUAL_MESSAGE(
82  "Coparison of 2 different 3D MITK vectors (third element). Result should be false.", mitk::Equal(v1, v4), false);
83  }
84 
85  void Equal_DifferentMitkVector2D_ReturnFalse()
86  {
87  mitk::Vector2D v1;
88  v1.SetElement(0, 1);
89  v1.SetElement(1, 1);
90  mitk::Vector2D v2;
91  v2.SetElement(0, 2);
92  v2.SetElement(1, 1);
93  CPPUNIT_ASSERT_EQUAL_MESSAGE(
94  "Coparison of 2 different 2D MITK vectors (first element). Result should be false.", mitk::Equal(v1, v2), false);
95  mitk::Vector2D v3;
96  v3.SetElement(0, 1);
97  v3.SetElement(1, 2);
98  CPPUNIT_ASSERT_EQUAL_MESSAGE(
99  "Coparison of 2 different 2D MITK vectors (second element). Result should be false.", mitk::Equal(v1, v3), false);
100  }
101 
102  void Equal_SameMitkVnlVector_ReturnTrue()
103  {
104  mitk::VnlVector v1(2);
105  v1.fill(8);
106  mitk::VnlVector v2(2);
107  v2.fill(8);
108  CPPUNIT_ASSERT(mitk::Equal(v1, v2));
109  }
110 
111  void Equal_DifferentMitkVnlVector_ReturnFalse()
112  {
113  mitk::VnlVector v1(3);
114  v1.fill(9.2);
115  mitk::VnlVector v2(3);
116  v2.fill(9.2);
117  v2[0] = 6;
118  CPPUNIT_ASSERT_EQUAL_MESSAGE(
119  "Comparison of 2 different MITK VNL vectors. Result should be false.", mitk::Equal(v1, v2), false);
120  }
121 
122  void Equal_SameVnlVector_ReturnTrue()
123  {
124  vnl_vector_fixed<mitk::ScalarType, 4u> v1;
125  v1.fill(3.0);
126  vnl_vector_fixed<mitk::ScalarType, 4u> v2;
127  v2.fill(3.0);
128  CPPUNIT_ASSERT(mitk::Equal(v1, v2));
129  }
130 
131  void Equal_DifferentVnlVector_ReturnFalse()
132  {
133  vnl_vector_fixed<mitk::ScalarType, 2u> v1;
134  v1.fill(8.231);
135  vnl_vector_fixed<mitk::ScalarType, 2u> v2;
136  v2[0] = 3.1;
137  v2[1] = 8.231;
138  CPPUNIT_ASSERT_EQUAL_MESSAGE(
139  "Comparison of 2 different VNL vectors (first element). Result should be false.", mitk::Equal(v1, v2), false);
140  vnl_vector_fixed<mitk::ScalarType, 2u> v3;
141  v3[0] = 8.231;
142  v3[1] = 2.14;
143  CPPUNIT_ASSERT_EQUAL_MESSAGE(
144  "Comparison of 2 different VNL vectors (first element). Result should be false.", mitk::Equal(v1, v3), false);
145  }
146 
147  void Equal_SameItkVector_ReturnTrue()
148  {
149  itk::Vector<mitk::ScalarType, 3u> v1;
150  v1.Fill(1.32);
151  itk::Vector<mitk::ScalarType, 3u> v2;
152  v2.Fill(1.32);
153  mitk::Equal(v1, v2);
154  CPPUNIT_ASSERT(mitk::Equal(v1, v2));
155  }
156 
157  void Equal_DifferentItkVector_ReturnFalse()
158  {
159  itk::Vector<mitk::ScalarType, 3u> v1;
160  v1.Fill(5.2);
161  itk::Vector<mitk::ScalarType, 3u> v2;
162  v2.Fill(5.2);
163  v2.SetElement(0, 1.4);
164  CPPUNIT_ASSERT_EQUAL_MESSAGE(
165  "Coparison of 2 different ITK vectors (first element). Result should be false.", mitk::Equal(v1, v2), false);
166  itk::Vector<mitk::ScalarType, 3u> v3;
167  v3.Fill(5.2);
168  v3.SetElement(1, 1.4);
169  CPPUNIT_ASSERT_EQUAL_MESSAGE(
170  "Coparison of 2 different ITK vectors (second element). Result should be false.", mitk::Equal(v1, v3), false);
171  itk::Vector<mitk::ScalarType, 3u> v4;
172  v4.Fill(5.2);
173  v4.SetElement(2, 1.4);
174  CPPUNIT_ASSERT_EQUAL_MESSAGE(
175  "Coparison of 2 different ITK vectors (third element). Result should be false.", mitk::Equal(v1, v4), false);
176  }
177 
178  void Equal_SameScalar_ReturnTrue()
179  {
180  mitk::ScalarType a = 6.432;
181  mitk::ScalarType b = 6.432;
182  CPPUNIT_ASSERT(mitk::Equal(a, b));
183  }
184 
185  void Equal_DifferentScalar_ReturnFalse()
186  {
187  mitk::ScalarType a = 0.6;
188  mitk::ScalarType b = 0.6 + 1.01 * mitk::eps;
189  CPPUNIT_ASSERT_EQUAL_MESSAGE("Comparison of 2 different scalars. Result should be false", mitk::Equal(a, b), false);
190  }
191 
192  void Equal_SameItkPoint_ReturnTrue()
193  {
194  itk::Point<mitk::ScalarType, 2> p1;
195  p1.Fill(3.21);
196  itk::Point<mitk::ScalarType, 2> p2;
197  p2.Fill(3.21);
198  CPPUNIT_ASSERT(mitk::Equal(p1, p2));
199  }
200 
201  void Equal_DifferentItkPoint_ReturnFalse()
202  {
203  itk::Point<mitk::ScalarType, 2> p1;
204  p1.Fill(2.1);
205  itk::Point<mitk::ScalarType, 2> p2;
206  p2[0] = 1;
207  p2[1] = 2.1;
208  CPPUNIT_ASSERT_EQUAL_MESSAGE(
209  "Comparison of 2 different points (first element). Result should be false.", mitk::Equal(p1, p2), false);
210  itk::Point<mitk::ScalarType, 2> p3;
211  p3[0] = 2.1;
212  p3[1] = 2.1 + 1.01 * mitk::eps;
213  CPPUNIT_ASSERT_EQUAL_MESSAGE(
214  "Comparison of 2 different points (second element). Result should be false.", mitk::Equal(p1, p3), false);
215  }
216 };
217 
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
vnl_vector< ScalarType > VnlVector
Definition: mitkVector.h:138
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