-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_stack.py
More file actions
94 lines (70 loc) · 1.74 KB
/
Copy pathtest_stack.py
File metadata and controls
94 lines (70 loc) · 1.74 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import pytest
from data_structures.stack import Stack
from data_structures.invalid_operation_error import InvalidOperationError
def test_exists():
assert Stack
# @pytest.mark.skip("TODO")
def test_push_onto_empty():
s = Stack()
s.push("apple")
actual = s.top.value
expected = "apple"
assert actual == expected
# @pytest.mark.skip("TODO")
def test_push_onto_full():
s = Stack()
s.push("apple")
s.push("banana")
s.push("cucumber")
actual = s.top.value
expected = "cucumber"
assert actual == expected
# @pytest.mark.skip("TODO")
def test_pop_single():
s = Stack()
s.push("apple")
actual = s.pop()
expected = "apple"
assert actual == expected
# @pytest.mark.skip("TODO")
def test_pop_some():
s = Stack()
s.push("apple")
s.push("banana")
s.push("cucumber")
s.pop()
actual = s.pop()
expected = "banana"
assert actual == expected
# @pytest.mark.skip("TODO")
def test_pop_until_empty():
s = Stack()
s.push("apple")
s.push("banana")
s.push("cucumber")
s.pop()
s.pop()
s.pop()
actual = s.is_empty()
expected = True
assert actual == expected
# @pytest.mark.skip("TODO")
def test_peek():
s = Stack()
s.push("apple")
s.push("banana")
actual = s.peek()
expected = "banana"
assert actual == expected
# @pytest.mark.skip("TODO")
def test_peek_empty():
s = Stack()
with pytest.raises(InvalidOperationError) as e:
s.peek()
assert str(e.value) == "Method not allowed on empty collection"
# @pytest.mark.skip("TODO")
def test_pop_empty():
s = Stack()
with pytest.raises(InvalidOperationError) as e:
s.pop()
assert str(e.value) == "Method not allowed on empty collection"