Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MasloMaslane committed Sep 24, 2023
1 parent 4db4156 commit 93aca82
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/sinol_make/commands/run/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ def run_solutions(self, compiled_commands, names, solutions):
for test in self.tests:
all_results[name][self.get_group(test)][test] = ExecutionResult(Status.CE)
print()
executions.sort(key = lambda x: (package_util.get_executable_key(x[1]), x[2]))
executions.sort(key = lambda x: (package_util.get_executable_key(x[1], self.ID), x[2]))
program_groups_scores = collections.defaultdict(dict)
print_data = PrintData(0)

Expand Down
2 changes: 1 addition & 1 deletion src/sinol_make/contest_types/icpc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import List, Dict

from sinol_make.commands.run.structs import ExecutionResult
from sinol_make.structs.status_structs import ExecutionResult
from sinol_make.contest_types import DefaultContest
from sinol_make.structs.status_structs import Status

Expand Down
25 changes: 16 additions & 9 deletions src/sinol_make/helpers/package_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,26 @@ def get_solutions_re(task_id: str) -> re.Pattern:
return re.compile(r"^%s[bs]?[0-9]*\.(cpp|cc|java|py|pas)$" % task_id)


def get_executable_key(executable):
def get_executable_key(executable, task_id):
name = get_file_name(executable)
task_id_len = len(task_id)
value = [0, 0]
if name[3] == 's':
if name[task_id_len] == 's':
value[0] = 1
suffix = name.split(".")[0][4:]
elif name[3] == 'b':
suffix = name.split(".")[0][(task_id_len + 1):]
elif name[task_id_len] == 'b':
value[0] = 2
suffix = name.split(".")[0][4:]
suffix = name.split(".")[0][(task_id_len + 1):]
else:
suffix = name.split(".")[0][3:]
suffix = name.split(".")[0][task_id_len:]
if suffix != "":
value[1] = int(suffix)
i = 0
digits = ""
while i < len(suffix) and suffix[i].isdigit():
digits += suffix[i]
i += 1
if digits != "":
value[1] = int(digits)
return tuple(value)


Expand Down Expand Up @@ -127,7 +134,7 @@ def get_solutions(task_id: str, args_solutions: Union[List[str], None] = None) -
if args_solutions is None:
solutions = [solution for solution in os.listdir("prog/")
if solutions_re.match(solution)]
return sorted(solutions, key=get_executable_key)
return sorted(solutions, key=lambda solution: get_executable_key(solution, task_id))
else:
solutions = []
for solution in get_files_matching(args_solutions, "prog"):
Expand All @@ -136,7 +143,7 @@ def get_solutions(task_id: str, args_solutions: Union[List[str], None] = None) -
if solutions_re.match(os.path.basename(solution)) is not None:
solutions.append(os.path.basename(solution))

return sorted(solutions, key=get_executable_key)
return sorted(solutions, key=lambda solution: get_executable_key(solution, task_id))


def get_file_name(file_path):
Expand Down
9 changes: 8 additions & 1 deletion tests/helpers/test_package_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,14 @@ def test_validate_files(create_package, capsys):

def test_get_executable_key():
os.chdir(get_simple_package_path())
assert package_util.get_executable_key("abc1.cpp.e") == (0, 1)
for task_id in ["abc", "long_task_id", "", "x"]:
assert package_util.get_executable_key(f"{task_id}1.cpp.e", task_id) == (0, 1)
assert package_util.get_executable_key(f"{task_id}2.cpp.e", task_id) == (0, 2)
assert package_util.get_executable_key(f"{task_id}s20.cpp.e", task_id) == (1, 20)
assert package_util.get_executable_key(f"{task_id}s21.cpp.e", task_id) == (1, 21)
assert package_util.get_executable_key(f"{task_id}b100.cpp.e", task_id) == (2, 100)
assert package_util.get_executable_key(f"{task_id}b101.cpp.e", task_id) == (2, 101)
assert package_util.get_executable_key(f"{task_id}x1000.cpp.e", task_id) == (0, 0)


def test_get_solutions():
Expand Down

0 comments on commit 93aca82

Please sign in to comment.