Exemple #1
0
 def test_report(self):
     command = "PLACE"
     command_args = ["4", "4", "NORTH"]
     commands.execute(command, command_args)
     command = "REPORT"
     command_args = None
     commands.execute(command, command_args)
Exemple #2
0
 def test_place(self):
     command = "PLACE"
     command_args = ["0", "1", "NORTH"]
     commands.execute(command, command_args)
     self.assertEqual(0, self.robot.x)
     self.assertEqual(1, self.robot.y)
     self.assertEqual("NORTH", self.robot.f)
Exemple #3
0
 def test_place_invalid_direction(self):
     command = "PLACE"
     command_args = ["2", "3", "WEST"]
     commands.execute(command, command_args)
     command = "PLACE"
     command_args = ["0", "0", "UP"]
     commands.execute(command, command_args)
     self.assertEqual("WEST", self.robot.f)
Exemple #4
0
 def test_place_invalid_position(self):
     command = "PLACE"
     command_args = ["0", "1", "NORTH"]
     commands.execute(command, command_args)
     command = "PLACE"
     command_args = ["0", "A", "NORTH"]
     commands.execute(command, command_args)
     self.assertEqual(1, self.robot.y)
Exemple #5
0
 def test_right(self):
     command = "PLACE"
     command_args = ["2", "3", "EAST"]
     commands.execute(command, command_args)
     command = "RIGHT"
     command_args = None
     commands.execute(command, command_args)
     self.assertEqual(2, self.robot.x)
     self.assertEqual(3, self.robot.y)
     self.assertEqual("SOUTH", self.robot.f)
Exemple #6
0
 def test_left(self):
     command = "PLACE"
     command_args = ["4", "1", "NORTH"]
     commands.execute(command, command_args)
     command = "LEFT"
     command_args = None
     commands.execute(command, command_args)
     self.assertEqual(4, self.robot.x)
     self.assertEqual(1, self.robot.y)
     self.assertEqual("WEST", self.robot.f)
Exemple #7
0
 def test_move(self):
     command = "PLACE"
     command_args = ["1", "2", "NORTH"]
     commands.execute(command, command_args)
     command = "MOVE"
     command_args = None
     commands.execute(command, command_args)
     self.assertEqual(1, self.robot.x)
     self.assertEqual(3, self.robot.y)
     self.assertEqual("NORTH", self.robot.f)
Exemple #8
0
 def test_place_missing_params(self):
     command = "PLACE"
     command_args = ["4", "1", "SOUTH"]
     commands.execute(command, command_args)
     command = "PLACE"
     command_args = None
     commands.execute(command, command_args)
     self.assertEqual(4, self.robot.x)
     self.assertEqual(1, self.robot.y)
     self.assertEqual("SOUTH", self.robot.f)
Exemple #9
0
def start_simulation():
    ''' Start simulator and wait for the next command

    '''

    signal.signal(signal.SIGTERM, _shutting_down)
    signal.signal(signal.SIGINT, _shutting_down)
    print('''
#######################################################################
####### ####### #     #         ######  ####### ######  ####### #######
   #    #     #  #   #          #     # #     # #     # #     #    #
   #    #     #   # #           #     # #     # #     # #     #    #
   #    #     #    #            ######  #     # ######  #     #    #
   #    #     #    #            #   #   #     # #     # #     #    #
   #    #     #    #            #    #  #     # #     # #     #    #
   #    #######    #            #     # ####### ######  #######    #
#######################################################################
Enter command as follows:
PLACE X,Y,F:   Place robot at (0<=x<5),(0<=y<5) position facing NORTH, EAST, SOUTH or WEST.
               Example: PLACE 3,4,WEST
MOVE       :   Move the toy robot one unit forward in the direction it is currently facing.
LEFT       :   Rotate the robot 90 degrees left without changing the position of the robot.
RIGHT      :   Rotate the robot 90 degrees right without changing the position of the robot.
REPORT     :   Announce the X,Y and F of the robot.

''')
    for line in sys.stdin:
        valid = re.match(r"(\w+)( (.*))?", line)
        if not valid:
            print("ERROR: Invalid format for line: ", line)
            continue
        global first_cmd
        if first_cmd and valid.group(1) != "PLACE":
            print("ERROR: First command must be PLACE")
            continue
        else:
            first_cmd = False

        commands.execute(
            valid.group(1),
            valid.group(3).split(',') if valid.lastindex > 1 else [])