Python: More elegant solution for day 3

This commit is contained in:
Adrian Rumpold
2022-12-15 08:09:09 +01:00
parent aeebed7ec9
commit d3dc061564
2 changed files with 11 additions and 9 deletions

View File

@@ -1,5 +1,5 @@
from typing import ContextManager, Optional
from solution import part1, part2, priority, threes
from solution import part1, part2, priority, chunks
from contextlib import nullcontext as no_raise
@@ -38,17 +38,17 @@ def test_priority(s: str, expected: int) -> None:
@pytest.mark.parametrize(
"line,expected,raises",
[
("a\nb\nc", [("a", "b", "c")], no_raise()),
("a\nb\nc", [["a", "b", "c"]], no_raise()),
("a\nb\nc\nd", None, pytest.raises(ValueError)),
],
)
def test_threes(
def test_chunks(
line: str,
expected: Optional[list[tuple[str, str, str]]],
raises: ContextManager,
):
with raises:
actual = list(threes(line.splitlines()))
actual = list(chunks(line.splitlines(), 3))
if expected:
assert actual == expected