-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_stack.py
More file actions
57 lines (36 loc) · 1.26 KB
/
test_stack.py
File metadata and controls
57 lines (36 loc) · 1.26 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
from __future__ import unicode_literals
import pytest
from stack import Stack
@pytest.fixture
def base_stack():
return Stack([1, 2, 3])
def test_construct_from_iterable_valid(base_stack):
expected_output = "(1, 2, 3)"
assert base_stack.__repr__() == expected_output
def test_construct_from_nested_iterable_valid():
arg = ([1, 2, 3], 'string')
expected_output = "([1, 2, 3], u'string')"
assert Stack(arg).__repr__() == expected_output
def test_construct_from_string_valid():
arg = "string"
expected_output = "(u's', u't', u'r', u'i', u'n', u'g')"
assert Stack(arg).__repr__() == expected_output
def test_construct_empty_valid():
expected_output = "()"
assert Stack().__repr__() == expected_output
def test_construct_from_none_fails():
with pytest.raises(TypeError):
Stack(None)
def test_construct_from_single_integer_fails():
with pytest.raises(TypeError):
Stack(2)
def test_push(base_stack):
base_stack.push(4)
assert base_stack.__repr__() == "(4, 1, 2, 3)"
def test_pop(base_stack):
assert base_stack.pop() == 1
assert base_stack.__repr__() == "(2, 3)"
def test_pop_after_multi_push(base_stack):
for x in range(10):
base_stack.push(x)
assert base_stack.pop() == 9