def setUp(self) :
        robot_start_x = 0
        robot_start_y = 0
        robot_location = Location(robot_start_x, robot_start_y)

        self.warehouse = Warehouse(robot_location)
        self.warehouse.spawn_crate(Crate(Location(4, 4)))
        self.warehouse.spawn_crate(Crate(Location(9, 9)))
Example #2
0
 def __init__(self, warehouse_calls_in: RobotWarehouseInterface,
              initial_location: Location):
     self.warehouse_calls = warehouse_calls_in
     self.location = initial_location
     self.has_crate = False
     self.movement_to_location_map = {
         RobotDirection.NORTH: Location(0, 1),
         RobotDirection.SOUTH: Location(0, -1),
         RobotDirection.WEST: Location(-1, 0),
         RobotDirection.EAST: Location(1, 0)
     }
     return
    def test_move_outside_warehouse_east_boundary_is_stopped(self):
        robot_start_x = 9
        robot_end_x = 9

        move_command = RobotDirection.EAST
        robot_start_y = 0
        robot_location = Location(robot_start_x, robot_start_y)

        warehouse = Warehouse(robot_location)
        warehouse.issue_command_to_robot(move_command)

        self.assertEqual(robot_end_x, robot_location.x)
    def test_drop_crate_at_location_creates_crate(self):
        location = Location(1,1)
        crate_at_location_before = self.warehouse.check_crate_at_location(location)
        self.assertFalse(crate_at_location_before)

        self.warehouse.robot.process_direction(RobotDirection.GRAB)

        self.assertTrue(self.warehouse.robot.has_crate)
        self.assertFalse(self.warehouse.check_crate_at_location(location))

        self.warehouse.robot.process_direction(RobotDirection.DROP)
        self.assertTrue(self.warehouse.check_crate_at_location(location))
    def test_move_outside_warehouse_south_is_stopped(self):
        robot_start_x = 0
        robot_start_y = 0

        move_command = RobotDirection.SOUTH
        robot_end_y = 0

        robot_location = Location(robot_start_x, robot_start_y)

        warehouse = Warehouse(robot_location)
        warehouse.issue_command_to_robot(move_command)

        self.assertEqual(robot_end_y, robot_location.y)
    def test_move_east(self):
        robot_start_x = 2
        robot_start_y = 2

        move_command = RobotDirection.EAST
        expected_x_result = 3

        robot_location = Location(robot_start_x, robot_start_y)

        warehouse = Warehouse(robot_location)
        warehouse.issue_command_to_robot(move_command)

        self.assertEqual(expected_x_result, robot_location.x)
        self.assertEqual(robot_start_y, robot_location.y)
Example #7
0
        result_location.y = 0 if result_location.y < 0 else result_location.y
        result_location.x = self.GRID_X_MAX if result_location.x > self.GRID_X_MAX else result_location.x
        result_location.y = self.GRID_Y_MAX if result_location.y > self.GRID_Y_MAX else result_location.y

        return result_location

    def spawn_crate(self, crate: Crate):
        self.crates.append(crate)

    def __init__(self, robot_start_location: Location):
        self.robot = Robot(self, robot_start_location)
        self.crates: List[Crate] = []


if __name__ == '__main__':

    robot_start_x = 0
    robot_start_y = 0
    robot_location = Location(robot_start_x, robot_start_y)

    warehouse = Warehouse(robot_location)
    warehouse.spawn_crate(Crate(Location(4, 4)))
    warehouse.spawn_crate(Crate(Location(9, 9)))

    commandString = "N E"

    commands = CommandParser.process_string(commandString)

    for command in commands:
        warehouse.issue_command_to_robot(command)
 def test_initial_robot_position_2_2(self):
     robot_start_x = 2
     robot_start_y = 2
     robot_location = Location(robot_start_x, robot_start_y)
     self.assertEqual(robot_start_x, robot_location.x)
     self.assertEqual(robot_start_y, robot_location.y)
    def test_crate_at_location_returns_true(self):

        result = self.warehouse.check_crate_at_location(Location(4,4))
        self.assertTrue(result)
    def test_crate_not_at_location_returns_false(self):

        result = self.warehouse.check_crate_at_location(Location(1,1))
        self.assertFalse(result)