Ejemplo n.º 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
Ejemplo n.º 2
0
 def test_bad_y_value(self):
     with pytest.raises(InvalidCommand):
         (cmd, args) = parse('PLACE 0,b,NORTH\n')
Ejemplo 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'
Ejemplo n.º 4
0
 def test_missing_coordinates(self):
     with pytest.raises(InvalidCommand):
         (cmd, args) = parse('PLACE\n')
Ejemplo n.º 5
0
 def test_bad_facing_value(self):
     with pytest.raises(InvalidCommand):
         (cmd, args) = parse('PLACE 0,0,DOWN\n')
Ejemplo n.º 6
0
 def test_invalid_cmd(self):
     with pytest.raises(InvalidCommand):
         (cmd, args) = parse('BAD ROBOT\n')
Ejemplo n.º 7
0
 def test_valid_report_cmd(self):
     (cmd, args) = parse('REPORT\n')
     assert cmd == 'REPORT'
     assert args is None
Ejemplo n.º 8
0
 def test_valid_right_cmd(self):
     (cmd, args) = parse('RIGHT\n')
     assert cmd == 'RIGHT'
     assert args is None
Ejemplo n.º 9
0
 def test_valid_left_cmd(self):
     (cmd, args) = parse('LEFT\n')
     assert cmd == 'LEFT'
     assert args is None
Ejemplo n.º 10
0
 def test_valid_move_cmd(self):
     (cmd, args) = parse('MOVE\n')
     assert cmd == 'MOVE'
     assert args is None