Yes, I do "".join(). Python is not always beautiful. I began reusing part 1 for part 2, until I realised you cannot reuse the Counter.most_common, and you need the actual values to be able to se equal occourences. I probably lost 5-15 minutes just to dribble with 3 levels of nested objects. In GMT+1 before coffee, that cost me. Part 2 was way uglier before some well motivated refactoring. Since all tests and expected output were in place, refactoring was easy.
41 lines
740 B
Python
41 lines
740 B
Python
import unittest
|
|
|
|
from solutions.day_03 import Solution
|
|
|
|
|
|
class Day03TestCase(unittest.TestCase):
|
|
def setUp(self):
|
|
self.solution = Solution()
|
|
self.puzzle_input = self.solution.parse_input(
|
|
"""
|
|
00100
|
|
11110
|
|
10110
|
|
10111
|
|
10101
|
|
01111
|
|
00111
|
|
11100
|
|
10000
|
|
11001
|
|
00010
|
|
01010
|
|
"""
|
|
)
|
|
|
|
def test_parse_puzzle_input(self):
|
|
data = """
|
|
00100
|
|
11110
|
|
"""
|
|
assert self.solution.parse_input(data) == ["00100", "11110"]
|
|
|
|
def test_solve_first_part(self):
|
|
assert self.solution.solve(self.puzzle_input) == 198
|
|
|
|
def test_solve_second_part(self):
|
|
assert self.solution.solve_again(self.puzzle_input) == 230
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|