Medical Imaging Interaction Toolkit  2018.4.99-b20efe7f
Medical Imaging Interaction Toolkit
mitkModelFitStaticParameterMapTest.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 <iostream>
14 #include "mitkTestingMacros.h"
15 
17 #include "mitkModelFitException.h"
18 
19 int mitkModelFitStaticParameterMapTest(int /*argc*/, char*[] /*argv[]*/)
20 {
21  MITK_TEST_BEGIN("mitkModelFitStaticParameterMapTest")
22 
25  list.push_back(0);
26  map.Add("test", list);
27  MITK_TEST_CONDITION_REQUIRED(map.Get("test").size() == 1 &&
28  map.Get("test").front() == 0,
29  "Testing if Add successfully adds a new list.");
30 
31  map.Add("test", list);
32  MITK_TEST_CONDITION_REQUIRED(map.Get("test").size() == 1 &&
33  map.Get("test")[0] == 0,
34  "Testing if Add doesn't add to an existing list.");
35 
36  MITK_TEST_FOR_EXCEPTION(std::range_error, map.Get(""));
37 
39  list2.push_back(3);
40  map.Add("abc", list2);
41  MITK_TEST_CONDITION_REQUIRED(map.Get("test").size() == 1 &&
42  map.Get("test").front() == 0 &&
43  map.Get("abc").size() == 1 &&
44  map.Get("abc").front() == 3,
45  "Testing if Get returns the correct list.");
46 
47  list.push_back(1);
48  map.Add("def", list);
49  list.push_back(2);
50  // Adding a list with 3 values when there's already a list with two values
52 
53  map.Clear();
54  MITK_TEST_FOR_EXCEPTION(std::range_error, map.Get("test"));
55 
56  list2.push_back(5);
57  list2.push_back(2);
58  list2.push_back(4);
59  list2.push_back(1);
61  list3.push_back(3);
62  list3.push_back(1);
63  list3.push_back(4);
64  list3.push_back(2);
65  list3.push_back(5);
66  map.Add("abc", list2);
67  map.Add("def", list3);
68  map.Sort();
69  MITK_TEST_CONDITION_REQUIRED(map.Get("abc")[0] == 1 &&
70  map.Get("abc")[1] == 2 &&
71  map.Get("abc")[2] == 3 &&
72  map.Get("abc")[3] == 4 &&
73  map.Get("abc")[4] == 5 &&
74  map.Get("def")[0] == 5 &&
75  map.Get("def")[1] == 4 &&
76  map.Get("def")[2] == 3 &&
77  map.Get("def")[3] == 2 &&
78  map.Get("def")[4] == 1,
79  "Testing if Sort successfully sorts by the first key");
80 
81  map.Sort("def");
82  MITK_TEST_CONDITION_REQUIRED(map.Get("abc")[0] == 5 &&
83  map.Get("abc")[1] == 4 &&
84  map.Get("abc")[2] == 3 &&
85  map.Get("abc")[3] == 2 &&
86  map.Get("abc")[4] == 1 &&
87  map.Get("def")[0] == 1 &&
88  map.Get("def")[1] == 2 &&
89  map.Get("def")[2] == 3 &&
90  map.Get("def")[3] == 4 &&
91  map.Get("def")[4] == 5,
92  "Testing if Sort successfully sorts by the given key");
93 
95  list4.push_back(0);
96  map.Clear();
97  map.Add("ghi", list4);
98  map.Add("abc", list2);
99  map.Add("def", list3);
100 
101  map.Sort();
102  MITK_TEST_CONDITION_REQUIRED(map.Get("ghi")[0] == 0 &&
103  map.Get("abc")[0] == 1 &&
104  map.Get("abc")[1] == 2 &&
105  map.Get("abc")[2] == 3 &&
106  map.Get("abc")[3] == 4 &&
107  map.Get("abc")[4] == 5 &&
108  map.Get("def")[0] == 5 &&
109  map.Get("def")[1] == 4 &&
110  map.Get("def")[2] == 3 &&
111  map.Get("def")[3] == 2 &&
112  map.Get("def")[4] == 1,
113  "Testing if Sort successfully sorts if the map includes " <<
114  "one-value-lists");
115 
116  MITK_TEST_END()
117 }
ModelBase::StaticParameterValuesType ValueType
Type of the map value.
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
int mitkModelFitStaticParameterMapTest(int, char *[])
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
#define MITK_TEST_FOR_EXCEPTION(EXCEPTIONCLASS, STATEMENT)
Simplified version of MITK_TEST_FOR_EXCEPTION_BEGIN / END for a single statement. ...
void Add(const std::string &name, const ValueType &newList)
Adds the given value list under the given variable name if the name doesn&#39;t exist already...
void Clear()
Resets the map, so it&#39;s empty.
const ValueType & Get(const std::string &name) const
Returns the values of the given variable name.
MITKMATCHPOINTREGISTRATION_EXPORT ResultImageType::Pointer map(const InputImageType *input, const RegistrationType *registration, bool throwOnOutOfInputAreaError=false, const double &paddingValue=0, const ResultImageGeometryType *resultGeometry=nullptr, bool throwOnMappingError=true, const double &errorValue=0, mitk::ImageMappingInterpolator::Type interpolatorType=mitk::ImageMappingInterpolator::Linear)
Class-specific exception for modelfits.
void Sort(const std::string &name="")
Sorts the values of the given variable name in ascending order. The values of all other variables wil...
and MITK_TEST_END()