Пример #1
0
def main():
    """Run Mr Robot, run!

    Simulate a robot interactively."""
    robot = Robot()

    for line in fileinput.input():
        try:

            (cmd, coords) = parse(line)
            if cmd == 'PLACE':
                robot.place(coords)
            else:
                # Assume Robot has a method for each valid command.
                # (A potential weak point, but this is covered sufficiently by
                # the command_pattern testing)
                getattr(robot, cmd.lower())()

        except InvalidCommand:
            # Silently ignore invalid commands
            pass
Пример #2
0
 def test_bad_y_value(self):
     with pytest.raises(InvalidCommand):
         (cmd, args) = parse('PLACE 0,b,NORTH\n')
Пример #3
0
 def test_valid_place_cmd(self):
     (cmd, args) = parse('PLACE 1,2,NORTH\n')
     assert cmd == 'PLACE'
     assert args['x'] == 1
     assert args['y'] == 2
     assert args['f'] == 'NORTH'
Пример #4
0
 def test_missing_coordinates(self):
     with pytest.raises(InvalidCommand):
         (cmd, args) = parse('PLACE\n')
Пример #5
0
 def test_bad_facing_value(self):
     with pytest.raises(InvalidCommand):
         (cmd, args) = parse('PLACE 0,0,DOWN\n')
Пример #6
0
 def test_invalid_cmd(self):
     with pytest.raises(InvalidCommand):
         (cmd, args) = parse('BAD ROBOT\n')
Пример #7
0
 def test_valid_report_cmd(self):
     (cmd, args) = parse('REPORT\n')
     assert cmd == 'REPORT'
     assert args is None
Пример #8
0
 def test_valid_right_cmd(self):
     (cmd, args) = parse('RIGHT\n')
     assert cmd == 'RIGHT'
     assert args is None
Пример #9
0
 def test_valid_left_cmd(self):
     (cmd, args) = parse('LEFT\n')
     assert cmd == 'LEFT'
     assert args is None
Пример #10
0
 def test_valid_move_cmd(self):
     (cmd, args) = parse('MOVE\n')
     assert cmd == 'MOVE'
     assert args is None