def test_dequeue(self): queue = CircularQueue(6) for i in range(0, 5): queue.enqueue(i * 5) assert queue.data == [0, 5, 10, 15, 20, None] assert queue.size == 5 assert queue.capacity == 6 assert queue.head == 0 assert queue.tail == 5
def test_accessors(self): queue = CircularQueue() # manually set queue variables to test accessors queue.data = [5, 10, 15, None] queue.head = 0 queue.tail = 3 queue.size = 3 assert queue.is_empty() == False assert len(queue) == 3 assert queue.head_element() == 5
def test_shrink(self): queue = CircularQueue(8) queue.data = [0, 1, 2, 3, None, None, None, None] queue.size = 4 queue.head = 0 queue.tail = 4 print(queue.head) print(queue.tail) print() queue.dequeue() print(queue.head) print(queue.tail) print(queue) print() queue.dequeue() print(queue.head) print(queue.tail) print(queue.data) #queue.shrink() print() print(queue.data) print(queue.tail) #queue.shrink() # print(queue.capacity) assert queue.data == [2, 3, None, None] assert queue.size == 2 assert queue.capacity == 4 assert queue.head == 0 assert queue.tail == 2
def test_grow(self): queue = CircularQueue(5) queue.data = [0, 1, 2, 3, 4] #ueue.enqueue(5) queue.head = 0 queue.tail = 0 queue.size = 5 queue.grow() #print(queue.tail_element()) assert queue.data == [0, 1, 2, 3, 4, None, None, None, None, None] queue.head == 0 queue.tail == 0 queue.size == 5 queue.capacity == 10
def test_enqueue(self): queue = CircularQueue() queue.enqueue(10) queue.enqueue(20) queue.enqueue(30) assert queue.data == [10, 20, 30, None] assert queue.size == 3 assert queue.head == 0 assert queue.tail == 3 assert queue.capacity == 4
def __init__(self): self._queue = CircularQueue(5)
class App: def __init__(self): self._queue = CircularQueue(5) def run(self): print("------------------------------") print() self._queue.enqueue(25) self._queue.to_string() print() self._queue.enqueue(2) self._queue.to_string() print() self._queue.enqueue(35) self._queue.to_string() print() self._queue.dequeue() self._queue.to_string() print() self._queue.enqueue(8) self._queue.to_string() print() self._queue.dequeue() self._queue.to_string() print() self._queue.dequeue() self._queue.to_string() print() self._queue.dequeue() self._queue.to_string() print() self._queue.enqueue(12) self._queue.to_string() print() self._queue.enqueue(3) self._queue.to_string() # test print() self._queue.enqueue(7) self._queue.to_string() print() print("------------------------------") print("Result : ") self._queue.to_string() print() print("Remaining Item :", self._queue.count()) print() print("------------------------------") input("Press any key to exit....")
def test_q(self): queue = CircularQueue() queue.enqueue(10) queue.enqueue(20) queue.enqueue(30) print(queue.head_element()) print(queue.tail_element()) queue.dequeue() print() print(queue.data[0]) print(queue.data[1]) print(queue.data[2]) print(queue.data[3]) queue.dequeue() # queue.enqueue(60) print() print(queue.head_element()) print(queue.tail_element()) # queue.grow() #print(queue.head_element()) #print(queue.tail_element()) # queue.dequeue() # queue.dequeue() print(queue.capacity)
def __init__(self, size, priority_size): self._size = size self._priority_size = priority_size self._queue = [ CircularQueue(size) ] for i in range(priority_size - 1): self._queue.append(CircularQueue(size))