From b7b76812ea73bbeae6d47c3a2e1b3c69ccd0d881 Mon Sep 17 00:00:00 2001 From: alexo Date: Wed, 27 Dec 2023 02:34:01 +1100 Subject: [PATCH] day3: coverage --- day03/lib/classes.py | 2 -- day03/tests/test_classes.py | 10 ++++++++++ pyproject.toml | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/day03/lib/classes.py b/day03/lib/classes.py index d2341fb..9e27b35 100644 --- a/day03/lib/classes.py +++ b/day03/lib/classes.py @@ -120,8 +120,6 @@ def find_gear_parts( self, gear: Gear, part_numbers: list[PartNumber] ) -> list[PartNumber]: """Returns a list of part_numbers that are touching a given gear""" - if gear.part_numbers is not None: - return gear.part_numbers result = [] for part_number in part_numbers: if part_number.touching(gear.col, gear.row, self.row_size): diff --git a/day03/tests/test_classes.py b/day03/tests/test_classes.py index 60ad3d0..01eb0a8 100644 --- a/day03/tests/test_classes.py +++ b/day03/tests/test_classes.py @@ -1,5 +1,7 @@ from dataclasses import dataclass +import pytest + from day03.day3 import INPUT_SMALL from day03.lib.classes import Gear, Matrix, PartNumber from day03.lib.parsers import get_matrix @@ -53,6 +55,9 @@ def test_matrix() -> None: assert len(gears) == 3 + matrix2: Matrix = Matrix(["*755."]) + assert matrix2.is_engine_part(PartNumber(1, 0, 3, 755)) + def test_gear() -> None: # 69... @@ -69,3 +74,8 @@ def test_gear() -> None: assert gear1.gear_ratio == 0 assert gear2.gear_ratio == 69 * 78 assert gear3.gear_ratio == 0 + + gear_not_init = Gear(1, 1) + + with pytest.raises(ValueError): + gear_not_init.gear_ratio diff --git a/pyproject.toml b/pyproject.toml index 334bc83..b6c7654 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,7 +33,7 @@ relative_files = true [tool.coverage.report] -exclude_lines = ["if __name__ == .__main__.:", "def main"] +exclude_lines = ["if __name__ == .__main__.:", "def main", "if TYPE_CHECKING:"] omit = ["download_inputs.py", "maker.py"] precision = 2 skip_covered = true