def test_example_six(self): example_input = """ ######### #G......# #.E.#...# #..##..G# #...##..# #...#...# #.G...G.# #.....G.# ######### """ s = Solver(from_str=example_input) one, units, grid_str = s.solve_part_one() self.assertEqual(one, 18740) round_str = """ ######### #.G.....# #G.G#...# #.G##...# #...##..# #.G.#...# #.......# #.......# ######### """.strip().replace(" ", "") self.assertEqual(Solver.unit_by_loc((2, 1), units)["HP"], 137) self.assertEqual(Solver.unit_by_loc((1, 2), units)["HP"], 200) self.assertEqual(Solver.unit_by_loc((3, 2), units)["HP"], 200) self.assertEqual(Solver.unit_by_loc((2, 3), units)["HP"], 200) self.assertEqual(Solver.unit_by_loc((2, 5), units)["HP"], 200) self.assertEqual(grid_str, round_str) two, units, grid_str = s.solve_part_two() self.assertEqual(two, 1140) round_str = """ ######### #.......# #.E.#...# #..##...# #...##..# #...#...# #.......# #.......# ######### """.strip().replace(" ", "") self.assertEqual(grid_str, round_str) self.assertEqual(Solver.unit_by_loc((2, 2), units)["HP"], 38)
def test_example_three(self): example_input = """ ####### #E..EG# #.#G.E# #E.##E# #G..#.# #..E#.# ####### """ s = Solver(from_str=example_input) one, units, grid_str = s.solve_part_one() self.assertEqual(one, 39514) round_str = """ ####### #.E.E.# #.#E..# #E.##.# #.E.#.# #...#.# ####### """.strip().replace(" ", "") self.assertEqual(grid_str, round_str) self.assertEqual(Solver.unit_by_loc((2, 1), units)["HP"], 164) self.assertEqual(Solver.unit_by_loc((4, 1), units)["HP"], 197) self.assertEqual(Solver.unit_by_loc((3, 2), units)["HP"], 200) self.assertEqual(Solver.unit_by_loc((1, 3), units)["HP"], 98) self.assertEqual(Solver.unit_by_loc((2, 4), units)["HP"], 200) two, units, grid_str = s.solve_part_two() self.assertEqual(two, 31284) round_str = """ ####### #.E.E.# #.#E..# #E.##E# #.E.#.# #...#.# ####### """.strip().replace(" ", "") self.assertEqual(grid_str, round_str) self.assertEqual(Solver.unit_by_loc((2, 1), units)["HP"], 200) self.assertEqual(Solver.unit_by_loc((4, 1), units)["HP"], 23) self.assertEqual(Solver.unit_by_loc((3, 2), units)["HP"], 200) self.assertEqual(Solver.unit_by_loc((1, 3), units)["HP"], 125) self.assertEqual(Solver.unit_by_loc((5, 3), units)["HP"], 200) self.assertEqual(Solver.unit_by_loc((2, 4), units)["HP"], 200)
def test_example_four(self): example_input = """ ####### #E.G#.# #.#G..# #G.#.G# #G..#.# #...E.# ####### """ s = Solver(from_str=example_input) one, units, grid_str = s.solve_part_one() self.assertEqual(one, 27755) round_str = """ ####### #G.G#.# #.#G..# #..#..# #...#G# #...G.# ####### """.strip().replace(" ", "") self.assertEqual(grid_str, round_str) self.assertEqual(Solver.unit_by_loc((1, 1), units)["HP"], 200) self.assertEqual(Solver.unit_by_loc((3, 1), units)["HP"], 98) self.assertEqual(Solver.unit_by_loc((3, 2), units)["HP"], 200) self.assertEqual(Solver.unit_by_loc((5, 4), units)["HP"], 95) self.assertEqual(Solver.unit_by_loc((4, 5), units)["HP"], 200) two, units, grid_str = s.solve_part_two() self.assertEqual(two, 3478) round_str = """ ####### #.E.#.# #.#E..# #..#..# #...#.# #.....# ####### """.strip().replace(" ", "") self.assertEqual(grid_str, round_str) self.assertEqual(Solver.unit_by_loc((2, 1), units)["HP"], 8) self.assertEqual(Solver.unit_by_loc((3, 2), units)["HP"], 86)
def test_example_five(self): example_input = """ ####### #.E...# #.#..G# #.###.# #E#G#G# #...#G# ####### """ s = Solver(from_str=example_input) one, units, grid_str = s.solve_part_one() self.assertEqual(one, 28944) round_str = """ ####### #.....# #.#G..# #.###.# #.#.#.# #G.G#G# ####### """.strip().replace(" ", "") self.assertEqual(grid_str, round_str) self.assertEqual(Solver.unit_by_loc((3, 2), units)["HP"], 200) self.assertEqual(Solver.unit_by_loc((1, 5), units)["HP"], 98) self.assertEqual(Solver.unit_by_loc((3, 5), units)["HP"], 38) self.assertEqual(Solver.unit_by_loc((5, 5), units)["HP"], 200) two, units, grid_str = s.solve_part_two() self.assertEqual(two, 6474) round_str = """ ####### #...E.# #.#..E# #.###.# #.#.#.# #...#.# ####### """.strip().replace(" ", "") self.assertEqual(grid_str, round_str) self.assertEqual(Solver.unit_by_loc((4, 1), units)["HP"], 14) self.assertEqual(Solver.unit_by_loc((5, 2), units)["HP"], 152)
def test_example_one(self): example_input = """ ####### #.G...# #...EG# #.#.#G# #..G#E# #.....# ####### """ s = Solver(from_str=example_input) one, units, grid_str = s.solve_part_one() self.assertEqual(one, 27730) round_str = """ ####### #G....# #.G...# #.#.#G# #...#.# #....G# ####### """.strip().replace(" ", "") self.assertEqual(grid_str, round_str) self.assertEqual(Solver.unit_by_loc((1, 1), units)["HP"], 200) self.assertEqual(Solver.unit_by_loc((2, 2), units)["HP"], 131) self.assertEqual(Solver.unit_by_loc((5, 3), units)["HP"], 59) self.assertEqual(Solver.unit_by_loc((5, 5), units)["HP"], 200) two, units, grid_str = s.solve_part_two() round_str = """ ####### #..E..# #...E.# #.#.#.# #...#.# #.....# ####### """.strip().replace(" ", "") self.assertEqual(grid_str, round_str) self.assertEqual(Solver.unit_by_loc((3, 1), units)["HP"], 158) self.assertEqual(Solver.unit_by_loc((4, 2), units)["HP"], 14) self.assertEqual(two, 4988)
def test_solution(self): s = Solver(from_file="input/december15.input") one, units, grid_str = s.solve_part_one() self.assertEqual(one, 246176) two, units, grid_str = s.solve_part_two() self.assertEqual(two, 58128)