def test_moves_from_hallway(self): diagram = AoC2021_23._parse(("#############", "#B..A.C...DC#", "###.#.#.#.###", " #A#B#D#.#", " #########")) self.assertEqual( diagram.moves_from_hallway(), {("room_a", 3, 1), ("room_d", 9, 0)})
def test_energy_for_move_from_hallway(self): diagram = AoC2021_23._parse(("#############", "#B..A.C...DC#", "###.#.#.#.###", " #A#B#D#.#", " #########")) self.assertEqual( diagram.energy_for_move_from_hallway(("room_a", 3, 1)), 2) self.assertEqual( diagram.energy_for_move_from_hallway(("room_d", 9, 0)), 3_000)
def test_moves_to_hallway(self): diagram = AoC2021_23._parse(("#############", "#.....D.....#", "###C#B#.#C###", " #A#B#D#A#", " #########")) self.assertEqual( diagram.moves_to_hallway(), {("room_a", 1, 0), ("room_a", 1, 1), ("room_a", 1, 3), ("room_c", 0, 7), ("room_c", 0, 9), ("room_c", 0, 10), ("room_d", 1, 7), ("room_d", 1, 9), ("room_d", 1, 10), })
def test_all_empty(self): diagram = AoC2021_23._parse(("#############", "#...C.D.....#", "###.#B#.#A###", " #A#B#D#C#", " #########")) self.assertTrue(diagram.all_empty(3, "room_a")) self.assertTrue(diagram.all_empty(3, "room_b")) self.assertTrue(diagram.all_empty(5, "room_b")) self.assertTrue(diagram.all_empty(5, "room_c")) self.assertTrue(diagram.all_empty(5, "room_d")) self.assertFalse(diagram.all_empty(5, "room_a")) self.assertFalse(diagram.all_empty(3, "room_c")) self.assertFalse(diagram.all_empty(3, "room_d"))
def test_do_move_to_hallway(self): diagram = AoC2021_23._parse(("#############", "#.....D.....#", "###C#B#.#C###", " #A#B#D#A#", " #########")) temp = diagram.do_move_to_hallway(("room_a", 1, 0)) ans = temp.do_move_to_hallway(("room_d", 1, 7)) self.assertEqual( diagram.hallway.amphipods, ['.', '.', '.', '.', '.', 'D', '.', '.', '.', '.', '.']) self.assertEqual( ans.hallway.amphipods, ['C', '.', '.', '.', '.', 'D', '.', 'C', '.', '.', '.']) self.assertEqual(diagram.room_a.amphipods, ['A', 'C']) self.assertEqual(ans.room_a.amphipods, ['A', '.']) self.assertEqual(diagram.room_b.amphipods, ['B', 'B']) self.assertEqual(ans.room_b.amphipods, ['B', 'B']) self.assertEqual(diagram.room_c.amphipods, ['D', '.']) self.assertEqual(ans.room_c.amphipods, ['D', '.']) self.assertEqual(diagram.room_d.amphipods, ['A', 'C']) self.assertEqual(ans.room_d.amphipods, ['A', '.'])
def test_do_move_from_hallway(self): diagram = AoC2021_23._parse(("#############", "#B..A.C...DC#", "###.#.#.#.###", " #A#B#D#.#", " #########")) temp = diagram.do_move_from_hallway(("room_a", 3, 1)) ans = temp.do_move_from_hallway(("room_d", 9, 0)) self.assertEqual( diagram.hallway.amphipods, ['B', '.', '.', 'A', '.', 'C', '.', '.', '.', 'D', 'C']) self.assertEqual( ans.hallway.amphipods, ['B', '.', '.', '.', '.', 'C', '.', '.', '.', '.', 'C']) self.assertEqual(diagram.room_a.amphipods, ['A', '.']) self.assertEqual(ans.room_a.amphipods, ['A', 'A']) self.assertEqual(diagram.room_b.amphipods, ['B', '.']) self.assertEqual(ans.room_b.amphipods, ['B', '.']) self.assertEqual(diagram.room_c.amphipods, ['D', '.']) self.assertEqual(ans.room_c.amphipods, ['D', '.']) self.assertEqual(diagram.room_d.amphipods, ['.', '.']) self.assertEqual(ans.room_d.amphipods, ['D', '.'])
def test(self): diagram = AoC2021_23._parse(("#############", "#...........#", "###B#C#B#D###", " #D#C#B#A#", " #D#B#A#C#", " #A#D#C#A#", " #########")) diagram.assert_valid() self.assertEqual(diagram.hallway.destination_for, '.') self.assertEqual(diagram.room_a.destination_for, 'A') self.assertEqual(diagram.room_b.destination_for, 'B') self.assertEqual(diagram.room_c.destination_for, 'C') self.assertEqual(diagram.room_d.destination_for, 'D') self.assertEqual(diagram.hallway.capacity, 11) self.assertEqual(diagram.room_a.capacity, 4) self.assertEqual(diagram.room_b.capacity, 4) self.assertEqual(diagram.room_c.capacity, 4) self.assertEqual(diagram.room_d.capacity, 4) self.assertEqual(diagram.hallway.amphipods, ['.'] * 11) self.assertEqual(diagram.room_a.amphipods, ['A', 'D', 'D', 'B']) self.assertEqual(diagram.room_b.amphipods, ['D', 'B', 'C', 'C']) self.assertEqual(diagram.room_c.amphipods, ['C', 'A', 'B', 'B']) self.assertEqual(diagram.room_d.amphipods, ['A', 'C', 'A', 'D'])
def test_energy_for_move(self): diagram = AoC2021_23._parse(("#############", "#.....D.....#", "###C#B#.#A###", " #A#B#D#C#", " #########")) self.assertEqual(diagram.energy_for_move_to_hallway(("room_a", 1, 0)), 300) self.assertEqual(diagram.energy_for_move_to_hallway(("room_a", 1, 1)), 200) self.assertEqual(diagram.energy_for_move_to_hallway(("room_a", 1, 3)), 200) self.assertEqual(diagram.energy_for_move_to_hallway(("room_c", 0, 7)), 3_000) self.assertEqual(diagram.energy_for_move_to_hallway(("room_c", 0, 9)), 5_000) self.assertEqual(diagram.energy_for_move_to_hallway(("room_c", 0, 10)), 6_000) self.assertEqual(diagram.energy_for_move_to_hallway(("room_d", 1, 7)), 2) self.assertEqual(diagram.energy_for_move_to_hallway(("room_d", 1, 9)), 2) self.assertEqual(diagram.energy_for_move_to_hallway(("room_d", 1, 10)), 3)