forked from clair3st/Data-Structures
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_stack.py
More file actions
54 lines (37 loc) · 1.28 KB
/
test_stack.py
File metadata and controls
54 lines (37 loc) · 1.28 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
"""Test for Stack implementation."""
import pytest
@pytest.fixture
def test_stack():
"""Fixture for testing."""
from src.stack import Stack
empty = Stack()
one = Stack(5)
multi = Stack([1, 2, 'three', 4, 5])
return empty, one, multi
def test_stack_is_initialized(test_stack):
"""Test stack."""
assert test_stack[0]._stack._length is 0
def test_empty_stack_push(test_stack):
"""Test can push on an empty stack."""
test_stack[0].push(3)
assert test_stack[0]._stack._length is 1
def test_stack_of_one_push(test_stack):
"""Test can push on an stack of 1."""
test_stack[1].push(2)
assert test_stack[1]._stack.head.data is 2
def test_stack_of_multiple_push(test_stack):
"""Test can push on an stack of multiple."""
test_stack[2].push(2)
assert test_stack[2]._stack.head.data is 2
def test_empty_stack_pop(test_stack):
"""Test can pop on an empty stack."""
with pytest.raises(IndexError):
test_stack[0].pop()
def test_stack_of_one_pop(test_stack):
"""Test can pop on an stack of 1."""
test_stack[1].pop()
assert test_stack[1]._stack.head is None
def test_stack_of_multiple_pop(test_stack):
"""Test can pop on an stack of multiple."""
test_stack[2].pop()
assert test_stack[2]._stack.head.data is 4