def testUpdateRidersInWaitDict(self): r1 = Rider("R1", 0, 7, 1, 10, 20, 1, 1, 2, 1) dispatch = Dispatcher() for zone_id in range(1, 78): dispatch.cancel_rider[zone_id] = 0 dispatch.handleRiderIntoDict(r1) RiderStatusTracker.timestamp = 1 dispatch.updateRidersInWaitDict() self.assertEqual(WAITING, r1.getStatus()) self.assertEqual( "7: {0: {}, 1: {}, 2: {}, 3: {}, 4: {}, 5: {}, 6: {1: [R1, ], }, 7: {}, 8: {}, 9: {}, 10: {}, 11: {}, -1: {}, }", dispatch.showRiderWaitDict(7)) self.assertEqual(1, r1.getWaitTime()) self.assertEqual(1, dispatch.countRiderNumberInWaitDict()) RiderStatusTracker.timestamp = 21 dispatch.updateRidersInWaitDict() self.assertEqual(CANCEL, r1.getStatus()) self.assertEqual( "7: {0: {}, 1: {}, 2: {}, 3: {}, 4: {}, 5: {}, 6: {}, 7: {}, 8: {}, 9: {}, 10: {}, 11: {}, -1: {}, }", dispatch.showRiderWaitDict(7)) self.assertEqual("{R1, }", dispatch.showRiderCanceledDict()) self.assertEqual(1, r1.getWaitTime()) self.assertEqual(1, dispatch.countRiderNumberInCancelDict())
def testConstructor(self): r1 = Rider("R1", 0, 7, 6, 10, 20, 1, 1, 2, 1) self.assertEqual("R1", r1.getID()) self.assertEqual(0, r1.getRequestTimeStamp()) self.assertEqual(7, r1.getSrcZone()) self.assertEqual(6, r1.getDestZone()) self.assertEqual(10, r1.getDefaultPrice()) self.assertEqual(math.inf, r1.getPrice()) self.assertEqual(20, r1.getPatience()) self.assertEqual(1, r1.getShortestTime()) self.assertEqual(None, r1.getArrivalTimestamp()) self.assertEqual(None, r1.getGroupID()) self.assertEqual("waiting", r1.getStatus()) self.assertEqual(0, r1.getWaitTime()) self.assertEqual(-1, r1.getDetourTime()) self.assertEqual(0, r1.getSat()) self.assertEqual( "{R1, 0, 7, 6, 10, inf, 20, 6, 1, None, None, waiting, 0, -1, 0}", str(r1))
def testUpdateDriverInDictWhenInService(self): Driver.timestamp = 0 Rider.timestamp = 0 Dispatcher.timestamp = 0 DriverStatusTracker.timestamp = 0 d1 = Driver("D1", 22) r1 = Rider("R1", 0, 7, 1, 10, 20, 1, 1, 2, 1) # 0 r2 = Rider("R2", 0, 7, 3, 10, 20, 1, 1, 2, 1) r3 = Rider("R3", 0, 7, 6, 10, 20, 1, 1, 2, 1) r4 = Rider("R4", 0, 7, 6, 10, 20, 1, 1, 2, 1) dispatch = Dispatcher() dispatch.handleDriverIntoDict(d1) dispatch.handleRiderIntoDict(r1) dispatch.handleRiderIntoDict(r2) dispatch.handleRiderIntoDict(r3) dispatch.handleRiderIntoDict(r4) dispatch.matchRidertoDriver() dispatch.updateDriverInDict() self.assertEqual("[7, 6, 6, 3, 1]", d1.showTripRoute()) self.assertEqual("[R1, R2, R3, R4]", d1.showRidersOnBoard()) Driver.timestamp = 1 Rider.timestamp = 1 Dispatcher.timestamp = 1 DriverStatusTracker.timestamp = 1 dispatch.updateDriverInDict() self.assertEqual("[6, 6, 3, 1]", d1.showTripRoute()) self.assertEqual("[R1, R2, R3, R4]", d1.showRidersOnBoard()) self.assertEqual("{R1, R2, R3, R4, }", dispatch.showRiderServedDict()) Driver.timestamp = 2 Rider.timestamp = 2 Dispatcher.timestamp = 2 DriverStatusTracker.timestamp = 2 dispatch.updateDriverInDict() self.assertEqual("[3, 1]", d1.showTripRoute()) self.assertEqual("[R1, R2]", d1.showRidersOnBoard()) self.assertEqual(FINISHED, r3.getStatus()) self.assertEqual(FINISHED, r4.getStatus()) self.assertEqual("{R1, R2, }", dispatch.showRiderServedDict()) self.assertEqual("{R3, R4, }", dispatch.showRiderFinishedDict()) Driver.timestamp = 3 Rider.timestamp = 3 Dispatcher.timestamp = 3 DriverStatusTracker.timestamp = 3 dispatch.updateDriverInDict() self.assertEqual("[1]", d1.showTripRoute()) self.assertEqual("[R1]", d1.showRidersOnBoard()) self.assertEqual(FINISHED, r2.getStatus()) self.assertEqual("{R1, }", dispatch.showRiderServedDict()) self.assertEqual("{R2, R3, R4, }", dispatch.showRiderFinishedDict()) Driver.timestamp = 5 Rider.timestamp = 5 Dispatcher.timestamp = 5 DriverStatusTracker.timestamp = 5 dispatch.updateDriverInDict() self.assertEqual("[]", d1.showTripRoute()) self.assertEqual("[]", d1.showRidersOnBoard()) self.assertEqual(FINISHED, r1.getStatus()) self.assertEqual(IDLE, d1.getStatus()) self.assertEqual("{}", dispatch.showRiderServedDict()) self.assertEqual("{R1, R2, R3, R4, }", dispatch.showRiderFinishedDict()) self.assertEqual(1, dispatch.countTotalDriverNumber()) self.assertEqual(4, dispatch.countCurrentTotalRiderNumber())
def testSetStatus(self): r0 = Rider("R0", 0, 8, 24, 7.75, 20, -87.6333, 41.8996, -87.6764, 41.9012) r0.setStatus(SERVING) self.assertEqual(SERVING, r0.getStatus())