def test_generate_robot(self): grid = Grid(3, 3) grid.generate_robot(0, 0, 'N') assert len(grid.robots) > 0 assert grid.robots[0].pos() == (0, 0, 'N')
def test_should_not_generate_robot_at_invalid_coordinate(self): grid = Grid(3, 3) with pytest.raises(CustomExceptions.CoordinateDoesntExistError) as exc: grid.generate_robot(4, 1, 'E') assert str(exc.value) == str((4, 1, 'E'))
def test_should_not_generate_robot_at_same_coordinate(self): grid = Grid(3, 3) grid.generate_robot(1, 1, 'E') with pytest.raises(CustomExceptions.LaunchRobotCrashError) as exc: grid.generate_robot(1, 1, 'E') assert str(exc.value) == str((1, 1, 'E'))
def test_last_positions(self, robots, expected): grid = Grid(5, 5) for robot in robots: grid.generate_robot(*robot) final = grid.last_positions() assert len(final) == len(expected) assert final == expected
def test_apply_robot_instructions( self, robot_position, instructions, final, ): grid = Grid(5, 5) grid.generate_robot(*robot_position) grid.apply_robot_instructions(instructions) assert grid.robots[0].pos() == final
def main(): print('*** Welcome to the Mars Robots Guide! ***\n') print('Here are the computed outputs:\n') with open('robots_guide.in.md') as f: lines = f.readlines() grid_size = lines[0] if not grid_size: return grid_size = grid_size.split(' ') max_x_axis = int(grid_size[0]) max_y_axis = int(grid_size[1]) if max_x_axis > 50 or max_y_axis > 50: raise CustomExceptions.InvalidGridRangeError(max_x_axis, max_y_axis) grid = Grid( x=max_x_axis, y=max_y_axis, ) updated_lines = lines.pop(0) # upper-right coordinates of the rectangular world robots_seed_positions = lines[::2] # Robots initial position robots_instructions = lines[1::2] # Robots instructions for position, instruction in zip(robots_seed_positions, robots_instructions): robot_initial_pos = position.strip('\n') if not robot_initial_pos: break robot_instruction = instruction robot_initial_pos = robot_initial_pos.split(' ') grid.generate_robot( x=int(robot_initial_pos[0]), y=int(robot_initial_pos[1]), orientation=robot_initial_pos[2], ) grid.apply_robot_instructions(robot_instruction) f.close()