Skip to content

Commit 0a4a394

Browse files
authored
Clean up tests
Signed-off-by: Bradley Reynolds <[email protected]>
1 parent 1205871 commit 0a4a394

File tree

5 files changed

+129
-8
lines changed

5 files changed

+129
-8
lines changed

events/advent_of_code/2022/03/python/aoc_2022_03.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
from collections import Counter
2+
from itertools import batched
23
from pathlib import Path
34
from string import ascii_lowercase, ascii_uppercase
5+
from typing import TYPE_CHECKING
6+
7+
if TYPE_CHECKING:
8+
from collections.abc import Iterable
9+
10+
11+
def flatten[T](
12+
iterable: Iterable[Iterable[T]],
13+
) -> Iterable[T]:
14+
return [item for sub_iter in iterable for item in sub_iter]
415

5-
from darbia.utils.iterables import chunks, flatten
616

717
priorities = dict(
818
zip(ascii_lowercase + ascii_uppercase, range(1, 52 + 1), strict=False),
@@ -22,7 +32,7 @@ def part_one(values: list[str]) -> int:
2232

2333
def part_two(values: list[str]) -> int:
2434
total = 0
25-
for group in chunks(values, 3):
35+
for group in batched(values, 3, strict=True):
2636
counter = Counter(flatten([list(set(chunk)) for chunk in group]))
2737
for character, occurrences in counter.items():
2838
if occurrences == 3:

events/advent_of_code/2022/05/python/aoc_2022_05.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import re
22
from dataclasses import dataclass
3+
from itertools import batched
34
from pathlib import Path
45
from typing import TYPE_CHECKING
56

6-
from darbia.utils.iterables import chunks
7-
87
if TYPE_CHECKING:
98
from collections.abc import Iterable
109

@@ -27,7 +26,7 @@ def build_from(cls, text: str) -> Ship:
2726
ship = Ship({index: [] for index in range(1, stack_count + 1)})
2827
for line in lines:
2928
stack = 1
30-
for chunk in chunks(line, 4):
29+
for chunk in batched(line, 4, strict=False):
3130
if chunk[0] == "[":
3231
ship.stacks[stack].append(chunk[1])
3332
stack += 1 # noqa: SIM113

events/advent_of_code/2022/10/python/aoc_2022_10.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1+
from itertools import batched
12
from pathlib import Path
23

3-
from darbia.utils.iterables import chunks
4-
54

65
def run_cycles(text: str) -> dict[int, int]:
76
cycles = {}
@@ -45,7 +44,7 @@ def part_two(text: str) -> str:
4544
cycles = run_cycles(text)
4645
for cycle, x in cycles.items():
4746
pixels.append("#" if x - 1 <= (cycle - 1) % 40 <= x + 1 else " ")
48-
return "\n".join("".join(row) for row in chunks(pixels, 40))
47+
return "\n".join("".join(row) for row in batched(pixels, 40, strict=True))
4948

5049

5150
if __name__ == "__main__":

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ repository = "https://github.com/shenanigansd/scratchpad"
2121

2222
[project.optional-dependencies]
2323
dev = [
24+
"nox",
2425
"prek",
2526
"ruff",
2627
"mypy",

uv.lock

Lines changed: 112 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)