コード例 #1
0
ファイル: test_Events.py プロジェクト: rslawik/mgr-simulation
 def test_canPerformExperiment1(self):
     # t=0
     ie1, ie2 = InjectEvent(0, 3), InjectEvent(0, 5)
     events = Events([ie1, ie2])
     self.assertEqual(events.next(), ie1)
     self.assertEqual(events.next(), ie2)
     se1, se2 = SentEvent(3, "alg"), SentEvent(5, "adv")
     events.schedule(se1)
     events.schedule(se2)
     ee1 = ErrorEvent(5)
     events.schedule(ee1)
     # t=3
     self.assertEqual(events.next(), se1)
     se3 = SentEvent(8, "alg")
     events.schedule(se3)
     ee2 = ErrorEvent(8)
     events.schedule(ee2)
     # t=5
     self.assertEqual(events.next(), se2)
     self.assertEqual(events.next(), ee1)
     se4 = SentEvent(8, "adv")
     events.schedule(se4)
     # t=8
     self.assertEqual(events.next(), se4)
     self.assertEqual(events.next(), ee2)
     self.assertFalse(events.hasNext())
コード例 #2
0
ファイル: test_Events.py プロジェクト: rslawik/mgr-simulation
 def test_SimultaneousSentAndError(self):
     ie1, ie2 = InjectEvent(1, None), InjectEvent(2, None)
     events = Events([ie1, ie2])
     se1 = SentEvent(1.5, None)
     events.schedule(se1)
     se2 = SentEvent(2, None)
     events.schedule(se2)
     ee = ErrorEvent(1.5)
     events.schedule(ee)
     self.assertEqual(events.next(), ie1)
     self.assertEqual(events.next(), se1)
     self.assertEqual(events.next(), ee)
     self.assertEqual(events.next(), ie2)
     self.assertEqual(events.hasNext(), False)
コード例 #3
0
ファイル: Events.py プロジェクト: rslawik/mgr-simulation
 def schedule(self, event):
     if isinstance(event, ErrorEvent):
         Events.scheduleEventInList(self.errorEvents, event)
         self.sentEvents = list(
             takewhile(lambda e: e <= event, self.sentEvents))
     elif isinstance(event, SentEvent):
         if not self.errorEvents or self.errorEvents and event <= self.errorEvents[
                 0]:
             Events.scheduleEventInList(self.sentEvents, event)
     elif isinstance(event, WaitEvent):
         if self.injectEvents:
             errorTime = self.injectEvents[0].time
             if self.sentEvents:
                 errorTime = min(errorTime, self.sentEvents[0].time)
                 self.sentEvents = []
             error = ErrorEvent(errorTime)
             self.schedule(error)
コード例 #4
0
ファイル: test_Events.py プロジェクト: rslawik/mgr-simulation
 def test_canScheduleSentAndErrorEventBefore(self):
     sentEvent, errorEvent = SentEvent(2.9, None), ErrorEvent(2.8)
     self.events.schedule(sentEvent)
     self.events.schedule(errorEvent)
     self.assertHasEventsInOrder([self.ie1, errorEvent, self.ie2, self.ie3])
コード例 #5
0
 def scheduleError(time, error):
     if error:
         events.schedule(
             ErrorEvent(time + error) if error >= 0 else WaitEvent())
コード例 #6
0
 def assertScheduleAndError(self, packet):
     scheduled = self.algorithm.schedule()
     self.assertEqual(scheduled, packet)
     self.algorithm.notify(ErrorEvent(0))