Python: More elegant solution for day 3
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user