Skip to content

Commit

Permalink
use invisible delimiter
Browse files Browse the repository at this point in the history
  • Loading branch information
a-zakir committed Nov 8, 2024
1 parent 9dba113 commit 45ab2f1
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
107 changes: 54 additions & 53 deletions tests/cpp/logger/logger_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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("");
Expand Down Expand Up @@ -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;
Expand All @@ -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 =
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions tests/end_to_end/cucumber/features/steps/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 45ab2f1

Please sign in to comment.