diff --git a/day01/day1a.py b/day01/day1a.py index f912436..9e45b54 100644 --- a/day01/day1a.py +++ b/day01/day1a.py @@ -26,8 +26,7 @@ def get_input(input_file: str) -> list[str]: return list(file) -def main(input_file: str = INPUT) -> int: - lines = get_input(input_file) +def part1(lines: list[str]) -> int: total = 0 for line in lines: first, last = get_first_last(line) @@ -36,5 +35,10 @@ def main(input_file: str = INPUT) -> int: return total +def main() -> None: + lines = get_input(INPUT) + print(part1(lines)) + + if __name__ == "__main__": main() diff --git a/day01/day1b.py b/day01/day1b.py index 078a853..1af9bfa 100644 --- a/day01/day1b.py +++ b/day01/day1b.py @@ -24,7 +24,7 @@ class WordNumber: number: str = "1" -mappings = [ +MAPPINGS: list[WordNumber] = [ WordNumber("one", "1"), WordNumber("two", "2"), WordNumber("three", "3"), @@ -43,7 +43,7 @@ def process_line(line: str) -> int: if char.isnumeric(): index_to_chars[index] = char - for mapping in mappings: + for mapping in MAPPINGS: substring = line[index : index + len(mapping.word)] if substring == mapping.word: index_to_chars[index] = mapping.number @@ -60,12 +60,15 @@ def get_input(input_file: str) -> list[str]: return list(file) -def main(input_file: str = INPUT) -> int: - lines = get_input(input_file) +def part2(lines: list[str]) -> int: total = sum(process_line(line) for line in lines) - print(total) return total +def main() -> None: + lines = get_input(INPUT) + print(part2(lines)) + + if __name__ == "__main__": main() diff --git a/day01/tests/test_day1a.py b/day01/tests/test_day1a.py index 981ac03..27e1428 100644 --- a/day01/tests/test_day1a.py +++ b/day01/tests/test_day1a.py @@ -1,6 +1,6 @@ import pytest -from day01.day1a import INPUT_SMALL, get_first_last, get_input, main +from day01.day1a import INPUT_SMALL, get_first_last, get_input, part1 def test_get_first_last() -> None: @@ -17,8 +17,9 @@ def test_get_first_last() -> None: get_first_last("") -def test_main() -> None: - assert main(INPUT_SMALL) == 142 +def test_part1() -> None: + lines: list[str] = get_input(INPUT_SMALL) + assert part1(lines) == 142 def test_get_input() -> None: diff --git a/day01/tests/test_day1b.py b/day01/tests/test_day1b.py index d7d589a..190d67a 100644 --- a/day01/tests/test_day1b.py +++ b/day01/tests/test_day1b.py @@ -1,4 +1,4 @@ -from day01.day1b import INPUT_SMALL, IndexValue, get_input, main, process_line +from day01.day1b import INPUT_SMALL, IndexValue, get_input, part2, process_line def test_process_line() -> None: @@ -23,5 +23,6 @@ def test_index_value() -> None: assert str(index_val) == ("(i:0, v:1)") -def test_main() -> None: - assert main(INPUT_SMALL) == 281 +def test_part2() -> None: + lines: list[str] = get_input(INPUT_SMALL) + assert part2(lines) == 281 diff --git a/day02/day2.py b/day02/day2.py index 63a5f8c..ac71f83 100644 --- a/day02/day2.py +++ b/day02/day2.py @@ -33,7 +33,7 @@ def parse_colors_count(self, string: str) -> None: self.red = num elif color == Color.GREEN: self.green = num - elif color == Color.BLUE: + else: # color == Color.BLUE: self.blue = num @@ -66,9 +66,6 @@ def __str__(self) -> str: def power_level(self) -> int: return self.red * self.green * self.blue - def __repr__(self) -> str: - return str(self) - def game_filter(game: Game) -> bool: """Returns true if the game satisfies the constraints of Question 1""" diff --git a/day02/tests/test_day2.py b/day02/tests/test_day2.py index fbc69a0..e6725b3 100644 --- a/day02/tests/test_day2.py +++ b/day02/tests/test_day2.py @@ -13,9 +13,11 @@ def test_draw() -> None: """Test draws""" draw1: Draw = Draw("3 blue, 4 red") draw2: Draw = Draw("4 blue, 3 green") + draw3: Draw = Draw("4 blue, 3 green, 1 red") assert [draw1.red, draw1.green, draw1.blue] == [4, 0, 3] assert [draw2.red, draw2.green, draw2.blue] == [0, 3, 4] + assert [draw3.red, draw3.green, draw3.blue] == [1, 3, 4] def test_game() -> None: @@ -33,6 +35,9 @@ def test_game() -> None: assert game2.green == 3 assert game2.blue == 4 + assert str(game1) == "Game 1: 4,2,6" + assert str(game2) == "Game 2: 1,3,4" + def test_part1() -> None: """Tests get_games, game_filter, part1""" diff --git a/pyproject.toml b/pyproject.toml index 4b3aaea..334bc83 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,8 +31,10 @@ command_line = '-m pytest' source = ['.'] relative_files = true + [tool.coverage.report] -exclude_lines = ["if __name__ == .__main__.:"] +exclude_lines = ["if __name__ == .__main__.:", "def main"] +omit = ["download_inputs.py", "maker.py"] precision = 2 skip_covered = true fail_under = 0