def test_clear(): myQ = Queue() myQ.enqueue(3) myQ.enqueue(4) myQ.clear() assert myQ.size() == 0 assert myQ.isEmpty() assert myQ.toList() == []
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 ()
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()))
def test_isEmpty(): myQ = Queue() assert myQ.isEmpty()