Skip to content

Commit

Permalink
fix: normalization of input, and enhance boj run output
Browse files Browse the repository at this point in the history
  • Loading branch information
xvzc committed Jul 10, 2024
1 parent b427cbd commit 948ce45
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions boj/commands/run/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,7 @@ async def _run_testcase_async(

await asyncio.sleep(uniform(0.2, 0.7))

if process.returncode != 0:
color = "bold magenta"
status = "ERROR"
text = error.rstrip()
elif testcase.compare(output):
if testcase.compare(output):
color = "bold green"
status = "PASSED"
text = output
Expand All @@ -175,6 +171,11 @@ async def _run_testcase_async(
status = "FAILED"
text = output

if process.returncode != 0:
color = "bold magenta"
status = "ERROR"
text += '\n' + error.rstrip()

progress.update(
task_id=task_id,
description=create_case_label(label_width, testcase.label)
Expand Down
8 changes: 4 additions & 4 deletions boj/data/testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

def normalize(s: str):
s = s.rstrip()
normalized_text = "\n".join([line.rstrip() for line in s.splitlines()])
normalized_text = "\n".join([line.rstrip() for line in s.splitlines()]).rstrip()
return normalized_text


Expand All @@ -19,11 +19,11 @@ def __init__(self, label: str, input_: str, output: str):

@property
def input(self):
return self.__input
return normalize(self.__input)

@property
def output(self):
return self.__output
return normalize(self.__output)

@property
def label(self):
Expand All @@ -33,7 +33,7 @@ def __repr__(self):
return "Testcase {" + self.input + ", " + self.output + "}"

def compare(self, stdout: str):
return normalize(self.output) == normalize(stdout)
return self.output == normalize(stdout)

def to_text_files(self, dir_: str) -> (TextFile, TextFile):
input_ = TextFile(
Expand Down

0 comments on commit 948ce45

Please sign in to comment.