def testCalcTripProfitWithNoRider(self): try: d1 = Driver("V0", 23) d1.calcTripProfit() self.fail("Expected Exception here.") except: pass
def testCalcTripRouteFailure(self): try: d1 = Driver("V0", 23) d1.calcTripRoute() self.fail("Expected exception here.") except: pass
def testUpdateDriverInDictWhenIdle(self): d1 = Driver("D1", 1) dispatcher = Dispatcher() dispatcher.handleDriverIntoDict(d1) dispatcher.updateDriverInDict() self.assertEqual(1, d1.getIdleTime())
def testUpdateDriverInDictFailure(self): try: d1 = Driver("D1", 22) d1.setStatus("ffff") dispatch = Dispatcher() dispatch.handleDriverIntoDict(d1) dispatch.updateDriverInDict() self.fail("Expected exception here.") except: pass
def testHandleDriverIntoDictWithSameDriver(self): try: d1 = Driver("D1", 7) d2 = Driver("D1", 7) dispatcher = Dispatcher() dispatcher.handleDriverIntoDict(d1) dispatcher.handleDriverIntoDict(d2) self.fail("Expected exception here.") except: pass
def testAddDriver(self): d1 = Driver("D1", 2) d2 = Driver("D2", 2) rl = RequestList() rl.add(d1) rl.add(d2) self.assertEqual( "[{D1, 2, idle, 0, 0, Riders: [], Route: []}, {D2, 2, idle, 0, 0, Riders: [], Route: []}, ]", str(rl)) self.assertEqual(2, len(rl)) self.assertEqual(False, rl.is_empty()) self.assertEqual("{D1, 2, idle, 0, 0, Riders: [], Route: []}", str(rl.first_element()))
def testNotifyRiderPrice(self): d1 = Driver("V0", 23) 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, 77, 10, 20, 1, 1, 2, 1) r4 = Rider("R4", 0, 7, 6, 10, 20, 1, 1, 2, 1) riders = {"R1": r1, "R2": r2, "R3": r3, "R4": r4} d1.setRiders(riders) d1.calcTripRoute() d1.calcTripEffort() d1.notifyRiderPrice() self.assertAlmostEqual(7.87208, r1.getPrice(), delta=0.01) self.assertAlmostEqual(7.87208, r2.getPrice(), delta=0.01) self.assertAlmostEqual(7.87208, r3.getPrice(), delta=0.01) self.assertAlmostEqual(7.87208, r4.getPrice(), delta=0.01)
def testCalcTripProfitWithWrongPrice(self): try: d1 = Driver("V0", 23) 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, 77, 10, 20, 1, 1, 2, 1) r4 = Rider("R4", 0, 7, 6, 10, 20, 1, 1, 2, 1) riders = {"R1": r1, "R2": r2, "R3": r3, "R4": r4} d1.setRiders(riders) d1.calcTripRoute() d1.calcTripEffort() d1.calcTripProfit() self.fail("Expected Exception here.") except: pass
def testRemoveRider(self): try: d1 = Driver("V0", 23) r1 = Rider("R1", 0, 7, 1, 10, 20, 1, 1, 2, 1) # 0 riders = {"R1": r1} d1.setRiders(riders) d1.removeRider("R1") self.assertEqual("[]", d1.showRidersOnBoard()) d1.removeRider("R2") self.fail("Expected exception here.") except: pass
def testHandleRiderIntoDictFailure(self): try: d1 = Driver("D1", 7) dispatcher = Dispatcher() dispatcher.handleRiderIntoDict(d1) self.fail("Expected exception here.") except: pass
def testConstructor(self): d1 = Driver("V0", 23) self.assertEqual("V0", d1.getID()) self.assertEqual(23, d1.getPos()) self.assertEqual(IDLE, d1.getStatus()) self.assertEqual(0, d1.getTripEffort()) self.assertEqual(0, d1.getTripProfit()) self.assertEqual(0, d1.getIdleTime()) self.assertEqual("{V0, 23, idle, 0, 0, Riders: [], Route: []}", str(d1))
def importDriverData(file_name, driver_list): driver = pd.read_csv(file_name) numOfDriver = len(driver) print("Import Driver Data:") for i in range(0, numOfDriver): obs = driver.iloc[i, :] actor_id = obs["ID"] zone_id = obs["Zone"] driver_list.add(Driver(actor_id, zone_id)) if i % 100 == 0: print(i)
def testHandleDriverIntoDictSuccess(self): d1 = Driver("D1", 1) d2 = Driver("D2", 20) d3 = Driver("D3", 77) d4 = Driver("D4", 77) dispatcher = Dispatcher() dispatcher.handleDriverIntoDict(d1) dispatcher.handleDriverIntoDict(d2) dispatcher.handleDriverIntoDict(d3) dispatcher.handleDriverIntoDict(d4) self.assertEqual("1: {D1, }", dispatcher.showDriverDict(1)) self.assertEqual(d1, dispatcher.getDriverFromDriverDict(1, "D1")) self.assertEqual(1, dispatcher.getDriverNumberOfZone(1)) self.assertEqual("20: {D2, }", dispatcher.showDriverDict(20)) self.assertEqual(d2, dispatcher.getDriverFromDriverDict(20, "D2")) self.assertEqual(1, dispatcher.getDriverNumberOfZone(20)) self.assertEqual("77: {D3, D4, }", dispatcher.showDriverDict(77)) self.assertEqual(d3, dispatcher.getDriverFromDriverDict(77, "D3")) self.assertEqual(d4, dispatcher.getDriverFromDriverDict(77, "D4")) self.assertEqual(2, dispatcher.getDriverNumberOfZone(77)) self.assertEqual(4, dispatcher.countTotalDriverNumber()) self.assertEqual(0, dispatcher.countCurrentTotalRiderNumber())
def testRemoveDriver(self): d1 = Driver("D1", 2) d2 = Driver("D2", 2) rl = RequestList() rl.add(d1) rl.add(d2) rl.remove() self.assertEqual("[{D2, 2, idle, 0, 0, Riders: [], Route: []}, ]", str(rl)) self.assertEqual(1, len(rl)) self.assertEqual(False, rl.is_empty()) self.assertEqual("{D2, 2, idle, 0, 0, Riders: [], Route: []}", str(rl.first_element())) rl.remove() self.assertEqual("[]", str(rl)) self.assertEqual(0, len(rl)) self.assertEqual(True, rl.is_empty()) try: rl.first_element() self.fail("Expected exception here.") except: pass
def testAddRidersIntoVehicle(self): try: d1 = Driver("V0", 23) 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, 77, 10, 20, 1, 1, 2, 1) r4 = Rider("R4", 0, 7, 6, 10, 20, 1, 1, 2, 1) riders = {"R1": r1, "R2": r2, "R3": r3, "R4": r4} d1.setRiders(riders) self.assertEqual(r1, d1.getRider("R1")) self.assertEqual(r2, d1.getRider("R2")) self.assertEqual(r3, d1.getRider("R3")) self.assertEqual(r4, d1.getRider("R4")) d1.getRider("R5") self.fail("Expected exception here.") except: pass
def testCalcTripRouteSuccess(self): d1 = Driver("V0", 23) 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, 77, 10, 20, 1, 1, 2, 1) r4 = Rider("R4", 0, 7, 6, 10, 20, 1, 1, 2, 1) riders = {"R1": r1, "R2": r2, "R3": r3, "R4": r4} d1.setRiders(riders) d1.calcTripRoute() self.assertEqual("[7, 6, 3, 77, 1]", d1.showTripRoute()) try: elem1 = d1.popTripRoute() self.assertEqual(7, elem1.getZoneID()) self.assertEqual(PICKUP, elem1.getEvent()) self.assertEqual(None, elem1.getRiderID()) elem2 = d1.popTripRoute() self.assertEqual(6, elem2.getZoneID()) self.assertEqual(DROPOFF, elem2.getEvent()) self.assertEqual("R4", elem2.getRiderID()) elem3 = d1.popTripRoute() self.assertEqual(3, elem3.getZoneID()) self.assertEqual(DROPOFF, elem3.getEvent()) self.assertEqual("R2", elem3.getRiderID()) elem4 = d1.popTripRoute() self.assertEqual(77, elem4.getZoneID()) self.assertEqual(DROPOFF, elem4.getEvent()) self.assertEqual("R3", elem4.getRiderID()) elem5 = d1.popTripRoute() self.assertEqual(1, elem5.getZoneID()) self.assertEqual(DROPOFF, elem5.getEvent()) self.assertEqual("R1", elem5.getRiderID()) elem6 = d1.popTripRoute() self.fail("Expected exception here.") except: pass
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 testCalcTripProfitSuccess(self): d1 = Driver("V0", 23) 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, 77, 10, 20, 1, 1, 2, 1) r4 = Rider("R4", 0, 7, 6, 10, 20, 1, 1, 2, 1) riders = {"R1": r1, "R2": r2, "R3": r3, "R4": r4} d1.setRiders(riders) d1.calcTripRoute() d1.calcTripEffort() r1.calcPrice(4) r2.calcPrice(4) r3.calcPrice(4) r4.calcPrice(4) d1.calcTripProfit() self.assertAlmostEqual(26.0883, d1.getTripProfit(), delta=0.01)
def testMatchRidertoDriver(self): r1 = Rider("R1", 0, 1, 6, 10, 20, 1, 1, 2, 1) # 0 r2 = Rider("R2", 0, 1, 6, 10, 20, 1, 1, 2, 1) r5 = Rider("R5", 0, 1, 6, 10, 20, 1, 1, 2, 1) r6 = Rider("R6", 0, 1, 6, 10, 20, 1, 1, 2, 1) r8 = Rider("R8", 0, 1, 6, 10, 20, 1, 1, 2, 1) r9 = Rider("R9", 0, 1, 7, 10, 20, 1, 1, 2, 1) r3 = Rider("R3", 0, 1, 4, 10, 20, 1, 1, 1, 2) #90 r4 = Rider("R4", 0, 1, 6, 10, 20, 1, 1, 1, 2) r7 = Rider("R7", 0, 1, 8, 10, 20, 1, 1, 1, 2) r10 = Rider("R10", 0, 1, 6, 10, 20, 1, 1, 2, 2) #45 r11 = Rider("R11", 0, 1, 28, 10, 20, 1, 1, 2, 2) r12 = Rider("R12", 0, 1, 8, 10, 20, 1, 1, 2, 2) r13 = Rider("R13", 0, 1, 6, 10, 20, 1, 1, 0, 2) # 135 r14 = Rider("R14", 0, 1, 6, 10, 20, 1, 1, 0, 1) #-180 r15 = Rider("R15", 0, 1, 6, 10, 20, 1, 1, 1, 0) # -90 d1 = Driver("D1", 2) d2 = Driver("D2", 2) d3 = Driver("D3", 2) d4 = Driver("D4", 1) d5 = Driver("D5", 1) d6 = Driver("D6", 77) dispatcher = Dispatcher() Dispatcher.timestamp = 0 Driver.timestamp = 0 Rider.timestamp = 0 dispatcher.handleDriverIntoDict(d1) dispatcher.handleDriverIntoDict(d2) dispatcher.handleDriverIntoDict(d3) dispatcher.handleDriverIntoDict(d4) dispatcher.handleDriverIntoDict(d5) dispatcher.handleDriverIntoDict(d6) dispatcher.handleRiderIntoDict(r1) dispatcher.handleRiderIntoDict(r2) dispatcher.handleRiderIntoDict(r3) dispatcher.handleRiderIntoDict(r4) dispatcher.handleRiderIntoDict(r5) dispatcher.handleRiderIntoDict(r6) dispatcher.handleRiderIntoDict(r7) dispatcher.handleRiderIntoDict(r8) dispatcher.handleRiderIntoDict(r9) dispatcher.handleRiderIntoDict(r10) dispatcher.handleRiderIntoDict(r11) dispatcher.handleRiderIntoDict(r12) dispatcher.handleRiderIntoDict(r13) dispatcher.handleRiderIntoDict(r14) dispatcher.handleRiderIntoDict(r15) print(dispatcher.showRiderWaitDict(1)) dispatcher.matchRidertoDriver() print(dispatcher.showRiderWaitDict(1)) #observer dispatch self.assertEqual( "{R1, R10, R11, R12, R14, R15, R2, R3, R4, R5, R6, R7, R8, R9, }", dispatcher.showRiderServedDict()) self.assertEqual( "R13", dispatcher.getRiderFromWaitDict(1, 10, 1, "R13").getID()) self.assertEqual(6, dispatcher.countTotalDriverNumber()) self.assertEqual(1, dispatcher.countRiderNumberInWaitDict()) self.assertEqual(14, dispatcher.countRiderNumberInServeDict()) # observer rider self.assertEqual(SERVING, dispatcher.getRiderFromServedDict("R14").getStatus()) self.assertEqual( 1, dispatcher.getRiderFromServedDict("R14").getDetourTime()) self.assertAlmostEqual( 9.132, dispatcher.getRiderFromServedDict("R14").getPrice(), delta=0.01) self.assertAlmostEqual( 2.452, dispatcher.getRiderFromServedDict("R14").getSat(), delta=0.01) self.assertEqual( 4, dispatcher.getRiderFromServedDict("R14").getArrivalTimestamp()) self.assertEqual(SERVING, dispatcher.getRiderFromServedDict("R15").getStatus()) self.assertEqual( 0, dispatcher.getRiderFromServedDict("R15").getDetourTime()) self.assertAlmostEqual( 9.6, dispatcher.getRiderFromServedDict("R15").getPrice(), delta=0.01) self.assertAlmostEqual( 1.822, dispatcher.getRiderFromServedDict("R15").getSat(), delta=0.01) self.assertEqual( 3, dispatcher.getRiderFromServedDict("R15").getArrivalTimestamp()) self.assertEqual(SERVING, dispatcher.getRiderFromServedDict("R1").getStatus()) self.assertEqual( 1, dispatcher.getRiderFromServedDict("R1").getDetourTime()) self.assertAlmostEqual( 8.276, dispatcher.getRiderFromServedDict("R1").getPrice(), delta=0.01) self.assertAlmostEqual( 12.057, dispatcher.getRiderFromServedDict("R1").getSat(), delta=0.01) self.assertEqual( 4, dispatcher.getRiderFromServedDict("R1").getArrivalTimestamp()) self.assertEqual(SERVING, dispatcher.getRiderFromServedDict("R2").getStatus()) self.assertEqual( 1, dispatcher.getRiderFromServedDict("R2").getDetourTime()) self.assertAlmostEqual( 8.276, dispatcher.getRiderFromServedDict("R2").getPrice(), delta=0.01) self.assertAlmostEqual( 12.057, dispatcher.getRiderFromServedDict("R2").getSat(), delta=0.01) self.assertEqual( 4, dispatcher.getRiderFromServedDict("R2").getArrivalTimestamp()) self.assertEqual(SERVING, dispatcher.getRiderFromServedDict("R5").getStatus()) self.assertEqual( 1, dispatcher.getRiderFromServedDict("R5").getDetourTime()) self.assertAlmostEqual( 8.276, dispatcher.getRiderFromServedDict("R5").getPrice(), delta=0.01) self.assertAlmostEqual( 12.057, dispatcher.getRiderFromServedDict("R5").getSat(), delta=0.01) self.assertEqual( 4, dispatcher.getRiderFromServedDict("R5").getArrivalTimestamp()) self.assertEqual(SERVING, dispatcher.getRiderFromServedDict("R6").getStatus()) self.assertEqual( 1, dispatcher.getRiderFromServedDict("R6").getDetourTime()) self.assertAlmostEqual( 8.276, dispatcher.getRiderFromServedDict("R6").getPrice(), delta=0.01) self.assertAlmostEqual( 12.057, dispatcher.getRiderFromServedDict("R6").getSat(), delta=0.01) self.assertEqual( 4, dispatcher.getRiderFromServedDict("R6").getArrivalTimestamp()) self.assertEqual(SERVING, dispatcher.getRiderFromServedDict("R8").getStatus()) self.assertEqual( 0, dispatcher.getRiderFromServedDict("R8").getDetourTime()) self.assertAlmostEqual( 9.3, dispatcher.getRiderFromServedDict("R8").getPrice(), delta=0.01) self.assertAlmostEqual( 2.858, dispatcher.getRiderFromServedDict("R8").getSat(), delta=0.01) self.assertEqual( 3, dispatcher.getRiderFromServedDict("R8").getArrivalTimestamp()) self.assertEqual(SERVING, dispatcher.getRiderFromServedDict("R9").getStatus()) self.assertEqual( 0, dispatcher.getRiderFromServedDict("R9").getDetourTime()) self.assertAlmostEqual( 9.3, dispatcher.getRiderFromServedDict("R9").getPrice(), delta=0.01) self.assertAlmostEqual( 2.858, dispatcher.getRiderFromServedDict("R9").getSat(), delta=0.01) self.assertEqual( 4, dispatcher.getRiderFromServedDict("R9").getArrivalTimestamp()) self.assertEqual(SERVING, dispatcher.getRiderFromServedDict("R10").getStatus()) self.assertEqual( 1, dispatcher.getRiderFromServedDict("R10").getDetourTime()) self.assertAlmostEqual( 8.561, dispatcher.getRiderFromServedDict("R10").getPrice(), delta=0.01) self.assertAlmostEqual( 7.432, dispatcher.getRiderFromServedDict("R10").getSat(), delta=0.01) self.assertEqual( 4, dispatcher.getRiderFromServedDict("R10").getArrivalTimestamp()) self.assertEqual(SERVING, dispatcher.getRiderFromServedDict("R11").getStatus()) self.assertEqual( 1, dispatcher.getRiderFromServedDict("R11").getDetourTime()) self.assertAlmostEqual( 8.561, dispatcher.getRiderFromServedDict("R11").getPrice(), delta=0.01) self.assertAlmostEqual( 7.432, dispatcher.getRiderFromServedDict("R11").getSat(), delta=0.01) self.assertEqual( 7, dispatcher.getRiderFromServedDict("R11").getArrivalTimestamp()) self.assertEqual(SERVING, dispatcher.getRiderFromServedDict("R12").getStatus()) self.assertEqual( 1, dispatcher.getRiderFromServedDict("R12").getDetourTime()) self.assertAlmostEqual( 8.561, dispatcher.getRiderFromServedDict("R12").getPrice(), delta=0.01) self.assertAlmostEqual( 7.432, dispatcher.getRiderFromServedDict("R12").getSat(), delta=0.01) self.assertEqual( 6, dispatcher.getRiderFromServedDict("R12").getArrivalTimestamp()) self.assertEqual(SERVING, dispatcher.getRiderFromServedDict("R3").getStatus()) self.assertEqual( 1, dispatcher.getRiderFromServedDict("R3").getDetourTime()) self.assertAlmostEqual( 8.561, dispatcher.getRiderFromServedDict("R3").getPrice(), delta=0.01) self.assertAlmostEqual( 7.432, dispatcher.getRiderFromServedDict("R3").getSat(), delta=0.01) self.assertEqual( 3, dispatcher.getRiderFromServedDict("R3").getArrivalTimestamp()) self.assertEqual(SERVING, dispatcher.getRiderFromServedDict("R4").getStatus()) self.assertEqual( 1, dispatcher.getRiderFromServedDict("R4").getDetourTime()) self.assertAlmostEqual( 8.561, dispatcher.getRiderFromServedDict("R4").getPrice(), delta=0.01) self.assertAlmostEqual( 7.432, dispatcher.getRiderFromServedDict("R4").getSat(), delta=0.01) self.assertEqual( 4, dispatcher.getRiderFromServedDict("R4").getArrivalTimestamp()) self.assertEqual(SERVING, dispatcher.getRiderFromServedDict("R7").getStatus()) self.assertEqual( 1, dispatcher.getRiderFromServedDict("R7").getDetourTime()) self.assertAlmostEqual( 8.561, dispatcher.getRiderFromServedDict("R7").getPrice(), delta=0.01) self.assertAlmostEqual( 7.432, dispatcher.getRiderFromServedDict("R7").getSat(), delta=0.01) self.assertEqual( 6, dispatcher.getRiderFromServedDict("R7").getArrivalTimestamp()) self.assertEqual(0, dispatcher.calcAverageWaitTimeOfRiders()) self.assertAlmostEqual(0.786, dispatcher.calcAverageDetourTimeOfRiders(), delta=0.01) self.assertAlmostEqual(0, dispatcher.calcAverageWaitTimeOfRiders()) self.assertEqual(10, dispatcher.calcAverageDefaultFareRiders()) self.assertAlmostEqual(8.7, dispatcher.calcAverageFareOfRiders(), delta=0.01) self.assertAlmostEqual(7.343, dispatcher.calcAverageSatOfRiders(), delta=0.01) #observe driver self.assertEqual( "[R14]", dispatcher.getDriverFromDriverDict(2, "D1").showRidersOnBoard()) self.assertEqual( "[1, 6]", dispatcher.getDriverFromDriverDict(2, "D1").showTripRoute()) self.assertEqual( INSERVICE, dispatcher.getDriverFromDriverDict(2, "D1").getStatus()) self.assertEqual( 4, dispatcher.getDriverFromDriverDict(2, "D1").getTripEffort()) self.assertAlmostEqual(5.532, dispatcher.getDriverFromDriverDict( 2, "D1").getTripProfit(), delta=0.01) self.assertEqual( "[R15]", dispatcher.getDriverFromDriverDict(1, "D4").showRidersOnBoard()) self.assertEqual( "[1, 6]", dispatcher.getDriverFromDriverDict(1, "D4").showTripRoute()) self.assertEqual( INSERVICE, dispatcher.getDriverFromDriverDict(1, "D4").getStatus()) self.assertEqual( 3, dispatcher.getDriverFromDriverDict(1, "D4").getTripEffort()) self.assertAlmostEqual(6.9, dispatcher.getDriverFromDriverDict( 1, "D4").getTripProfit(), delta=0.01) self.assertEqual( "[R1, R2, R5, R6]", dispatcher.getDriverFromDriverDict(2, "D2").showRidersOnBoard()) self.assertEqual( "[1, 6, 6, 6, 6]", dispatcher.getDriverFromDriverDict(2, "D2").showTripRoute()) self.assertEqual( INSERVICE, dispatcher.getDriverFromDriverDict(2, "D2").getStatus()) self.assertEqual( 4, dispatcher.getDriverFromDriverDict(2, "D2").getTripEffort()) self.assertAlmostEqual(29.503, dispatcher.getDriverFromDriverDict( 2, "D2").getTripProfit(), delta=0.01) self.assertEqual( "[R8, R9]", dispatcher.getDriverFromDriverDict(1, "D5").showRidersOnBoard()) self.assertEqual( "[1, 6, 7]", dispatcher.getDriverFromDriverDict(1, "D5").showTripRoute()) self.assertEqual( INSERVICE, dispatcher.getDriverFromDriverDict(1, "D5").getStatus()) self.assertEqual( 4, dispatcher.getDriverFromDriverDict(1, "D5").getTripEffort()) self.assertAlmostEqual(15, dispatcher.getDriverFromDriverDict( 1, "D5").getTripProfit(), delta=0.01) self.assertEqual( "[R10, R11, R12]", dispatcher.getDriverFromDriverDict(2, "D3").showRidersOnBoard()) self.assertEqual( "[1, 6, 8, 28]", dispatcher.getDriverFromDriverDict(2, "D3").showTripRoute()) self.assertEqual( INSERVICE, dispatcher.getDriverFromDriverDict(2, "D3").getStatus()) self.assertEqual( 7, dispatcher.getDriverFromDriverDict(2, "D3").getTripEffort()) self.assertAlmostEqual(19.383, dispatcher.getDriverFromDriverDict( 2, "D3").getTripProfit(), delta=0.01) self.assertEqual( "[R3, R4, R7]", dispatcher.getDriverFromDriverDict(77, "D6").showRidersOnBoard()) self.assertEqual( "[1, 4, 6, 8]", dispatcher.getDriverFromDriverDict(77, "D6").showTripRoute()) self.assertEqual( INSERVICE, dispatcher.getDriverFromDriverDict(77, "D6").getStatus()) self.assertEqual( 6, dispatcher.getDriverFromDriverDict(77, "D6").getTripEffort()) self.assertAlmostEqual(20.283, dispatcher.getDriverFromDriverDict( 77, "D6").getTripProfit(), delta=0.01) self.assertEqual(15, dispatcher.countCurrentTotalRiderNumber()) self.assertAlmostEqual(16.1002, dispatcher.calcAverageProfitOfDrivers(), delta=0.01) self.assertAlmostEqual(0, dispatcher.calcAverageIdleTimeOfDrivers(), delta=0.01)
def testCalcTripEffortSuccess(self): d1 = Driver("V0", 23) Driver.timestamp = 20 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, 77, 10, 20, 1, 1, 2, 1) r4 = Rider("R4", 0, 7, 6, 10, 20, 1, 1, 2, 1) riders = {"R1": r1, "R2": r2, "R3": r3, "R4": r4} d1.setRiders(riders) d1.calcTripRoute() d1.calcTripEffort() elem1 = d1.popTripRoute() self.assertEqual(22, elem1.getEventTime()) elem2 = d1.popTripRoute() self.assertEqual(23, elem2.getEventTime()) rider1 = d1.getRider(elem2.getRiderID()) self.assertEqual(23, rider1.getArrivalTimestamp()) self.assertEqual(2, rider1.getDetourTime()) elem3 = d1.popTripRoute() self.assertEqual(24, elem3.getEventTime()) rider2 = d1.getRider(elem3.getRiderID()) self.assertEqual(24, rider2.getArrivalTimestamp()) self.assertEqual(2, rider2.getDetourTime()) elem4 = d1.popTripRoute() self.assertEqual(25, elem4.getEventTime()) rider3 = d1.getRider(elem4.getRiderID()) self.assertEqual(25, rider3.getArrivalTimestamp()) self.assertEqual(2, rider3.getDetourTime()) elem5 = d1.popTripRoute() self.assertEqual(26, elem5.getEventTime()) rider4 = d1.getRider(elem5.getRiderID()) self.assertEqual(26, rider4.getArrivalTimestamp()) self.assertEqual(2, rider4.getDetourTime()) self.assertEqual(6, d1.getTripEffort())
def testSetStatus(self): d1 = Driver("V0", 23) d1.setStatus(INSERVICE) self.assertEqual("inservice", d1.getStatus())
def testTickWaitTime(self): d1 = Driver("V0", 23) d1.tickIdleTime() self.assertEqual(1, d1.getIdleTime())