Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkTemporoSpatialStringPropertyTest.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 
18 #include "mitkTestFixture.h"
19 #include "mitkTestingMacros.h"
20 
21 #include <limits>
22 
23 class mitkTemporoSpatialStringPropertyTestSuite : public mitk::TestFixture
24 {
25  CPPUNIT_TEST_SUITE(mitkTemporoSpatialStringPropertyTestSuite);
26 
27  MITK_TEST(GetValue);
28  MITK_TEST(HasValue);
29  MITK_TEST(SetValue);
30 
33 
34  CPPUNIT_TEST_SUITE_END();
35 
36 private:
37  std::string refJSON;
39 
40 public:
41  void setUp() override
42  {
43  refJSON = "{\"values\":[{\"t\":0, \"z\":0, \"value\":\"v_0_0\"}, {\"t\":3, \"z\":0, \"value\":\"v_3_0\"}, "
44  "{\"t\":3, \"z\":2, \"value\":\"v_3_2\"}, {\"t\":6, \"z\":1, \"value\":\"v_6_1\"}]}";
46  refProp->SetValue(0, 0, "v_0_0");
47  refProp->SetValue(3, 0, "v_3_0");
48  refProp->SetValue(3, 2, "v_3_2");
49  refProp->SetValue(6, 1, "v_6_1");
50  }
51 
52  void tearDown() override {}
53  void GetValue()
54  {
55  CPPUNIT_ASSERT(refProp->GetValue() == "v_0_0");
56 
57  CPPUNIT_ASSERT(refProp->GetValue(3, 0) == "v_3_0");
58  CPPUNIT_ASSERT(refProp->GetValue(3, 2) == "v_3_2");
59  CPPUNIT_ASSERT(refProp->GetValue(3, 1, false, true) == "v_3_0");
60  CPPUNIT_ASSERT(refProp->GetValue(3, 5, false, true) == "v_3_2");
61 
62  CPPUNIT_ASSERT(refProp->GetValueBySlice(0) == "v_0_0");
63  CPPUNIT_ASSERT(refProp->GetValueBySlice(4, true) == "v_0_0");
64 
65  CPPUNIT_ASSERT(refProp->GetValueByTimeStep(3) == "v_3_0");
66  CPPUNIT_ASSERT(refProp->GetValueByTimeStep(6) == "v_6_1");
67  CPPUNIT_ASSERT(refProp->GetValueByTimeStep(5, true) == "v_3_0");
68 
69  CPPUNIT_ASSERT(refProp->GetValueAsString() == "v_0_0");
70 
71  CPPUNIT_ASSERT(refProp->GetAvailableTimeSteps().size() == 3);
72  CPPUNIT_ASSERT(refProp->GetAvailableTimeSteps()[0] == 0);
73  CPPUNIT_ASSERT(refProp->GetAvailableTimeSteps()[1] == 3);
74  CPPUNIT_ASSERT(refProp->GetAvailableTimeSteps()[2] == 6);
75 
76  CPPUNIT_ASSERT(refProp->GetAvailableSlices(0).size() == 1);
77  CPPUNIT_ASSERT(refProp->GetAvailableSlices(0)[0] == 0);
78  CPPUNIT_ASSERT(refProp->GetAvailableSlices(3).size() == 2);
79  CPPUNIT_ASSERT(refProp->GetAvailableSlices(3)[0] == 0);
80  CPPUNIT_ASSERT(refProp->GetAvailableSlices(3)[1] == 2);
81 
82  CPPUNIT_ASSERT(refProp->GetAvailableSlices(2).size() == 0);
83  }
84 
85  void HasValue()
86  {
87  CPPUNIT_ASSERT(refProp->HasValue());
88 
89  CPPUNIT_ASSERT(refProp->HasValue(3, 0));
90  CPPUNIT_ASSERT(refProp->HasValue(3, 2));
91  CPPUNIT_ASSERT(refProp->HasValue(3, 1, false, true));
92  CPPUNIT_ASSERT(refProp->HasValue(3, 5, false, true));
93  CPPUNIT_ASSERT(!refProp->HasValue(3, 1));
94  CPPUNIT_ASSERT(!refProp->HasValue(3, 5));
95  CPPUNIT_ASSERT(refProp->HasValue(4, 2, true, true));
96  CPPUNIT_ASSERT(refProp->HasValue(4, 2, true, false));
97  CPPUNIT_ASSERT(!refProp->HasValue(4, 2, false, true));
98 
99  CPPUNIT_ASSERT(refProp->HasValueBySlice(0));
100  CPPUNIT_ASSERT(refProp->HasValueBySlice(4, true));
101  CPPUNIT_ASSERT(!refProp->HasValueBySlice(4));
102 
103  CPPUNIT_ASSERT(refProp->HasValueByTimeStep(3));
104  CPPUNIT_ASSERT(refProp->HasValueByTimeStep(6));
105  CPPUNIT_ASSERT(refProp->HasValueByTimeStep(5, true));
106  CPPUNIT_ASSERT(!refProp->HasValueByTimeStep(5));
107  }
108 
109  void SetValue()
110  {
111  CPPUNIT_ASSERT_NO_THROW(refProp->SetValue(8, 9, "v_8_9"));
112  CPPUNIT_ASSERT(refProp->GetValue(8, 9) == "v_8_9");
113 
114  CPPUNIT_ASSERT_NO_THROW(refProp->SetValue("newValue"));
115  CPPUNIT_ASSERT(refProp->GetValue(0, 0) == "newValue");
116  CPPUNIT_ASSERT(refProp->GetAvailableTimeSteps().size() == 1);
117  CPPUNIT_ASSERT(refProp->GetAvailableSlices(0).size() == 1);
118  }
119 
121  {
123  CPPUNIT_ASSERT(refJSON ==
124  data); //"Testing serializeTemporoSpatialStringPropertyToJSON() producing correct string.");
125  }
126 
128  {
131 
132  mitk::TemporoSpatialStringProperty *tsProp = dynamic_cast<mitk::TemporoSpatialStringProperty *>(prop.GetPointer());
133 
134  CPPUNIT_ASSERT(
135  tsProp->GetValue(0, 0) ==
136  "v_0_0"); //"Testing deserializeJSONToTemporoSpatialStringProperty() producing property with correct value 1");
137  CPPUNIT_ASSERT(
138  tsProp->GetValue(3, 0) ==
139  "v_3_0"); //"Testing deserializeJSONToTemporoSpatialStringProperty() producing property with correct value 2");
140  CPPUNIT_ASSERT(
141  tsProp->GetValue(3, 2) ==
142  "v_3_2"); //"Testing deserializeJSONToTemporoSpatialStringProperty() producing property with correct value 3");
143  CPPUNIT_ASSERT(
144  tsProp->GetValue(6, 1) ==
145  "v_6_1"); //"Testing deserializeJSONToTemporoSpatialStringProperty() producing property with correct value 4");
146  CPPUNIT_ASSERT(*tsProp == *refProp); //"Testing deserializeJSONToTemporoSpatialStringProperty()");
147  }
148 };
149 
150 MITK_TEST_SUITE_REGISTRATION(mitkTemporoSpatialStringProperty)
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
MITKCORE_EXPORT::std::string serializeTemporoSpatialStringPropertyToJSON(const mitk::BaseProperty *prop)
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
Test fixture for parameterized tests.
MITKCORE_EXPORT mitk::BaseProperty::Pointer deserializeJSONToTemporoSpatialStringProperty(const std::string &value)
Property for time and space resolved string values.