forked from tlake/data-structures
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_linked_list.py
71 lines (46 loc) · 1.49 KB
/
test_linked_list.py
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
#!/usr/bin/env python
from __future__ import unicode_literals
import pytest
from linked_list import LinkedList, Node
@pytest.fixture()
def create_linked_list():
return LinkedList([1, 2, 3])
@pytest.fixture()
def create_empty_list():
return LinkedList()
@pytest.fixture()
def create_unpointed_node():
return Node(1)
def test_linked_list(create_linked_list):
assert create_linked_list.head.val == 3
def test_insert(create_linked_list):
l1 = create_linked_list
l1.insert(4)
assert l1.head.val == 4
def test_pop(create_linked_list):
pop1 = create_linked_list
pop1.pop()
assert pop1.head.val == 2
def test_size(create_linked_list):
size1 = create_linked_list
assert size1.size() == 3
size1.pop()
assert size1.size() == 2
def test_search(create_linked_list):
search1 = create_linked_list
assert search1.search(3).val == 3
def test_remove_head(create_linked_list):
l_list = create_linked_list
second_head = l_list.head.next
l_list.remove(l_list.head)
assert l_list.head == second_head
def test_remove_on_empty_error(create_empty_list, create_unpointed_node):
with pytest.raises(LookupError):
empty_list = create_empty_list
empty_list.remove(create_unpointed_node)
def test_display(create_linked_list):
display1 = create_linked_list.display()
assert display1 == '(3, 2, 1)'
def test_repr_is_display(create_linked_list):
a_list = create_linked_list
assert a_list.display() == repr(a_list)