Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitk::mitkModelTestFixture Class Reference

Test fixture base class for model fit unit tests. More...

#include <mitkModelTestFixture.h>

Inheritance diagram for mitk::mitkModelTestFixture:
Collaboration diagram for mitk::mitkModelTestFixture:

Static Public Member Functions

static json ParseJSONFile (const std::string path)
 Parse a JSON file from the test data directory. More...
 
static ModelBase::ParametersType ParseTestParameters (const json modelValues_json_obj)
 Extract model parameter values from a JSON object into a ParametersType array. More...
 
static ModelBase::StaticParameterMapType ParseStaticParameters (const json profile_json_obj, const json modelValues_json_obj)
 Parse static parameter names and values from JSON into a StaticParameterMapType. More...
 
static void SetStaticParametersForTest (mitk::ModelBase::Pointer testmodel, const json profile_json_obj, const json modelValues_json_obj)
 Convenience method that parses static parameters from JSON and applies them to a model. More...
 
static void CompareModelAndReferenceProfile (const mitk::ModelBase::Pointer testmodel, const json profile_json_obj)
 Assert that a model's profile (parameter names, scales, units, etc.) matches a JSON reference. More...
 
static void CompareModelAndReferenceSignal (mitk::ModelBase::Pointer testmodel, const json modelValues_json_obj, const json profile_json_obj)
 Assert that a model's computed signal matches a JSON reference for all parameter sets. More...
 
static void CompareModelAndReferenceDerivedParameters (const mitk::ModelBase::Pointer testmodel, json modelValues_json_obj)
 Assert that a model's derived parameters match a JSON reference for all parameter sets. More...
 

Additional Inherited Members

- Protected Member Functions inherited from mitk::TestFixture
std::vector< std::string > GetTestParameter () const
 Get parameters for this test fixture. More...
 
- Static Protected Member Functions inherited from mitk::TestFixture
static std::string GetTestDataFilePath (const std::string &testData)
 Get the absolute path for test data. More...
 

Detailed Description

Test fixture base class for model fit unit tests.

Provides static helper methods that load model reference data from JSON files and compare a model's profile, signal output, and derived parameters against the reference values. Subclass this fixture, set up your model in setUp(), and use the provided comparison methods in your test cases.

The expected JSON structure contains:

  • A "profile" object with numberOfParameters, parameterNames, parameterScales, parameterUnits, static parameter metadata, functionString, classID, etc.
  • A "modelValues" array with entries containing timeGrid, modelParameterValues, staticParameterValues, signal, and derivedParameterValues.
See also
mitk::ModelBase, mitk::TestFixture

Definition at line 55 of file mitkModelTestFixture.h.

Member Function Documentation

◆ CompareModelAndReferenceDerivedParameters()

static void mitk::mitkModelTestFixture::CompareModelAndReferenceDerivedParameters ( const mitk::ModelBase::Pointer  testmodel,
json  modelValues_json_obj 
)
inlinestatic

Assert that a model's derived parameters match a JSON reference for all parameter sets.

For each entry in the "modelValues" array, sets the time grid, computes the derived parameters via GetDerivedParameters(), and compares each value against the reference "derivedParameterValues" array with a tolerance of 1e-6.

Parameters
testmodelThe model instance to validate.
modelValues_json_objJSON object containing the "modelValues" array.

Definition at line 245 of file mitkModelTestFixture.h.

References mitk::Equal(), and ParseTestParameters().

◆ CompareModelAndReferenceProfile()

static void mitk::mitkModelTestFixture::CompareModelAndReferenceProfile ( const mitk::ModelBase::Pointer  testmodel,
const json  profile_json_obj 
)
inlinestatic

Assert that a model's profile (parameter names, scales, units, etc.) matches a JSON reference.

Checks numberOfParameters, parameterNames, parameterScales, parameterUnits, derived parameters, static parameters, functionString, classID, modelDisplayName, modelType, axis names, and axis units.

Parameters
testmodelThe model instance to validate.
profile_json_objJSON object containing the expected profile values.

Definition at line 152 of file mitkModelTestFixture.h.

◆ CompareModelAndReferenceSignal()

static void mitk::mitkModelTestFixture::CompareModelAndReferenceSignal ( mitk::ModelBase::Pointer  testmodel,
const json  modelValues_json_obj,
const json  profile_json_obj 
)
inlinestatic

Assert that a model's computed signal matches a JSON reference for all parameter sets.

For each entry in the "modelValues" array, sets the static parameters and time grid, computes the signal via GetSignal(), and compares each sample against the reference "signal" array with a tolerance of 1e-6.

Parameters
testmodelThe model instance to validate.
modelValues_json_objJSON object containing the "modelValues" array.
profile_json_objJSON object containing static parameter names.

Definition at line 196 of file mitkModelTestFixture.h.

References mitk::Equal(), ParseTestParameters(), and SetStaticParametersForTest().

◆ ParseJSONFile()

static json mitk::mitkModelTestFixture::ParseJSONFile ( const std::string  path)
inlinestatic

Parse a JSON file from the test data directory.

Parameters
pathRelative path to the JSON file within the MITK test data directory.
Returns
The parsed JSON object. Returns an empty object if the file cannot be opened or parsed.

Definition at line 64 of file mitkModelTestFixture.h.

References mitk::TestFixture::GetTestDataFilePath(), and MITK_ERROR.

◆ ParseStaticParameters()

static ModelBase::StaticParameterMapType mitk::mitkModelTestFixture::ParseStaticParameters ( const json  profile_json_obj,
const json  modelValues_json_obj 
)
inlinestatic

Parse static parameter names and values from JSON into a StaticParameterMapType.

Parameters
profile_json_objJSON object containing "staticParameterNames".
modelValues_json_objJSON object containing "staticParameterValues".
Returns
A map of static parameter names to their value vectors.

Definition at line 111 of file mitkModelTestFixture.h.

Referenced by SetStaticParametersForTest().

◆ ParseTestParameters()

static ModelBase::ParametersType mitk::mitkModelTestFixture::ParseTestParameters ( const json  modelValues_json_obj)
inlinestatic

Extract model parameter values from a JSON object into a ParametersType array.

Reads the "modelParameterValues" array from the JSON object and returns it as a ModelBase::ParametersType.

Parameters
modelValues_json_objJSON object containing a "modelParameterValues" array.
Returns
The parsed parameter values.

Definition at line 93 of file mitkModelTestFixture.h.

Referenced by CompareModelAndReferenceDerivedParameters(), and CompareModelAndReferenceSignal().

◆ SetStaticParametersForTest()

static void mitk::mitkModelTestFixture::SetStaticParametersForTest ( mitk::ModelBase::Pointer  testmodel,
const json  profile_json_obj,
const json  modelValues_json_obj 
)
inlinestatic

Convenience method that parses static parameters from JSON and applies them to a model.

Parameters
testmodelThe model instance to configure.
profile_json_objJSON object containing "staticParameterNames".
modelValues_json_objJSON object containing "staticParameterValues".

Definition at line 135 of file mitkModelTestFixture.h.

References ParseStaticParameters().

Referenced by CompareModelAndReferenceSignal().


The documentation for this class was generated from the following file: