tools.compare(): a <> b => -1/0/1

aoc.printSolution(): better readable test output
This commit is contained in:
Stefan Harmuth 2021-12-01 02:30:04 +01:00
parent 91e2477328
commit 70dd7657ec
2 changed files with 13 additions and 2 deletions

4
aoc.py
View File

@ -133,8 +133,8 @@ def printSolution(day, part, solution, test=None, test_case=0, exec_time=None):
if test is not None:
print(
"(TEST day%d/part%d/case%d) -- got '%s' -- expected '%s' -> %s"
% (day, part, test_case, solution, test, "correct" if test == solution else "WRONG")
"%s (TEST day%d/part%d/case%d) -- got '%s' -- expected '%s'"
% ("OK" if test == solution else "FAIL", day, part, test_case, solution, test)
)
else:
print("Solution to day %s, part %s: %s%s" % (day, part, solution, time_output))

View File

@ -4,6 +4,7 @@ import sys
def get_script_dir(follow_symlinks=True):
"""return path of the executed script"""
if getattr(sys, 'frozen', False):
path = os.path.abspath(sys.executable)
else:
@ -16,3 +17,13 @@ def get_script_dir(follow_symlinks=True):
path = os.path.realpath(path)
return os.path.dirname(path)
def compare(a: int, b: int) -> int:
"""compare to values, return -1 if a is smaller than b, 1 if a is greater than b, 0 is both are equal"""
if a > b:
return -1
elif b > a:
return 1
else:
return 0