def test_robot_action_with_extra_arguments(self): # should not perform action if extra arguments are passed in robot = Robot(0, 0, 'NORTH', self.max_columns, self.max_rows) robot.perform_action('MOVE 222') self.assert_robot_state(robot, 0, 0, [0, 1]) robot.perform_action('LEFT JUNK VALUE') self.assert_robot_state(robot, 0, 0, [0, 1]) robot.perform_action('RIGHT -$$$-') self.assert_robot_state(robot, 0, 0, [0, 1])
def main(): # choose file automatically through a dialog window root = tk.Tk() root.withdraw() # read the default values from the configuration file config = configparser.ConfigParser() config.read('config.ini') # get the default dimensions of the board max_columns = int(config['DEFAULT']['N']) max_rows = int(config['DEFAULT']['M']) # get path to the command file command_file_path = config['DEFAULT']['INPUT_FILE_PATH'] # get the default starting position and facing direction of the robot default_start_x = int(config['DEFAULT']['START_X']) default_start_y = int(config['DEFAULT']['START_Y']) default_direction = config['DEFAULT']['FACING_DIRECTION'] # initialize the robot with these default starting values robot = Robot(default_start_x, default_start_y, default_direction, max_columns, max_rows) input_file_path = filedialog.askopenfilename( initialdir="./", title='Select the command file') root.update() root.destroy() # perform the actions present in the command file if len(input_file_path) > 0: robot.run(input_file_path) else: robot.run(command_file_path)
def test_robot_move_outside_board(self): # robot should ignore commands to move outside the board robot = Robot(0, 0, 'NORTH', self.max_columns, self.max_rows) robot.rotate(Constants.ANTI_CLOCKWISE) robot.perform_action(CommandType.MOVE.name) robot.perform_action(CommandType.MOVE.name) self.assert_robot_state(robot, 0, 0, [-1, 0])
def main(): # read the default values from the configuration file config = configparser.ConfigParser() config.read('config.ini') # get the default dimensions of the board max_columns = int(config['DEFAULT']['N']) max_rows = int(config['DEFAULT']['M']) # get path to the command file command_file_path = config['DEFAULT']['INPUT_FILE_PATH'] # get the default starting position and facing direction of the robot default_start_x = int(config['DEFAULT']['START_X']) default_start_y = int(config['DEFAULT']['START_Y']) default_direction = config['DEFAULT']['FACING_DIRECTION'] # initialize the robot with these default starting values robot = Robot(default_start_x, default_start_y, default_direction, max_columns, max_rows) # perform the actions present in the command file robot.run(command_file_path)
def test_robot_move_outside_board_from_top(self): # the agent should not move beyond the limits of the board # even when asked to robot = Robot(0, 0, 'NORTH', self.max_columns, self.max_rows) robot.perform_action('PLACE ' + str(self.max_columns - 1) + ' ' + str(self.max_rows - 1) + ' ' + Direction.NORTH.name) self.assert_robot_state(robot, self.max_columns - 1, self.max_rows - 1, [0, 1]) robot.perform_action(CommandType.MOVE.name) robot.perform_action(CommandType.MOVE.name) self.assert_robot_state(robot, self.max_columns - 1, self.max_rows - 1, [0, 1])
def test_main(self): robot = Robot(0, 0, 'NORTH', self.max_columns, self.max_rows) robot.run(Constants.INPUT_FILE_PATH) assert robot.state.x == 3 assert robot.state.y == 3 assert robot.state.direction_vector == [0, 1]
def test_robot_right_action(self): # the agent should move in the direction it is facing robot = Robot(0, 0, 'NORTH', self.max_columns, self.max_rows) robot.perform_action('RIGHT') self.assert_robot_state(robot, 0, 0, [1, 0])
def test_robot_move_action(self): # the agent should move in the direction it is facing robot = Robot(0, 0, 'NORTH', self.max_columns, self.max_rows) robot.perform_action('MOVE') self.assert_robot_state(robot, 0, 1, [0, 1])