Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
payetvin committed Dec 17, 2024
1 parent d6fb19b commit 5954300
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
16 changes: 7 additions & 9 deletions src/solver/systemParser/converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ static std::pair<std::string, std::string> splitLibraryModelString(const std::st
return {library, model};
}

static const SystemModel::Model* getModel(const std::vector<SystemModel::Library>& libraries,
static const SystemModel::Model& getModel(const std::vector<SystemModel::Library>& libraries,
const std::string& libraryId,
const std::string& modelId)
{
Expand All @@ -82,15 +82,13 @@ static const SystemModel::Model* getModel(const std::vector<SystemModel::Library
throw LibraryNotFound(libraryId);
}

try
{
auto& model = lib->Models().at(modelId);
return &model;
}
catch (const std::out_of_range&)
auto search = lib->Models().find(modelId);
if (search == lib->Models().end())
{
throw ModelNotFound(modelId);
}

return search->second;
}

static SystemModel::Component createComponent(const SystemParser::Component& c,
Expand All @@ -99,7 +97,7 @@ static SystemModel::Component createComponent(const SystemParser::Component& c,
const auto [libraryId, modelId] = splitLibraryModelString(c.model);
SystemModel::ModelBuilder model_builder;

const SystemModel::Model* model = getModel(libraries, libraryId, modelId);
const SystemModel::Model& model = getModel(libraries, libraryId, modelId);

SystemModel::ComponentBuilder component_builder;

Expand All @@ -110,7 +108,7 @@ static SystemModel::Component createComponent(const SystemParser::Component& c,
}

auto component = component_builder.withId(c.id)
.withModel(model)
.withModel(&model)
.withScenarioGroupId(c.scenarioGroup)
.withParameterValues(parameters)
.build();
Expand Down
18 changes: 12 additions & 6 deletions src/tests/src/study/system-model/test_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ BOOST_AUTO_TEST_CASE(fail_on_no_params1)
.withScenarioGroupId("scenario_group");
BOOST_CHECK_EXCEPTION(component_builder.build(),
std::invalid_argument,
checkMessage("The component \"component\" has 0 parameter(s), but its model has 2"));
checkMessage(
"The component \"component\" has 0 parameter(s), but its model has 2"));
}

BOOST_AUTO_TEST_CASE(fail_on_no_params2)
Expand All @@ -171,7 +172,8 @@ BOOST_AUTO_TEST_CASE(fail_on_no_params2)
.withScenarioGroupId("scenario_group");
BOOST_CHECK_EXCEPTION(component_builder.build(),
std::invalid_argument,
checkMessage("The component \"component\" has 0 parameter(s), but its model has 2"));
checkMessage(
"The component \"component\" has 0 parameter(s), but its model has 2"));
}

BOOST_AUTO_TEST_CASE(fail_on_missing_param)
Expand All @@ -183,7 +185,8 @@ BOOST_AUTO_TEST_CASE(fail_on_missing_param)
.withScenarioGroupId("scenario_group");
BOOST_CHECK_EXCEPTION(component_builder.build(),
std::invalid_argument,
checkMessage("The component \"component\" has 1 parameter(s), but its model has 2"));
checkMessage(
"The component \"component\" has 1 parameter(s), but its model has 2"));
}

BOOST_AUTO_TEST_CASE(fail_on_missing_wrong_param)
Expand All @@ -195,7 +198,8 @@ BOOST_AUTO_TEST_CASE(fail_on_missing_wrong_param)
.withScenarioGroupId("scenario_group");
BOOST_CHECK_EXCEPTION(component_builder.build(),
std::invalid_argument,
checkMessage("The component \"component\" has no value for parameter 'param1'"));
checkMessage(
"The component \"component\" has no value for parameter 'param1'"));
}

BOOST_AUTO_TEST_CASE(fail_on_too_many_params1)
Expand All @@ -207,7 +211,8 @@ BOOST_AUTO_TEST_CASE(fail_on_too_many_params1)
.withScenarioGroupId("scenario_group");
BOOST_CHECK_EXCEPTION(component_builder.build(),
std::invalid_argument,
checkMessage("The component \"component\" has 3 parameter(s), but its model has 2"));
checkMessage(
"The component \"component\" has 3 parameter(s), but its model has 2"));
}

BOOST_AUTO_TEST_CASE(fail_on_too_many_params2)
Expand All @@ -219,7 +224,8 @@ BOOST_AUTO_TEST_CASE(fail_on_too_many_params2)
.withScenarioGroupId("scenario_group");
BOOST_CHECK_EXCEPTION(component_builder.build(),
std::invalid_argument,
checkMessage("The component \"component\" has 1 parameter(s), but its model has 0"));
checkMessage(
"The component \"component\" has 1 parameter(s), but its model has 0"));
}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit 5954300

Please sign in to comment.