~loges/aoc-python-utils

d3a033d56b4ba5a4d8013335133fa938a9ad21a9 — Logan Connolly 7 months ago 6f174de
feat: do not raise assertion on wrong answer
1 files changed, 6 insertions(+), 4 deletions(-)

M aoc/_utils.py
M aoc/_utils.py => aoc/_utils.py +6 -4
@@ 4,15 4,17 @@ from pathlib import Path
from ._typing import IntLines, StrLines


def expect(value):
def expect(want):
    """Validate the result of the solution."""

    def inner(solver):
        @functools.wraps(solver)
        def wrapper(*args, **kwargs):
            result = solver(*args, **kwargs)
            assert result == value, f"expected: {value}, got: {result}"
            print(f"{solver.__name__}: {result}")
            got = solver(*args, **kwargs)
            emoji = "✅" if got == want else "❌"
            message = f"{emoji} {solver.__name__}: {got} (wanted {want})"

            print(message)

        return wrapper