def test_avoid_obstacles(self): console_input = iter( ["5 5 1", ".....", ".....", ".....", ".xxxx", "....."]) mock.builtins.input = lambda: next(console_input) gm = build_map() gm.player_pos = (0, 0) # Force player pos nav = Navigator(gm) route = nav.plan_route_to((4, 4)) print(route) self.assertListEqual(route, ['S', 'S', 'S', 'S', 'E', 'E', 'E', 'E'])
def test_spiral_outwards(self): console_input = iter( ["5 5 1", ".....", "xxxx.", "...x.", ".xxx.", "....."]) mock.builtins.input = lambda: next(console_input) gm = build_map() gm.player_pos = (2, 2) # Force player pos nav = Navigator(gm) route = nav.plan_route_to((0, 0)) print(route) self.assertEqual(len(route), 16)
def test_impossible_route(self): console_input = iter( ["5 5 1", ".x...", ".x...", ".x...", ".x...", ".x..."]) mock.builtins.input = lambda: next(console_input) gm = build_map() gm.player_pos = (0, 0) # Force player pos nav = Navigator(gm) route = nav.plan_route_to((4, 4)) print(route) self.assertIsNone(route)