Esempio n. 1
0
    def test_courier_available_event(self):
        """Test to verify the mechanics of how the dispatcher sets a courier to available"""

        # Constants
        initial_time = hour_to_sec(14)
        on_time = time(14, 0, 0)
        off_time = time(15, 0, 0)
        service_time = min_to_sec(6)

        # Services
        env = Environment(initial_time=initial_time)
        dispatcher = Dispatcher(env=env, matching_policy=DummyMatchingPolicy())

        # Creates a courier and sets it to the picking state
        courier = Courier(dispatcher=dispatcher, env=env, courier_id=32, on_time=on_time, off_time=off_time)
        dispatcher.idle_couriers = {courier.courier_id: courier}
        env.process(courier._picking_up_state(
            orders={
                21: Order(drop_off_service_time=service_time, ready_time=time(14, 20, 0))
            }
        ))
        env.run(until=initial_time + min_to_sec(10))

        # Verify courier properties are modified and it is allocated correctly
        self.assertEqual(courier.condition, 'picking_up')
        self.assertIn(courier.courier_id, dispatcher.picking_up_couriers.keys())
        self.assertEqual(dispatcher.idle_couriers, {})
Esempio n. 2
0
    def test_courier_idle_event(self, *args):
        """Test to verifiy the mechanics of how a courier is set to idle by the dispatcher"""

        # Constants
        initial_time = hour_to_sec(14)
        courier_id = 85
        time_delta = min_to_sec(10)
        random.seed(26)
        on_time = time(14, 0, 0)
        off_time = time(15, 0, 0)

        # Verifies 3 test cases: when the courier is busy, available or idle.
        # For each test case, assert the courier starts in a set and ends up in the idle set

        # Test 1: courier is busy
        env = Environment(initial_time=initial_time)
        dispatcher = Dispatcher(env=env, matching_policy=DummyMatchingPolicy())
        courier = Courier(dispatcher=dispatcher, env=env, courier_id=courier_id, on_time=on_time, off_time=off_time)
        dispatcher.moving_couriers = {courier.courier_id: courier}
        dispatcher.courier_idle_event(courier)
        env.run(until=initial_time + time_delta)
        self.assertIn(courier.courier_id, dispatcher.idle_couriers.keys())
        self.assertEqual(dispatcher.moving_couriers, {})
        self.assertEqual(dispatcher.picking_up_couriers, {})

        # Test 2: courier is available
        env = Environment(initial_time=initial_time)
        dispatcher = Dispatcher(env=env, matching_policy=DummyMatchingPolicy())
        courier = Courier(dispatcher=dispatcher, env=env, courier_id=courier_id, on_time=on_time, off_time=off_time)
        dispatcher.picking_up_couriers = {courier.courier_id: courier}
        dispatcher.courier_idle_event(courier)
        env.run(until=initial_time + time_delta)
        self.assertIn(courier.courier_id, dispatcher.idle_couriers.keys())
        self.assertEqual(dispatcher.moving_couriers, {})
        self.assertEqual(dispatcher.picking_up_couriers, {})

        # Test 3: courier is idle
        env = Environment(initial_time=initial_time)
        dispatcher = Dispatcher(env=env, matching_policy=DummyMatchingPolicy())
        courier = Courier(dispatcher=dispatcher, env=env, courier_id=courier_id, on_time=on_time, off_time=off_time)
        dispatcher.idle_couriers = {courier.courier_id: courier}
        dispatcher.courier_idle_event(courier)
        env.run(until=initial_time + time_delta)
        self.assertIn(courier.courier_id, dispatcher.idle_couriers.keys())
        self.assertEqual(dispatcher.moving_couriers, {})
        self.assertEqual(dispatcher.picking_up_couriers, {})