Skip to content

Commit

Permalink
Fix, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
flomnes committed Dec 18, 2024
1 parent b125fc9 commit 17a40f1
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/solver/modeler/parameters/encoder.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ struct convert<Antares::Solver::ModelerParameters>
{
static bool decode(const Node& node, Antares::Solver::ModelerParameters& rhs)
{
if (!node.IsMap())
{
return false;
}
rhs.solver = node["solver"].as<std::string>();
rhs.solverLogs = node["description"].as<bool>(false);
rhs.solverLogs = node["solver-logs"].as<bool>(false);
rhs.solverParameters = node["solver-parameters"].as<std::string>();
rhs.noOutput = node["no-output"].as<bool>(false);
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#pragma once

#include <filesystem>
#include <modelerParameters.h>

#include <antares/solver/modeler/parameters/modelerParameters.h>

namespace Antares::Solver
{
Expand Down
1 change: 1 addition & 0 deletions src/tests/src/solver/modeler/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
add_subdirectory(api)
add_subdirectory(parameters)
14 changes: 14 additions & 0 deletions src/tests/src/solver/modeler/parameters/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Zip writer
add_executable(parse-parameters testParametersParsing.cpp)

target_link_libraries(parse-parameters
PRIVATE
Boost::unit_test_framework
modeler-parameters
test_utils_unit
)

set_target_properties(parse-parameters PROPERTIES FOLDER Unit-tests/test-writer)

add_test(NAME parse-parameters COMMAND parse-parameters)
set_tests_properties(parse-parameters PROPERTIES LABELS unit)
54 changes: 54 additions & 0 deletions src/tests/src/solver/modeler/parameters/testParametersParsing.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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 <fstream>
#define BOOST_TEST_MODULE parse modeler parameters

#include <boost/test/unit_test.hpp>

#include <antares/solver/modeler/parameters/parseModelerParameters.h>

#include "files-system.h"

BOOST_AUTO_TEST_SUITE(read_modeler_parameters)

BOOST_AUTO_TEST_CASE(simple)
{
const auto working_tmp_dir = CREATE_TMP_DIR_BASED_ON_TEST_NAME();
const auto fileP = working_tmp_dir / "parameters.yaml";
{
std::ofstream param(fileP);
param << R"(
solver: sirius
solver-logs: false
solver-parameters: PRESOLVE 1
no-output: true)";
}

auto params = Antares::Solver::parseModelerParameters(fileP);
BOOST_CHECK_EQUAL(params.solver, "sirius");
BOOST_CHECK_EQUAL(params.solverLogs, false);
BOOST_CHECK_EQUAL(params.solverParameters, "PRESOLVE 1");
BOOST_CHECK_EQUAL(params.noOutput, true);
}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit 17a40f1

Please sign in to comment.