-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_d_linked_list.py
87 lines (62 loc) · 1.66 KB
/
test_d_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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# This file is for testing the Double Linked List
from d_linked_list import DLinked
import pytest
def test_insert_one():
linked = DLinked()
linked.insert("Bob")
assert linked.first.val == "Bob"
def test_insert_multi():
linked = DLinked()
linked.insert("Fred")
linked.insert("Bob")
linked.insert("Joe")
assert linked.first.val == "Joe"
def test_append_one():
linked = DLinked()
linked.append("Bob")
assert linked.last.val == "Bob"
def test_append_multi():
linked = DLinked()
linked.append("Fred")
linked.append("Bob")
linked.append("Joe")
assert linked.last.val == "Joe"
def test_pop_one():
linked = DLinked()
linked.insert("Bob")
assert linked.pop() == "Bob"
def test_pop_empty():
linked = DLinked()
with pytest.raises(ValueError):
linked.pop()
def test_shift_one():
linked = DLinked()
linked.insert("Bob")
assert linked.shift() == "Bob"
def test_shift_empty():
linked = DLinked()
with pytest.raises(ValueError):
linked.shift()
def test_remove_empty():
linked = DLinked()
with pytest.raises(AttributeError):
linked.remove("Bob")
def test_remove_one():
linked = DLinked()
linked.insert("Bob")
linked.remove("Bob")
with pytest.raises(AttributeError):
linked.remove("Bob")
def test_remove_wrong():
linked = DLinked()
linked.insert("Fred")
linked.insert("Bob")
linked.insert("Joe")
with pytest.raises(ValueError):
linked.remove("Sue")
def test_multi():
linked = DLinked()
linked.insert("Fred")
linked.insert("Bob")
linked.insert("Joe")
assert linked.first.val == "Joe"