Skip to content

Commit

Permalink
Fix boost
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonMarechal25 committed May 27, 2024
1 parent fa54839 commit 99fc322
Show file tree
Hide file tree
Showing 12 changed files with 299 additions and 291 deletions.
454 changes: 226 additions & 228 deletions src/CMakeLists.txt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
*/
#include <list> // Fix for Boost < 1.67

#define BOOST_TEST_MODULE test-end-to-end tests_binding_constraints
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE test - end - to - end tests_binding_constraints
#define WIN32_LEAN_AND_MEAN
#include <boost/test/data/test_case.hpp>
#include <boost/test/unit_test.hpp>
Expand Down
3 changes: 1 addition & 2 deletions src/tests/end-to-end/simple_study/simple-study.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
*/
#include <list> // Fix for Boost < 1.67

#define BOOST_TEST_MODULE test-end-to-end tests
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE test - end - to - end tests
#include <boost/test/data/test_case.hpp>
#include <boost/test/unit_test.hpp>

Expand Down
46 changes: 26 additions & 20 deletions src/tests/src/api_internal/test_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,42 +20,48 @@
*/

#define BOOST_TEST_MODULE test api
#define BOOST_TEST_DYN_LINK

#define WIN32_LEAN_AND_MEAN

#include <boost/test/unit_test.hpp>
#include <filesystem>

#include <boost/test/unit_test.hpp>

#include "API.h"
#include "in-memory-study.h"

class InMemoryStudyLoader : public Antares::IStudyLoader
class InMemoryStudyLoader: public Antares::IStudyLoader
{
public:
explicit InMemoryStudyLoader(bool success = true) : success_(success) {};
[[nodiscard]] std::unique_ptr<Antares::Data::Study> load() const override {
if (!success_) {
return nullptr;
}
StudyBuilder builder;
builder.addAreaToStudy("area1");
builder.addAreaToStudy("area2");
builder.study->initializeRuntimeInfos();
builder.study->parameters.resultFormat = ResultFormat::inMemory;
builder.study->prepareOutput();
return std::move(builder.study);
};
explicit InMemoryStudyLoader(bool success = true):
success_(success){};

[[nodiscard]] std::unique_ptr<Antares::Data::Study> load() const override
{
if (!success_)
{
return nullptr;
}
StudyBuilder builder;
builder.addAreaToStudy("area1");
builder.addAreaToStudy("area2");
builder.study->initializeRuntimeInfos();
builder.study->parameters.resultFormat = ResultFormat::inMemory;
builder.study->prepareOutput();
return std::move(builder.study);
}

bool success_ = true;
};


BOOST_AUTO_TEST_CASE(simulation_path_points_to_results)
{
Antares::API::APIInternal api;
auto study_loader = std::make_unique<InMemoryStudyLoader>();
auto results = api.run(*study_loader.get());
BOOST_CHECK_EQUAL(results.simulationPath, std::filesystem::path{"no_output"});
//Testing for "no_output" is a bit weird, but it's the only way to test this without actually running the simulation
// Testing for "no_output" is a bit weird, but it's the only way to test this without actually
// running the simulation
}

BOOST_AUTO_TEST_CASE(api_run_contains_antares_problem)
Expand All @@ -77,7 +83,7 @@ BOOST_AUTO_TEST_CASE(result_failure_when_study_is_null)
BOOST_CHECK(results.error);
}

//Test where data in problems are consistant with data in study
// Test where data in problems are consistant with data in study
BOOST_AUTO_TEST_CASE(result_contains_problems)
{
Antares::API::APIInternal api;
Expand All @@ -87,4 +93,4 @@ BOOST_AUTO_TEST_CASE(result_contains_problems)
BOOST_CHECK(!results.antares_problems.empty());
BOOST_CHECK(!results.error);
BOOST_CHECK_EQUAL(results.antares_problems.weeklyProblems.size(), 52);
}
}
7 changes: 4 additions & 3 deletions src/tests/src/api_lib/test_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@
*/

#define BOOST_TEST_MODULE test api
#define BOOST_TEST_DYN_LINK

#define WIN32_LEAN_AND_MEAN

#include <boost/test/unit_test.hpp>

#include "antares/api/solver.h"

BOOST_AUTO_TEST_CASE(result_failure_when_study_path_invalid) {
BOOST_AUTO_TEST_CASE(result_failure_when_study_path_invalid)
{
using namespace std::string_literals;
auto results = Antares::API::PerformSimulation("dummy"s);
BOOST_CHECK(results.error);
BOOST_CHECK(!results.error->reason.empty());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/

#define BOOST_TEST_MODULE test - benchmarking
#define BOOST_TEST_DYN_LINK
#include <thread>

#include <boost/test/unit_test.hpp>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include <list> // Fix for Boost < 1.67

#define BOOST_TEST_MODULE test - concurrency tests
#define BOOST_TEST_DYN_LINK
#include <boost/test/data/test_case.hpp>
#include <boost/test/unit_test.hpp>

Expand Down
1 change: 0 additions & 1 deletion src/tests/src/libs/antares/inifile/test_inifile_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
* along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
*/
#define BOOST_TEST_MODULE "test inifile IO"
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>

#include "antares/inifile/inifile.h"
Expand Down
1 change: 0 additions & 1 deletion src/tests/src/libs/antares/test_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
* along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
*/
#define BOOST_TEST_MODULE test utils
#define BOOST_TEST_DYN_LINK
#include <string>

#include <boost/test/unit_test.hpp>
Expand Down
1 change: 0 additions & 1 deletion src/tests/src/libs/antares/writer/test_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include <list> // Fix for Boost < 1.67

#define BOOST_TEST_MODULE test - writer tests
#define BOOST_TEST_DYN_LINK
#include <boost/test/data/test_case.hpp>
#include <boost/test/unit_test.hpp>

Expand Down
22 changes: 12 additions & 10 deletions src/tests/src/solver/lps/test_lps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
*/

#define BOOST_TEST_MODULE test translator
#define BOOST_TEST_DYN_LINK

#define WIN32_LEAN_AND_MEAN

#include <boost/test/unit_test.hpp>

#include <antares/solver/lps/LpsFromAntares.h>

using namespace Antares::Solver;
Expand Down Expand Up @@ -58,19 +58,21 @@ BOOST_AUTO_TEST_CASE(lps_with_both_constant_and_weekly_data_is_not_empty)
BOOST_CHECK(!lps.empty());
}

BOOST_AUTO_TEST_CASE(replace_const_data) {
LpsFromAntares lps;
ConstantDataFromAntares var;
var.VariablesCount = 42;
lps.setConstantData(var);
BOOST_CHECK(lps.constantProblemData.VariablesCount == 42);
BOOST_AUTO_TEST_CASE(replace_const_data)
{
LpsFromAntares lps;
ConstantDataFromAntares var;
var.VariablesCount = 42;
lps.setConstantData(var);
BOOST_CHECK(lps.constantProblemData.VariablesCount == 42);
}

//Add weekly data for week 1 year 1
BOOST_AUTO_TEST_CASE(add_weekly_data_for_week_1_year_1) {
// Add weekly data for week 1 year 1
BOOST_AUTO_TEST_CASE(add_weekly_data_for_week_1_year_1)
{
LpsFromAntares lps;
WeeklyDataFromAntares w;
w.RHS.push_back(43);
lps.addWeeklyData({1, 1}, w);
BOOST_CHECK(lps.weeklyData({1, 1}).RHS.size() != WeeklyDataFromAntares().RHS.size());
}
}
50 changes: 29 additions & 21 deletions src/tests/src/solver/optimisation/translator/test_translator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,45 @@
*/

#define BOOST_TEST_MODULE test translator
#define BOOST_TEST_DYN_LINK

#define WIN32_LEAN_AND_MEAN

#include <span>

#include <boost/test/unit_test.hpp>

#include <antares/solver/optimisation/HebdoProblemToLpsTranslator.h>
#include <span>
#include "antares/solver/optimisation/opt_period_string_generator_base.h"

using namespace Antares::Solver;

class StubOptPeriodStringGenerator : public OptPeriodStringGenerator {
class StubOptPeriodStringGenerator: public OptPeriodStringGenerator
{
public:
std::string to_string() const override {
std::string to_string() const override
{
return "Plop";
}
};

BOOST_AUTO_TEST_CASE(null_hebdo_is_empty_lps) {
BOOST_AUTO_TEST_CASE(null_hebdo_is_empty_lps)
{
HebdoProblemToLpsTranslator translator;
auto ret = translator.translate(nullptr, std::string());
BOOST_CHECK(ret == WeeklyDataFromAntares());
}

BOOST_AUTO_TEST_CASE(non_null_hebdo_returns_non_empty_lps) {
BOOST_AUTO_TEST_CASE(non_null_hebdo_returns_non_empty_lps)
{
HebdoProblemToLpsTranslator translator;
PROBLEME_ANTARES_A_RESOUDRE problemHebdo;
problemHebdo.CoutLineaire.push_back(45);
auto ret = translator.translate(&problemHebdo, std::string());
BOOST_CHECK(ret != WeeklyDataFromAntares());
}

BOOST_AUTO_TEST_CASE(Data_properly_copied) {
BOOST_AUTO_TEST_CASE(Data_properly_copied)
{
HebdoProblemToLpsTranslator translator;
PROBLEME_ANTARES_A_RESOUDRE problemHebdo;
problemHebdo.CoutLineaire = {0, 1, 2};
Expand All @@ -72,38 +78,43 @@ BOOST_AUTO_TEST_CASE(Data_properly_copied) {
BOOST_CHECK(ret.constraints == problemHebdo.NomDesContraintes);
}

BOOST_AUTO_TEST_CASE(translate_sens) {
BOOST_AUTO_TEST_CASE(translate_sens)
{
HebdoProblemToLpsTranslator translator;
PROBLEME_ANTARES_A_RESOUDRE problemHebdo;
problemHebdo.Sens = "<=>";

auto ret = translator.translate(&problemHebdo, std::string());
BOOST_CHECK(ret.Direction == std::vector({'<','=','>'}));
BOOST_CHECK(ret.Direction == std::vector({'<', '=', '>'}));
}

BOOST_AUTO_TEST_CASE(translate_name_is_filled) {
BOOST_AUTO_TEST_CASE(translate_name_is_filled)
{
HebdoProblemToLpsTranslator translator;
PROBLEME_ANTARES_A_RESOUDRE problemHebdo;

auto ret = translator.translate(&problemHebdo, "dummy");
BOOST_CHECK(!ret.name.empty());
}

BOOST_AUTO_TEST_CASE(translate_name_is_properly_filled) {
BOOST_AUTO_TEST_CASE(translate_name_is_properly_filled)
{
HebdoProblemToLpsTranslator translator;
PROBLEME_ANTARES_A_RESOUDRE problemHebdo;

auto ret = translator.translate(&problemHebdo, "problem-Plop--optim-nb-1.mps");
BOOST_CHECK_EQUAL(ret.name, "problem-Plop--optim-nb-1.mps");
}

BOOST_AUTO_TEST_CASE(empty_problem_empty_const_data) {
HebdoProblemToLpsTranslator translator;
auto ret = translator.commonProblemData(nullptr);
BOOST_CHECK(ret == ConstantDataFromAntares());
BOOST_AUTO_TEST_CASE(empty_problem_empty_const_data)
{
HebdoProblemToLpsTranslator translator;
auto ret = translator.commonProblemData(nullptr);
BOOST_CHECK(ret == ConstantDataFromAntares());
}

BOOST_AUTO_TEST_CASE(common_data_properly_copied) {
BOOST_AUTO_TEST_CASE(common_data_properly_copied)
{
HebdoProblemToLpsTranslator translator;
PROBLEME_ANTARES_A_RESOUDRE problemHebdo;
problemHebdo.NombreDeVariables = 1;
Expand All @@ -114,8 +125,6 @@ BOOST_AUTO_TEST_CASE(common_data_properly_copied) {
problemHebdo.CoefficientsDeLaMatriceDesContraintes = {0, 1, 2, 3, 4, 5};
problemHebdo.IndicesColonnes = {0, 1, 2, 3, 4, 5};



auto ret = translator.commonProblemData(&problemHebdo);
BOOST_CHECK_EQUAL(ret.VariablesCount, problemHebdo.NombreDeVariables);
BOOST_CHECK_EQUAL(ret.ConstraintesCount, problemHebdo.NombreDeContraintes);
Expand All @@ -125,7 +134,7 @@ BOOST_AUTO_TEST_CASE(common_data_properly_copied) {
BOOST_CHECK(std::ranges::equal(ret.Mdeb, problemHebdo.IndicesDebutDeLigne));
}

//throw exception if NombreDeVariables is 0
// throw exception if NombreDeVariables is 0
BOOST_AUTO_TEST_CASE(throw_exception_if_NombreDeVariables_is_0)
{
HebdoProblemToLpsTranslator translator;
Expand Down Expand Up @@ -164,7 +173,7 @@ BOOST_AUTO_TEST_CASE(throw_exception_if_NombreDeTermesDesLignes_out_of_bound)
BOOST_CHECK_THROW(translator.commonProblemData(&problemHebdo), std::runtime_error);
}

//NombreDeCoefficients
// NombreDeCoefficients
BOOST_AUTO_TEST_CASE(NombreDeCoefficients_is_properly_computed)
{
HebdoProblemToLpsTranslator translator;
Expand All @@ -179,4 +188,3 @@ BOOST_AUTO_TEST_CASE(NombreDeCoefficients_is_properly_computed)
auto ret = translator.commonProblemData(&problemHebdo);
BOOST_CHECK_EQUAL(ret.CoeffCount, 9);
}

0 comments on commit 99fc322

Please sign in to comment.