From 70dd7657ecab114dde66ef95e3b9818d1620cd9e Mon Sep 17 00:00:00 2001 From: Stefan Harmuth Date: Wed, 1 Dec 2021 02:30:04 +0100 Subject: [PATCH] tools.compare(): a <> b => -1/0/1 aoc.printSolution(): better readable test output --- aoc.py | 4 ++-- tools.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/aoc.py b/aoc.py index 9064738..cf90202 100644 --- a/aoc.py +++ b/aoc.py @@ -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)) diff --git a/tools.py b/tools.py index 8ee2e30..a11be26 100644 --- a/tools.py +++ b/tools.py @@ -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