예제 #1
0
def test_pop():
    letters = Stack()
    letters.push('A')
    letters.push('B')
    letters.push('C')
    assert letters.pop() == 'C'
예제 #2
0
def test_push_onto_empty():
    s = Stack()
    s.push("apple")
    actual = s.top.value
    expected = "apple"
    assert actual == expected
def test_stack_push():
    s = Stack()
    s.push('hello world')
    assert s.top.value == 'hello world'
예제 #4
0
def test_stacks_and_queues_1 ():
    stack = Stack()
    stack.push('a')
    actual = stack.top.value
    expected = 'a'
    assert actual == expected
예제 #5
0
def test_stacks_and_queues_7 ():
    stack = Stack()
    actual = stack.pop()
    expected = None
    assert actual == expected
def test_instantiate_empty_stack():
    stack = Stack()
    actual = stack.isEmpty()
    assert actual
def test_pop_or_peek_empty_stack():
    stack = Stack()
    with pytest.raises(EmptyStackException):
        stack.peek()
    with pytest.raises(EmptyStackException):
        stack.pop()
def test_stack_top():
    stack1 = Stack()
    assert stack1.top == None
def test_stack_str():
    stack9 = Stack()
    stack9.push(5)
    assert str(stack9) == "[5]"
def test_stack_peek():
    stack5 = Stack()
    stack5.push(5)
    assert stack5.peek() == 5
    assert stack5.top.val == 5
def test_stack_is_empty():
    stack6 = Stack()
    assert stack6.is_empty() == True
    stack6.push(5)
    assert stack6.is_empty() == False
def test_stack_pop_exception():
    stack4 = Stack()
    with pytest.raises(Exception) as excep:
        stack4.pop()
        assert "EmptyStack" in excep
def test_stack_pop():
    stack3 = Stack()
    stack3.push(0)
    assert stack3.pop() == 0
    assert stack3.top == None
def test_stack_push():
    stack2 = Stack()
    stack2.push(0)
    assert stack2.top.val == 0
예제 #15
0
def test_peek_on_empty_raises_exception():
    new_stack = Stack()
    expected = 'Exception'
    actual = new_stack.peek()
    assert expected == actual
예제 #16
0
 def test_instantiation_empty(self):
     assert Stack()
def test_pop_empty():
    s = Stack()
    with pytest.raises(InvalidOperationError) as e:
        s.pop()

    assert str(e.value) == "Method not allowed on empty collection"
예제 #18
0
 def stack(self):
     return Stack()
def test_stack_push():
    expected = "pass"
    stack = Stack()
    stack.push("pass")
    actual = f"{stack}"
    assert actual == expected
from stacks_and_queues.stacks_and_queues import Stack

class PseudoQueue():
  def __init__(self):
    self.stack1 = Stack()
    self.stack2 = Stack()

  def enqueue(self, value):
    self.stack1.push(value)

  def dequeue(self):
    while self.stack1.peek():
      if self.stack1.top.next == None:
        return self.stack1.top.value
      
      else:
        temp = self.stack1.pop()
        self.stack2.push(temp)
        continue

if __name__ == "__main__":
    new_stack = Stack()
    new_stack.push("10")
    new_stack.push("15")
    new_stack.push("20")
    # new_stack.pop()
    # new_stack.pop()
    print(new_stack)
예제 #21
0
 def __init__(self):
     self.input_stack = Stack()
     self.output = Stack()
 def __init__(self):
   self.stack1 = Stack()
   self.stack2 = Stack()
예제 #23
0
def test_stacks_and_queues_6 ():
    stack = Stack()
    actual = stack.top
    expected = None
    assert actual == expected
 def __init__(self):
     self.front_stack = Stack()
     self.rear_stack = Stack()
     self.front = self.rear = None
예제 #25
0
def test_pop_single():
    s = Stack()
    s.push("apple")
    actual = s.pop()
    expected = "apple"
    assert actual == expected
예제 #26
0
def test_can_successfully_instantiate_an_empty_stack():
    new_stack = Stack()
    expected = None
    actual = new_stack.top
    assert expected == actual
예제 #27
0
def test_pop_empty():
    s = Stack()
    with pytest.raises(InvalidOperationError) as e:
        s.pop()

    assert str(e.value) == "Not allowed on empty structure"
예제 #28
0
def test_can_successfully_push_to_a_stack():
    new_stack = Stack()
    new_stack.push('blue')
    expected = 'blue'
    actual = new_stack.peek()
    assert expected == actual
def test_stack_push_many():
    s = Stack()
    s.push('hello world')
    s.push('multiple values woah')
    assert s.top.value == 'multiple values woah'
예제 #30
0
def test_push_many():
    letters = Stack()
    letters.push('A')
    letters.push('B')
    letters.push('C')
    assert print_all(letters) == 'C; B; A; '