Python: Day 3
This commit is contained in:
57
03/py/test.py
Normal file
57
03/py/test.py
Normal file
@@ -0,0 +1,57 @@
|
||||
from typing import ContextManager, Optional
|
||||
from solution import part1, part2, priority, threes
|
||||
|
||||
from contextlib import nullcontext as no_raise
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@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_threes(
|
||||
line: str,
|
||||
expected: Optional[list[tuple[str, str, str]]],
|
||||
raises: ContextManager,
|
||||
):
|
||||
with raises:
|
||||
actual = list(threes(line.splitlines()))
|
||||
if expected:
|
||||
assert actual == expected
|
||||
|
||||
|
||||
def test_part2(example_data: str) -> None:
|
||||
assert part2(example_data) == 70
|
||||
Reference in New Issue
Block a user