def test_pop(): nums = Stack() nums.push(1) nums.push(2) nums.push(3) expected = nums.pop() assert expected == 3
def test_pop_empty(): stack = Stack() stack.push(7) stack.push(3) stack.pop() stack.pop() assert stack.isEmpty() == True
class PseudoQueue: def __init__(self): self.in_stack = Stack() self.out_stack = Stack() self.count = 0 def enqueue(self, value): self.count += 1 self.in_stack.push(value) def dequeue(self): if self.out_stack.is_empty: while self.count > 0: self.out_stack.push(self.in_stack.pop()) self.count -= 1 poped = self.out_stack.pop() return poped # I used this method to see the data and compare the output def __str__(self): output = '' cur = self.in_stack.top while cur: output += f' -> {{ {cur.value} }}' cur = cur.next return output
def test_empty_S(): nums = Stack() nums.push(1) nums.push(2) nums.push(3) nums.pop() nums.pop() nums.pop() expected = True assert expected == nums.is_empty()
class PseudoQueue: def __init__(self): self.inStack = Stack() self.outStack = Stack() def enqueue(self, value): self.inStack.push(value) def dequeue(self): if (self.inStack.top == None and self.outStack.top == None): raise AttributeError("Queue is empty.") if (self.outStack.top == None): while (self.inStack.top): self.outStack.push(self.inStack.pop()) return self.outStack.pop()
def test_pop(): stack = Stack() stack.push(7) stack.push(3) stack.pop() assert stack.top.value == 7
def test_push_multiple(): stack = Stack() stack.push(7) stack.push(3) assert stack.top.value == 3
def test_push_one(): stack = Stack() stack.push(7) assert stack.top.value == 7
def test_stack_peek(): stack = Stack() stack.push(7) stack.push(3) assert stack.peek() == 3
def test_push(): nums = Stack() nums.push(1) expected = nums.top.value assert expected == 1
def test_peek_S(): nums = Stack() nums.push(1) nums.push(2) expected = 2 assert expected == nums.peek()
def test_push_muliple(): nums = Stack() nums.push(5,6,10) expected = nums.top.value assert expected == 10