Esempio n. 1
0
def simulation(numseconds, pagesperminute):
    labprinter = Printer(pagesperminute)
    printerqueue = Queue()
    waitingtimes = []
    longestqueue = 0

    for currentsecond in range(numseconds):

        if newprinttask():
            newtask = Task(currentsecond)
            printerqueue.enqueue(newtask)
            if printerqueue.size() > longestqueue:
                longestqueue = printerqueue.size()

        if not labprinter.busy() and printerqueue.has_items():
            nexttask = printerqueue.dequeue()
            waitingtimes.append(nexttask.waittime(currentsecond))
            labprinter.startnext(nexttask)

        labprinter.tick()

    averagewait = sum(waitingtimes) / len(waitingtimes)
    print "Average Wait %6.2f secs %3d tasks remaining." % (
        averagewait, printerqueue.size())
    print "The longest the queue got to was %d tasks. \n" % (longestqueue)
Esempio n. 2
0
def simulation(numseconds, pagesperminute):
    labprinter = Printer(pagesperminute)
    printerqueue = Queue()
    waitingtimes = []
    longestqueue = 0

    for currentsecond in range(numseconds):

        if newprinttask():
            newtask = Task(currentsecond)
            printerqueue.enqueue(newtask)
            if printerqueue.size() > longestqueue:
                longestqueue = printerqueue.size()

        if not labprinter.busy() and printerqueue.has_items():
            nexttask = printerqueue.dequeue()
            waitingtimes.append(nexttask.waittime(currentsecond))
            labprinter.startnext(nexttask)

        labprinter.tick()

    averagewait = sum(waitingtimes)/len(waitingtimes)
    print "Average Wait %6.2f secs %3d tasks remaining." % (averagewait, printerqueue.size())
    print "The longest the queue got to was %d tasks. \n" % (longestqueue)
 def test_busy(self):
     # Create a printer, give it a task, check if busy
     canon = Printer(12)
     self.assertEqual(canon.busy(), False)
     canon.currenttask = True
     self.assertEqual(canon.busy(), True)
 def test_busy(self):
     # Create a printer, give it a task, check if busy
     canon = Printer(12)
     self.assertEqual(canon.busy(), False)
     canon.currenttask = True
     self.assertEqual(canon.busy(), True)