From 45ab2f181100edf6ff8c6c73af878bf54a661b67 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Fri, 8 Nov 2024 12:43:59 +0100 Subject: [PATCH] use invisible delimiter --- .../benders/benders_core/BendersMathLogger.h | 2 +- tests/cpp/logger/logger_test.cpp | 107 +++++++++--------- .../cucumber/features/steps/steps.py | 4 +- 3 files changed, 57 insertions(+), 56 deletions(-) diff --git a/src/cpp/benders/benders_core/include/antares-xpansion/benders/benders_core/BendersMathLogger.h b/src/cpp/benders/benders_core/include/antares-xpansion/benders/benders_core/BendersMathLogger.h index 9b1fdc0eb..c1a62c16f 100644 --- a/src/cpp/benders/benders_core/include/antares-xpansion/benders/benders_core/BendersMathLogger.h +++ b/src/cpp/benders/benders_core/include/antares-xpansion/benders/benders_core/BendersMathLogger.h @@ -43,7 +43,7 @@ class LogDestination { std::ofstream file_stream_; std::ostream* stream_; std::streamsize width_ = 40; - std::string delimiter_ = "|"; + std::string delimiter_ = "\t"; public: void setDelimiter(const std::string& delimiter); diff --git a/tests/cpp/logger/logger_test.cpp b/tests/cpp/logger/logger_test.cpp index 5deeb1b15..b0feeaaf7 100644 --- a/tests/cpp/logger/logger_test.cpp +++ b/tests/cpp/logger/logger_test.cpp @@ -743,6 +743,7 @@ TEST_F(MasterLoggerTest, LogSwitchToInteger) { ASSERT_TRUE(_logger->_switchToIntegerCall); ASSERT_TRUE(_logger2->_switchToIntegerCall); } +static constexpr const char* const DELIMITER = "|"; TEST(LogDestinationTest, WithInvalidEmptyFilePath) { const std::filesystem::path invalid_file_path(""); @@ -867,10 +868,10 @@ TEST(MathLoggerBendersByBatchTest, HeadersListStdOutShort) { std::streamsize width = 25; std::ostringstream expected_msg; - expected_msg << "|"; + expected_msg << DELIMITER; for (const auto& header : headers_manager.HeadersList()) { expected_msg << std::setw(width) << std::left << header; - expected_msg << "|"; + expected_msg << DELIMITER; } expected_msg << std::endl; std::stringstream redirectedStdout; @@ -888,10 +889,10 @@ TEST(MathLoggerBendersByBatchTest, HeadersListFileLong) { std::streamsize width = 25; std::ostringstream expected_msg; - expected_msg << "|"; + expected_msg << DELIMITER; for (const auto& header : headers_manager.HeadersList()) { expected_msg << std::setw(width) << std::left << header; - expected_msg << "|"; + expected_msg << DELIMITER; } expected_msg << std::endl; auto log_file = @@ -923,39 +924,39 @@ TEST(MathLoggerBendersByBatchTest, DataInFileLong) { data.iteration_time - data.timer_master - data.subproblems_walltime; std::ostringstream expected_msg; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << data.it; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << std::scientific << std::setprecision(10) << data.lb; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << data.min_simplexiter; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << data.max_simplexiter; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << data.number_of_subproblem_solved; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << data.cumulative_number_of_subproblem_solved; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << std::setprecision(2) << data.iteration_time; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << std::setprecision(2) << data.timer_master; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << std::setprecision(2) << data.subproblems_walltime; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << std::setprecision(2) << data.subproblems_cumulative_cputime; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << std::setprecision(2) << time_not_solving; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::endl; auto log_file = CreateRandomSubDir(std::filesystem::temp_directory_path()) / "log.txt"; @@ -986,29 +987,29 @@ TEST(MathLoggerBendersByBatchTest, DataInStdOutShort) { data.iteration_time - data.timer_master - data.subproblems_walltime; std::ostringstream expected_msg; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << data.it; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << std::scientific << std::setprecision(10) << data.lb; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << data.min_simplexiter; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << data.max_simplexiter; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << data.number_of_subproblem_solved; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << std::setprecision(2) << data.iteration_time; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << std::setprecision(2) << data.timer_master; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << std::setprecision(2) << data.subproblems_walltime; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::endl; std::stringstream redirectedStdout; @@ -1041,52 +1042,52 @@ TEST(MathLoggerBendersBaseTest, DataInFileLong) { data.iteration_time - data.timer_master - data.subproblems_walltime; std::ostringstream expected_msg; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << data.it; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << std::scientific << std::setprecision(10) << data.lb; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << std::scientific << std::setprecision(10) << data.ub; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << std::scientific << std::setprecision(10) << data.best_ub; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << std::scientific << std::setprecision(2) << data.best_ub - data.lb; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << std::scientific << std::setprecision(2) << (data.best_ub - data.lb) / data.best_ub; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << data.min_simplexiter; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << data.max_simplexiter; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << data.number_of_subproblem_solved; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << data.cumulative_number_of_subproblem_solved; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << std::setprecision(2) << data.iteration_time; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << std::setprecision(2) << data.timer_master; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << std::setprecision(2) << data.subproblems_walltime; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << std::setprecision(2) << data.subproblems_cumulative_cputime; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << std::setprecision(2) << time_not_solving; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::endl; auto log_file = CreateRandomSubDir(std::filesystem::temp_directory_path()) / "log.txt"; @@ -1117,40 +1118,40 @@ TEST(MathLoggerBendersBaseTest, DataInStdOutShort) { data.iteration_time - data.timer_master - data.subproblems_walltime; std::ostringstream expected_msg; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << data.it; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << std::scientific << std::setprecision(10) << data.lb; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << std::scientific << std::setprecision(10) << data.ub; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << std::scientific << std::setprecision(10) << data.best_ub; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << std::scientific << std::setprecision(2) << data.best_ub - data.lb; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << std::scientific << std::setprecision(2) << (data.best_ub - data.lb) / data.best_ub; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << data.min_simplexiter; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << data.max_simplexiter; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << std::setprecision(2) << data.iteration_time; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << std::setprecision(2) << data.timer_master; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::left << std::setw(width) << std::setprecision(2) << data.subproblems_walltime; - expected_msg << "|"; + expected_msg << DELIMITER; expected_msg << std::endl; std::stringstream redirectedStdout; diff --git a/tests/end_to_end/cucumber/features/steps/steps.py b/tests/end_to_end/cucumber/features/steps/steps.py index df41f0369..85b876945 100644 --- a/tests/end_to_end/cucumber/features/steps/steps.py +++ b/tests/end_to_end/cucumber/features/steps/steps.py @@ -147,7 +147,7 @@ def check_solution(context): def read_table_from_string(raw_data): - reader = csv.reader(io.StringIO(raw_data), delimiter='|') + reader = csv.reader(io.StringIO(raw_data), delimiter='\t') header = [item.strip() for item in next(reader)[1:-1]] # Store the header row, ignoring the first and last columns current_results = [{header[index]: item.strip() for index, item in enumerate(row[1:-1])} for row in @@ -158,7 +158,7 @@ def read_table_from_string(raw_data): def read_cucumber_table_from_file(filename): with open(filename, 'r') as file: - reader = csv.reader(file, delimiter='|') + reader = csv.reader(file, delimiter='\t') header = [item.strip() for item in next(reader)[1:-1]] # Store the header row, ignoring the first and last columns current_results = [{header[index]: item.strip() for index, item in enumerate(row[1:-1])} for row in