13 #ifndef MITKMODELTESTFIXTURE_H
14 #define MITKMODELTESTFIXTURE_H
20 #include <itksys/SystemTools.hxx>
24 #include <nlohmann/json.hpp>
39 std::ifstream file(pathToFile);
43 MITK_ERROR <<
"Could not open \"" << pathToFile <<
"\"!";
47 json_obj = nlohmann::json::parse(file);
49 catch (
const json::exception& e)
59 testparameters.SetSize(modelValues_json_obj[
"modelParameterValues"].size());
60 for (
unsigned long i = 0; i < modelValues_json_obj[
"modelParameterValues"].size(); ++i)
62 testparameters[i] = modelValues_json_obj[
"modelParameterValues"][i];
64 return testparameters;
70 for (
unsigned long i = 0; i < modelValues_json_obj[
"staticParameterValues"].size(); ++i)
74 staticParameterName = profile_json_obj[
"staticParameterNames"][i];
75 for (
unsigned int j = 0; j < modelValues_json_obj[
"staticParameterValues"][i].size(); ++j)
77 staticParameterValues.push_back(modelValues_json_obj[
"staticParameterValues"][i][j]);
79 staticParameterMap.insert(std::make_pair(staticParameterName, staticParameterValues));
81 return staticParameterMap;
88 testmodel->SetStaticParameters(staticParameterMap);
93 CPPUNIT_ASSERT_MESSAGE(
"Checking number of parameters in model.", testmodel->GetNumberOfParameters() == profile_json_obj[
"numberOfParameters"]);
94 for (
unsigned long i = 0; i < profile_json_obj[
"numberOfParameters"]; i++)
96 CPPUNIT_ASSERT_MESSAGE(
"Checking parameter names.", testmodel->GetParameterNames()[i] == profile_json_obj[
"parameterNames"][i]);
97 CPPUNIT_ASSERT_MESSAGE(
"Checking parameter scales.", testmodel->GetParameterScales()[testmodel->GetParameterNames()[i]] == profile_json_obj[
"parameterScales"][i]);
98 CPPUNIT_ASSERT_MESSAGE(
"Checking parameter units.", testmodel->GetParameterUnits()[testmodel->GetParameterNames()[i]] == profile_json_obj[
"parameterUnits"][i]);
100 CPPUNIT_ASSERT_MESSAGE(
"Checking number of derived parameters in model.", testmodel->GetNumberOfDerivedParameters() == profile_json_obj[
"numberOfDerivedParameters"]);
101 for (
unsigned long i = 0; i < profile_json_obj[
"numberOfDerivedParameters"]; i++)
103 CPPUNIT_ASSERT_MESSAGE(
"Checking derived parameter names.", testmodel->GetDerivedParameterNames()[i] == profile_json_obj[
"derivedParameterNames"][i]);
104 CPPUNIT_ASSERT_MESSAGE(
"Checking derived parameter scales.", testmodel->GetDerivedParameterScales()[testmodel->GetDerivedParameterNames()[i]] == profile_json_obj[
"derivedParameterScales"][i]);
105 CPPUNIT_ASSERT_MESSAGE(
"Checking derived parameter units.", testmodel->GetDerivedParameterUnits()[testmodel->GetDerivedParameterNames()[i]] == profile_json_obj[
"derivedParameterUnits"][i]);
107 CPPUNIT_ASSERT_MESSAGE(
"Checking number of static parameters in model.", testmodel->GetNumberOfStaticParameters() == profile_json_obj[
"numberOfStaticParameters"]);
108 for (
unsigned long i = 0; i < profile_json_obj[
"numberOfStaticParameters"]; i++)
110 CPPUNIT_ASSERT_MESSAGE(
"Checking static parameter names.", testmodel->GetStaticParameterNames()[i] == profile_json_obj[
"staticParameterNames"][i]);
111 CPPUNIT_ASSERT_MESSAGE(
"Checking static parameter units.", testmodel->GetStaticParameterUnits()[testmodel->GetStaticParameterNames()[i]] == profile_json_obj[
"staticParameterUnits"][i]);
113 CPPUNIT_ASSERT_MESSAGE(
"Checking function string.", testmodel->GetFunctionString() == profile_json_obj[
"functionString"]);
114 CPPUNIT_ASSERT_MESSAGE(
"Checking class ID.", testmodel->GetClassID() == profile_json_obj[
"classID"]);
115 CPPUNIT_ASSERT_MESSAGE(
"Checking model display name.", testmodel->GetModelDisplayName() == profile_json_obj[
"modelDisplayName"]);
116 CPPUNIT_ASSERT_MESSAGE(
"Checking model type.", testmodel->GetModelType() == profile_json_obj[
"modelType"]);
117 CPPUNIT_ASSERT_MESSAGE(
"Checking x name.", testmodel->GetXName() == profile_json_obj[
"xName"]);
118 CPPUNIT_ASSERT_MESSAGE(
"Checking x axis name.", testmodel->GetXAxisName() == profile_json_obj[
"xAxisName"]);
119 CPPUNIT_ASSERT_MESSAGE(
"Checking x axis unit.", testmodel->GetXAxisUnit() == profile_json_obj[
"xAxisUnit"]);
120 CPPUNIT_ASSERT_MESSAGE(
"Checking y axis name.", testmodel->GetYAxisName() == profile_json_obj[
"yAxisName"]);
121 CPPUNIT_ASSERT_MESSAGE(
"Checking y axis unit.", testmodel->GetYAxisUnit() == profile_json_obj[
"yAxisUnit"]);
127 for (
unsigned int j = 0; j < modelValues_json_obj[
"modelValues"].size(); j++)
129 json modelValues_json_obj_current = modelValues_json_obj[
"modelValues"][j];
135 timeGrid.SetSize(modelValues_json_obj_current[
"timeGrid"].size());
136 for (
unsigned long i = 0; i < modelValues_json_obj_current[
"timeGrid"].size(); ++i)
138 timeGrid[i] = modelValues_json_obj_current[
"timeGrid"][i];
140 testmodel->SetTimeGrid(timeGrid);
148 signal = testmodel->GetSignal(testparameters);
153 std::stringstream ss;
154 ss <<
"Checking signal for model parameter set " << j <<
".";
155 std::string message = ss.str();
156 for (
unsigned long i = 0; i < signal.size(); i++)
158 CPPUNIT_ASSERT_MESSAGE(message,
mitk::Equal(signal[i], modelValues_json_obj_current[
"signal"][i], 1e-6,
true) ==
true);
165 for (
unsigned int j = 0; j < modelValues_json_obj[
"modelValues"].size(); j++)
167 json modelValues_json_obj_current = modelValues_json_obj[
"modelValues"][j];
171 timeGrid.SetSize(modelValues_json_obj_current[
"timeGrid"].size());
172 for (
unsigned long i = 0; i < modelValues_json_obj_current[
"timeGrid"].size(); ++i)
174 timeGrid[i] = modelValues_json_obj_current[
"timeGrid"][i];
176 testmodel->SetTimeGrid(timeGrid);
180 derivedParameterMap = testmodel->GetDerivedParameters(testparameters);
181 std::stringstream ss;
182 ss <<
"Checking derived parameters for model parameter set " << j <<
".";
183 std::string message = ss.str();
184 for (
unsigned long i = 0; i < modelValues_json_obj_current[
"derivedParameterValues"].size(); i++)
186 CPPUNIT_ASSERT_MESSAGE(message,
mitk::Equal(derivedParameterMap[testmodel->GetDerivedParameterNames()[i]], modelValues_json_obj_current[
"derivedParameterValues"][i], 1e-6,
true) ==
true);
192 #endif // MITKMODELTESTFIXTURE_H