forked from Firkraag/algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinked_list_test.py
More file actions
54 lines (53 loc) · 1.39 KB
/
Copy pathlinked_list_test.py
File metadata and controls
54 lines (53 loc) · 1.39 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
import unittest
from linked_list import linked_list, linked_list_node
class TestLinkedList(unittest.TestCase):
def test_insert(self):
L = linked_list()
a = linked_list_node(1)
b = linked_list_node(4)
c = linked_list_node(16)
d = linked_list_node(9)
e = linked_list_node(25)
L.insert(a)
L.insert(b)
L.insert(c)
L.insert(d)
L.insert(e)
l = []
x = L.head
while x != None:
l.append(x)
x = x.next
self.assertEquals(l, [e, d, c, b, a])
def test_search(self):
L = linked_list()
a = linked_list_node(1)
b = linked_list_node(4)
c = linked_list_node(16)
d = linked_list_node(9)
e = linked_list_node(25)
L.insert(a)
L.insert(b)
L.insert(c)
L.insert(d)
L.insert(e)
self.assertEquals(L.search(4), b)
def test_delete(self):
L = linked_list()
a = linked_list_node(1)
b = linked_list_node(4)
c = linked_list_node(16)
d = linked_list_node(9)
e = linked_list_node(25)
L.insert(a)
L.insert(b)
L.insert(c)
L.insert(d)
L.insert(e)
L.delete(b)
l = []
x = L.head
while x != None:
l.append(x)
x = x.next
self.assertEquals(l, [e, d, c, a])