From 74c882bbdbd47a5026876b33b83ce3477437d0c5 Mon Sep 17 00:00:00 2001 From: Mateusz Masiarz Date: Mon, 25 Sep 2023 11:59:33 +0200 Subject: [PATCH 1/3] Change order of tests in inwer --- src/sinol_make/commands/inwer/__init__.py | 2 +- src/sinol_make/commands/inwer/inwer_util.py | 14 ++++++++++---- src/sinol_make/structs/inwer_structs.py | 3 +++ tests/commands/inwer/test_unit.py | 11 +++++++++++ 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/sinol_make/commands/inwer/__init__.py b/src/sinol_make/commands/inwer/__init__.py index 58bf3e61..59ca28ba 100644 --- a/src/sinol_make/commands/inwer/__init__.py +++ b/src/sinol_make/commands/inwer/__init__.py @@ -92,7 +92,7 @@ def verify_and_print_table(self) -> Dict[str, TestResult]: has_terminal, terminal_width, terminal_height = util.get_terminal_size() - table_data = TableData(results, 0) + table_data = TableData(results, 0, self.task_id) if has_terminal: run_event = threading.Event() run_event.set() diff --git a/src/sinol_make/commands/inwer/inwer_util.py b/src/sinol_make/commands/inwer/inwer_util.py index 58ed5a9a..623d0886 100644 --- a/src/sinol_make/commands/inwer/inwer_util.py +++ b/src/sinol_make/commands/inwer/inwer_util.py @@ -37,6 +37,12 @@ def compile_inwer(inwer_path: str, args: argparse.Namespace, weak_compilation_fl return compile.compile_file(inwer_path, package_util.get_executable(inwer_path), compilers, weak_compilation_flags) +def sort_tests(tests, task_id): + # First sort by group, then by test name. + tests.sort(key=lambda test: [package_util.get_group(test, task_id), test]) + return tests + + def print_view(term_width, term_height, table_data: TableData): """ Prints current results of test verification. @@ -48,12 +54,12 @@ def print_view(term_width, term_height, table_data: TableData): results = table_data.results column_lengths = [0, len('Group') + 1, len('Status') + 1, 0] - sorted_test_paths = [] + tests = [] for result in results.values(): column_lengths[0] = max(column_lengths[0], len(result.test_name)) column_lengths[1] = max(column_lengths[1], len(result.test_group)) - sorted_test_paths.append(result.test_path) - sorted_test_paths.sort() + tests.append(result.test_path) + tests = sort_tests(tests, table_data.task_id) column_lengths[3] = max(10, term_width - column_lengths[0] - column_lengths[1] - column_lengths[2] - 9 - 3) # 9 is for " | " between columns, 3 for margin. margin = " " @@ -69,7 +75,7 @@ def print_line_separator(): " | " + "Output") print_line_separator() - for test_path in sorted_test_paths: + for test_path in tests: result = results[test_path] print(margin + result.test_name.ljust(column_lengths[0]) + " | ", end='') print(result.test_group.ljust(column_lengths[1] - 1) + " | ", end='') diff --git a/src/sinol_make/structs/inwer_structs.py b/src/sinol_make/structs/inwer_structs.py index f78d6f7c..8329ba9c 100644 --- a/src/sinol_make/structs/inwer_structs.py +++ b/src/sinol_make/structs/inwer_structs.py @@ -40,6 +40,9 @@ class TableData: # Number of executions finished i: int + # Task id + task_id: str + @dataclass class InwerExecution: test_path: str diff --git a/tests/commands/inwer/test_unit.py b/tests/commands/inwer/test_unit.py index 744fc404..ebfdae23 100644 --- a/tests/commands/inwer/test_unit.py +++ b/tests/commands/inwer/test_unit.py @@ -59,3 +59,14 @@ def test_asserting_inwer(create_package): print(res.output) print(assertion_re.match(res.output)) assert assertion_re.match(res.output) is not None + + +def test_tests_comparator(): + for ti in ["abc", "long_task_id", ""]: + assert inwer_util.sort_tests([f"{ti}2a.in", f"{ti}1a.in"], ti) == [f"{ti}1a.in", f"{ti}2a.in"] + assert inwer_util.sort_tests([f"{ti}2a.in", f"{ti}1a.in", f"{ti}1b.in"], ti) == \ + [f"{ti}1a.in", f"{ti}1b.in", f"{ti}2a.in"] + assert inwer_util.sort_tests([f"{ti}2a.in", f"{ti}1a.in", f"{ti}1b.in", f"{ti}10a.in"], ti) == \ + [f"{ti}1a.in", f"{ti}1b.in", f"{ti}2a.in", f"{ti}10a.in"] + assert inwer_util.sort_tests([f"{ti}2a.in", f"{ti}1a.in", f"{ti}1b.in", f"{ti}10a.in", f"{ti}10b.in"], ti) == \ + [f"{ti}1a.in", f"{ti}1b.in", f"{ti}2a.in", f"{ti}10a.in", f"{ti}10b.in"] From 3d3076eb9707286ccc2d60553a6de17cd51654ce Mon Sep 17 00:00:00 2001 From: Mateusz Masiarz Date: Mon, 25 Sep 2023 12:03:27 +0200 Subject: [PATCH 2/3] Change inwer template --- example_package/prog/abcinwer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example_package/prog/abcinwer.cpp b/example_package/prog/abcinwer.cpp index 2bfb3a5f..c629ec0c 100644 --- a/example_package/prog/abcinwer.cpp +++ b/example_package/prog/abcinwer.cpp @@ -38,13 +38,13 @@ int main() { }; string subtasks_s; for (auto [subtask_id, is_valid] : subtasks) - subtasks_s += is_valid ? to_string(subtask_id) : string("-"); + subtasks_s += is_valid ? to_string(subtask_id) : string("_"); map sample_tests = { {"0a", is_0a()}, {"1ocen", is_1ocen()}, }; - string sample_test_s = "-"; + string sample_test_s = "_"; for (auto [name, is_valid] : sample_tests) if (is_valid) sample_test_s = name; From 0fc3716143579c67339d8a8b7eae6cb0d0400025 Mon Sep 17 00:00:00 2001 From: Mateusz Masiarz Date: Mon, 25 Sep 2023 12:36:46 +0200 Subject: [PATCH 3/3] Revert "Change inwer template" This reverts commit 3d3076eb9707286ccc2d60553a6de17cd51654ce. --- example_package/prog/abcinwer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example_package/prog/abcinwer.cpp b/example_package/prog/abcinwer.cpp index c629ec0c..2bfb3a5f 100644 --- a/example_package/prog/abcinwer.cpp +++ b/example_package/prog/abcinwer.cpp @@ -38,13 +38,13 @@ int main() { }; string subtasks_s; for (auto [subtask_id, is_valid] : subtasks) - subtasks_s += is_valid ? to_string(subtask_id) : string("_"); + subtasks_s += is_valid ? to_string(subtask_id) : string("-"); map sample_tests = { {"0a", is_0a()}, {"1ocen", is_1ocen()}, }; - string sample_test_s = "_"; + string sample_test_s = "-"; for (auto [name, is_valid] : sample_tests) if (is_valid) sample_test_s = name;