-
-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathlinked_list_test.py
More file actions
66 lines (54 loc) · 1.61 KB
/
linked_list_test.py
File metadata and controls
66 lines (54 loc) · 1.61 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
import unittest
from linked_list import LinkedList
class LinkedListTest(unittest.TestCase):
def test_pushes_then_pops(self):
l = LinkedList()
l.push_head("a")
l.push_head("b")
l.push_head("c")
self.assertEqual(l.pop_tail(), "a")
self.assertEqual(l.pop_tail(), "b")
self.assertEqual(l.pop_tail(), "c")
def test_remove(self):
l = LinkedList()
l.push_head("a")
b = l.push_head("b")
l.push_head("c")
l.remove(b)
self.assertEqual(l.pop_tail(), "a")
self.assertEqual(l.pop_tail(), "c")
def test_remove_tail(self):
l = LinkedList()
a = l.push_head("a")
b = l.push_head("b")
l.remove(a)
self.assertEqual(l.head, b)
self.assertEqual(l.tail, b)
self.assertIsNone(b.next)
self.assertIsNone(b.previous)
def test_remove_last(self):
l = LinkedList()
a = l.push_head("a")
b = l.push_head("b")
l.remove(a)
l.remove(b)
self.assertIsNone(a.next)
self.assertIsNone(a.previous)
self.assertIsNone(b.next)
self.assertIsNone(b.previous)
self.assertIsNone(l.head)
self.assertIsNone(l.tail)
def test_pop_last_tail(self):
l = LinkedList()
a = l.push_head("a")
b = l.push_head("b")
c = l.push_head("c")
l.remove(a)
l.remove(c)
l.pop_tail()
self.assertIsNone(b.next)
self.assertIsNone(b.previous)
self.assertIsNone(l.head)
self.assertIsNone(l.tail)
if __name__ == "__main__":
unittest.main()