Skip to content

Commit

Permalink
day4: coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-ong committed Dec 26, 2023
1 parent b7b7681 commit 6d8e781
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
15 changes: 11 additions & 4 deletions day04/day4.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,21 @@ def grab_data(filename: str) -> list[Card]:
return result


def part1(cards: list[Card]) -> int:
return sum(card.get_points() for card in cards)


def part2(cards: list[Card]) -> int:
inventory: Inventory = Inventory(cards)
return inventory.total_cards()


def main() -> None:
cards: list[Card] = grab_data(INPUT)
# Q1
total_points = sum(card.get_points() for card in cards)
print(total_points)
print(part1(cards))
# Q2
inventory = Inventory(cards)
print(inventory.total_cards())
print(part2(cards))


if __name__ == "__main__":
Expand Down
24 changes: 23 additions & 1 deletion day04/tests/test_day4.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
from day04.day4 import INPUT_SMALL, Card, Inventory, grab_data, split_numbers
from day04.day4 import (
INPUT_SMALL,
Card,
Inventory,
grab_data,
part1,
part2,
split_numbers,
)


def test_split_numbers() -> None:
Expand All @@ -18,8 +26,22 @@ def test_card() -> None:
assert card.get_points() == 8
assert card.get_matches() == 4

card = Card("Card 1: 41 48 83 86 17 | 1 2 3 4 5 6 7 8\n")
assert card.get_points() == 0
assert card.get_matches() == 0


def test_inventory() -> None:
cards: list[Card] = grab_data(INPUT_SMALL)
inventory: Inventory = Inventory(cards)
assert inventory.total_cards() == 30


def test_part1() -> None:
cards: list[Card] = grab_data(INPUT_SMALL)
assert part1(cards) == 13


def test_part2() -> None:
cards: list[Card] = grab_data(INPUT_SMALL)
assert part2(cards) == 30

0 comments on commit 6d8e781

Please sign in to comment.