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