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())
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)
def test_injectWait(self): events = Events([InjectEvent(1, None), InjectEvent(2, None)]) events.schedule(WaitEvent()) event = events.next() self.assertIsInstance(event, InjectEvent) self.assertEqual(event.time, 1) event = events.next() self.assertIsInstance(event, ErrorEvent) self.assertEqual(event.time, 1) event = events.next() self.assertIsInstance(event, InjectEvent) self.assertEqual(event.time, 2)
def test_withoutSimultaneousEvents(self): ie1, ie2 = InjectEvent(1, None), InjectEvent(2, None) events = Events([ie1, ie2]) nextEvent = events.next() self.assertFalse(events.hasNextNow(nextEvent.time))
def setUp(self): self.ie1, self.ie2, self.ie3 = InjectEvent(1.1, None), InjectEvent( 4.2, None), InjectEvent(5.9, None) self.events = Events([self.ie1, self.ie2, self.ie3])
def fromFile(filename): with open(filename, 'r') as events: return Events(InjectEvent.fromLine(line) for line in events)
def injectPackets(self, *packets): for packet in packets: self.algorithm.notify(InjectEvent(0, packet))