def test_Empty_And_Size(self): expectedSize = 3 testQueue = Queue() testQueue.Enqueue(1) testQueue.Enqueue(2) testQueue.Enqueue(3) testSize = testQueue.Size() self.assertEqual(testSize, expectedSize) isEmpty = testQueue.IsEmpty() self.assertEqual(isEmpty, False) testQueue.Dequeue() testQueue.Dequeue() testQueue.Dequeue() isEmpty = testQueue.IsEmpty() self.assertEqual(isEmpty, True)
class ConvertToBinaryWithQueue(): def __init__(self, value): self.value = value self.queue = Queue() def ToBinary(self): highest_power_of_two = 1 while highest_power_of_two * 2 < self.value: highest_power_of_two *= 2 while highest_power_of_two >= 1: if self.value // highest_power_of_two == 0: self.queue.enqueue("0") else: self.queue.enqueue("1") self.value %= highest_power_of_two highest_power_of_two /= 2 binary = "" while not self.queue.IsEmpty(): binary += self.queue.dequeue() return binary