예제 #1
0
def test_clear():
    myQ = Queue()
    myQ.enqueue(3)
    myQ.enqueue(4)
    myQ.clear()
    assert myQ.size() == 0
    assert myQ.isEmpty()
    assert myQ.toList() == []
예제 #2
0
 def levelorder(self):
     myq = Queue()
     myq.enqueue(self)
     while not myq.isEmpty():
         cur = myq.dequeue()
         yield cur.data
         myq.enqueue(cur.left) if cur.left else ()
         myq.enqueue(cur.right) if cur.right else ()
예제 #3
0
def simulation(timeInsec, ppm):

    printer = Printer(ppm)
    printQueue = Queue()
    waitingTImes = []

    for second in range(timeInsec):
        if newPrintTask():
            task = Task(second)
            printQueue.enqueue(task)

        if (not printer.busy()) and (not printQueue.isEmpty()):
            nexttask = printQueue.dequeue()
            waitingTImes.append(nexttask.waitTime(second))
            printer.startNext(nexttask)

        printer.tick()
    averageWait = sum(waitingTImes) / len(waitingTImes)
    print("Average Wait %6.2f secs %3d tasks remaining." %
          (averageWait, printQueue.size()))
예제 #4
0
def test_isEmpty():
    myQ = Queue()
    assert myQ.isEmpty()