chore: Code linting

This commit is contained in:
Adrian Rumpold
2022-12-16 12:45:40 +01:00
parent 8f92555ad5
commit 6dabc43b6a
3 changed files with 4 additions and 6 deletions

57
03/py/test_day03.py Normal file
View File

@@ -0,0 +1,57 @@
from contextlib import nullcontext as no_raise
from typing import ContextManager, Optional
import pytest
from solution import chunks, part1, part2, priority
@pytest.fixture
def example_data() -> str:
return """vJrwpWtwJgWrhcsFMMfFFhFp
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
PmmdzqPrVvPwwTWBwg
wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
ttgJtRGJQctTZtZT
CrZsJsPPZsGzwwsLwLmpwMDw"""
def test_part1(example_data: str) -> None:
assert part1(example_data) == 157
@pytest.mark.parametrize(
"s,expected",
[
("a", 1),
("b", 2),
("z", 26),
("A", 27),
("C", 29),
("Z", 52),
],
)
def test_priority(s: str, expected: int) -> None:
assert priority(s) == expected
@pytest.mark.parametrize(
"line,expected,raises",
[
("a\nb\nc", [["a", "b", "c"]], no_raise()),
("a\nb\nc\nd", None, pytest.raises(ValueError)),
],
)
def test_chunks(
line: str,
expected: Optional[list[tuple[str, str, str]]],
raises: ContextManager,
):
with raises:
actual = list(chunks(line.splitlines(), 3))
if expected:
assert actual == expected
def test_part2(example_data: str) -> None:
assert part2(example_data) == 70