-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_stack.py
More file actions
52 lines (31 loc) · 985 Bytes
/
test_stack.py
File metadata and controls
52 lines (31 loc) · 985 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# -*- coding: utf-8 -*-
import pytest
from stack import Stack
def test_constructor():
test_stack = Stack()
assert test_stack.top is None
def test_push_accepts_item():
test_stack = Stack()
test_stack.push((1, 2, 3))
assert test_stack.top.data == (1, 2, 3)
def test_push_places_item_on_top():
test_stack = Stack()
test_stack.push("test")
test_stack.push(42)
assert test_stack.top.data == 42
def test_push_empty():
test_stack = Stack()
with pytest.raises(TypeError) as excinfo:
test_stack.push()
assert 'push() takes exactly 2 arguments (1 given)' in str(excinfo.value)
def test_pop():
test_stack = Stack()
test_stack.push("test")
test_stack.push(42)
assert test_stack.pop() == 42
assert test_stack.top.data == "test"
def test_pop_empty():
test_stack = Stack()
with pytest.raises(ValueError) as excinfo:
test_stack.pop()
assert 'The stack is empty' in str(excinfo.value)