예제 #1
0
 def test_stack_push_pop_with_elements(self):
     stack = Stack()
     stack.push(1)
     stack.push(2)
     stack.push(5)
     assert stack.pop() == 5
     assert stack.pop() == 2
     assert stack.pop() == 1
예제 #2
0
def test_pop_decreases_the_stack_size():
    stack = Stack()
    stack.push(42)
    previous_size = stack.size

    stack.pop()

    assert stack.size == (previous_size - 1)
    def test_is_empty(self):
        stack = Stack()
        assert stack.is_empty() is True

        stack.push(1)
        assert stack.is_empty() is False

        stack.pop()
        assert stack.is_empty() is True
    def test_size(self):
        stack = Stack()
        assert len(stack) == 0

        stack.push(1)
        assert len(stack) == 1

        stack.pop()
        assert len(stack) == 0
    def test_pop_items_with_initial_stack(self):
        tests = [1, '0', Stack, lambda x: x, {}, [], None]

        stack = Stack(tests)

        assert len(stack) == len(tests)

        for _ in tests:
            stack.pop()

        assert stack.is_empty() is True
    def test_pop_items(self):
        stack = Stack()

        with self.assertRaises(StackPopException):
            stack.pop()

        one = 1
        two = 2

        stack.push(one)
        stack.push(two)

        assert len(stack) == 2

        assert stack.pop() == two
        assert stack.pop() == one

        assert len(stack) == 0
예제 #7
0
def test_pop_on_empty_stack_returns_none():
    stack = Stack()

    assert stack.pop() == None
예제 #8
0
def test_pop_returns_the_latest_element_pushed():
    stack = Stack()
    stack.push("First")
    stack.push(42)

    assert stack.pop() == 42