Skip to content

Commit

Permalink
add test converter
Browse files Browse the repository at this point in the history
  • Loading branch information
payetvin committed Dec 13, 2024
1 parent 157c83a commit feed197
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 37 deletions.
1 change: 1 addition & 0 deletions src/tests/src/solver/modelParser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set(SOURCE_FILES
test_full.cpp
enum_operators.h
testSystemParser.cpp
testSystemConverter.cpp
)

# Add executable
Expand Down
70 changes: 70 additions & 0 deletions src/tests/src/solver/modelParser/testSystemConverter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright 2007-2024, RTE (https://www.rte-france.com)
* See AUTHORS.txt
* SPDX-License-Identifier: MPL-2.0
* This file is part of Antares-Simulator,
* Adequacy and Performance assessment for interconnected energy networks.
*
* Antares_Simulator is free software: you can redistribute it and/or modify
* it under the terms of the Mozilla Public Licence 2.0 as published by
* the Mozilla Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* Antares_Simulator is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Mozilla Public Licence 2.0 for more details.
*
* You should have received a copy of the Mozilla Public Licence 2.0
* along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
*/

#define WIN32_LEAN_AND_MEAN

#include <boost/test/unit_test.hpp>

#include <antares/solver/systemParser/converter.h>
#include <antares/solver/systemParser/parser.h>
#include <antares/study/system-model/system.h>

using namespace std::string_literals;
using namespace Antares::Solver;
using namespace Antares::Study;

BOOST_AUTO_TEST_CASE(parse_into_system_model)
{
SystemParser::Parser parser;
const auto system = R"(
system:
id: base_system
description: real application model
model-libraries: [std, mylib]
components:
- id: N
model: std.node
scenario-group: group-234
parameters:
- id: cost
type: constant
value: 30
- id: p_max
type: constant
value: 100
- id: G
model: mylib.generator
scenario-group: generator
)"s;

SystemParser::System systemObj = parser.parse(system);

auto systemModel = SystemConverter::convert(systemObj);

BOOST_CHECK_EQUAL(systemModel.Components().size(), 2);
BOOST_CHECK_EQUAL(systemModel.Components().at("N").Id(), "N");
BOOST_CHECK_EQUAL(systemModel.Components().at("G").Id(), "G");
BOOST_CHECK_EQUAL(systemModel.Components().at("G").getModel()->Id(), "generator");

/* BOOST_CHECK_EQUAL(systemModel.Components().at("N").getParameterValue("cost"), 30); */
/* BOOST_CHECK_EQUAL(systemModel.Components().at("N").getParameterValue("generator"), 100); */
}

37 changes: 0 additions & 37 deletions src/tests/src/solver/modelParser/testSystemParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,40 +182,3 @@ BOOST_AUTO_TEST_CASE(component_two_parameters)
BOOST_CHECK_EQUAL(param2.type, "constant");
BOOST_CHECK_EQUAL(param2.value, 100);
}

BOOST_AUTO_TEST_CASE(parse_into_system_model)
{
SystemParser::Parser parser;
const auto system = R"(
system:
id: base_system
description: real application model
model-libraries: [std, mylib]
components:
- id: N
model: std.node
scenario-group: group-234
parameters:
- id: cost
type: constant
value: 30
- id: p_max
type: constant
value: 100
- id: G
model: mylib.generator
scenario-group: generator
)"s;

SystemParser::System systemObj = parser.parse(system);

auto systemModel = SystemConverter::convert(systemObj);

BOOST_CHECK_EQUAL(systemModel.Components().size(), 2);
BOOST_CHECK_EQUAL(systemModel.Components().at("N").Id(), "N");
BOOST_CHECK_EQUAL(systemModel.Components().at("G").Id(), "G");
BOOST_CHECK_EQUAL(systemModel.Components().at("G").getModel()->Id(), "generator");

/* BOOST_CHECK_EQUAL(systemModel.Components().at("N").getParameterValue("cost"), 30); */
/* BOOST_CHECK_EQUAL(systemModel.Components().at("N").getParameterValue("generator"), 100); */
}

0 comments on commit feed197

Please sign in to comment.