tools.compare(): a <> b => -1/0/1
aoc.printSolution(): better readable test output
This commit is contained in:
parent
91e2477328
commit
70dd7657ec
4
aoc.py
4
aoc.py
@ -133,8 +133,8 @@ def printSolution(day, part, solution, test=None, test_case=0, exec_time=None):
|
|||||||
|
|
||||||
if test is not None:
|
if test is not None:
|
||||||
print(
|
print(
|
||||||
"(TEST day%d/part%d/case%d) -- got '%s' -- expected '%s' -> %s"
|
"%s (TEST day%d/part%d/case%d) -- got '%s' -- expected '%s'"
|
||||||
% (day, part, test_case, solution, test, "correct" if test == solution else "WRONG")
|
% ("OK" if test == solution else "FAIL", day, part, test_case, solution, test)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
print("Solution to day %s, part %s: %s%s" % (day, part, solution, time_output))
|
print("Solution to day %s, part %s: %s%s" % (day, part, solution, time_output))
|
||||||
|
|||||||
11
tools.py
11
tools.py
@ -4,6 +4,7 @@ import sys
|
|||||||
|
|
||||||
|
|
||||||
def get_script_dir(follow_symlinks=True):
|
def get_script_dir(follow_symlinks=True):
|
||||||
|
"""return path of the executed script"""
|
||||||
if getattr(sys, 'frozen', False):
|
if getattr(sys, 'frozen', False):
|
||||||
path = os.path.abspath(sys.executable)
|
path = os.path.abspath(sys.executable)
|
||||||
else:
|
else:
|
||||||
@ -16,3 +17,13 @@ def get_script_dir(follow_symlinks=True):
|
|||||||
path = os.path.realpath(path)
|
path = os.path.realpath(path)
|
||||||
|
|
||||||
return os.path.dirname(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
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user