Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkArrayTypeConversionTest.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 "mitkTestFixture.h"
18 #include "mitkTestingMacros.h"
19 
20 #include "mitkArray.h"
21 #include "mitkNumericConstants.h"
22 
23 class mitkArrayTypeConversionTestSuite : public mitk::TestFixture
24 {
25  CPPUNIT_TEST_SUITE(mitkArrayTypeConversionTestSuite);
26 
27  MITK_TEST(EqualArray_ReturnsTrue);
28  MITK_TEST(EqualArray_ReturnsFalse);
29 
30  MITK_TEST(FillVector3D_CorrectlyFilled);
31  MITK_TEST(FillVector4D_CorrectlyFilled);
32 
33  CPPUNIT_TEST_SUITE_END();
34 
35 private:
36  mitk::ScalarType a[3];
37  mitk::ScalarType b[3];
38 
39 public:
40  void setUp(void) override
41  {
42  b[0] = a[0] = 1.0;
43  b[1] = a[1] = 2.12;
44  b[2] = a[2] = 3.13;
45  }
46 
47  void tearDown(void) override {}
48  void EqualArray_ReturnsTrue(void)
49  {
50  CPPUNIT_ASSERT_EQUAL_MESSAGE(
51  "test if EqualArray method returns true for two equal arrays.", true, mitk::EqualArray(a, b, 3));
52  }
53 
54  void EqualArray_ReturnsFalse(void)
55  {
56  b[2] += mitk::eps;
57 
58  CPPUNIT_ASSERT_EQUAL_MESSAGE(
59  "test if EqualArray method returns false for two non-equal arrays.", false, mitk::EqualArray(a, b, 3));
60  }
61 
62  void FillVector3D_CorrectlyFilled(void)
63  {
64  mitk::ScalarType c[3];
65 
66  mitk::FillVector3D(c, a[0], a[1], a[2]);
67 
68  CPPUNIT_ASSERT_EQUAL_MESSAGE("test if FillVector3D correctly fills array types.", true, mitk::EqualArray(a, c, 3));
69  }
70 
71  void FillVector4D_CorrectlyFilled(void)
72  {
73  mitk::ScalarType e[4];
74  mitk::ScalarType f[4];
75 
76  e[0] = 1.0;
77  e[1] = 2.12;
78  e[2] = 3.13;
79  e[3] = 4.14;
80 
81  mitk::FillVector4D(f, e[0], e[1], e[2], e[3]);
82 
83  CPPUNIT_ASSERT_EQUAL_MESSAGE("test if FillVector4D correctly fills array types.", true, mitk::EqualArray(e, f, 4));
84  }
85 };
86 
87 MITK_TEST_SUITE_REGISTRATION(mitkArrayTypeConversion)
bool EqualArray(TArrayType1 &arrayType1, TArrayType2 &arrayType2, int size, ScalarType eps=mitk::eps, bool verbose=false)
Definition: mitkArray.h:132
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
double ScalarType
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
void FillVector3D(Tout &out, mitk::ScalarType x, mitk::ScalarType y, mitk::ScalarType z)
Definition: mitkArray.h:110
Test fixture for parameterized tests.
void FillVector4D(Tout &out, mitk::ScalarType x, mitk::ScalarType y, mitk::ScalarType z, mitk::ScalarType t)
Definition: mitkArray.h:118
MITKCORE_EXPORT const ScalarType eps