Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inwer improvements #134

Merged
merged 3 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions example_package/prog/abcinwer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, bool> sample_tests = {
{"0a", is_0a()},
{"1ocen", is_1ocen()},
};
string sample_test_s = "-";
string sample_test_s = "_";
MasloMaslane marked this conversation as resolved.
Show resolved Hide resolved
for (auto [name, is_valid] : sample_tests)
if (is_valid)
sample_test_s = name;
Expand Down
2 changes: 1 addition & 1 deletion src/sinol_make/commands/inwer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
14 changes: 10 additions & 4 deletions src/sinol_make/commands/inwer/inwer_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 = " "
Expand All @@ -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='')
Expand Down
3 changes: 3 additions & 0 deletions src/sinol_make/structs/inwer_structs.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class TableData:
# Number of executions finished
i: int

# Task id
task_id: str

@dataclass
class InwerExecution:
test_path: str
Expand Down
11 changes: 11 additions & 0 deletions tests/commands/inwer/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Loading