-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinkedlist2test.py
98 lines (71 loc) · 2.72 KB
/
linkedlist2test.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
88
89
90
91
92
93
94
95
96
97
98
import unittest
from linkedEG import LinkedList
class TestLinkedList(unittest.TestCase):
def setUp(self):
self.list = LinkedList()
def tearDown(self):
self.list = None
def test_put(self):
self.list.put("David")
self.assertTrue(self.list.head.get_data() == "David")
self.assertTrue(self.list.head.get_next() is None)
def test_put_two(self):
self.list.put("David")
self.list.put("Thomas")
self.assertTrue(self.list.head.get_data() == "Thomas")
head_next = self.list.head.get_next()
self.assertTrue(head_next.get_data() == "David")
def test_nextNode(self):
self.list.put("Jacob")
self.list.put("Pallymay")
self.list.put("Rasmus")
self.assertTrue(self.list.head.get_data() == "Rasmus")
head_next = self.list.head.get_next()
self.assertTrue(head_next.get_data() == "Pallymay")
last = head_next.get_next()
self.assertTrue(last.get_data() == "Jacob")
def test_positive_get(self):
self.list.put("Jacob")
self.list.put("Pallymay")
self.list.put("Rasmus")
found = self.list.get("Jacob")
self.assertTrue(found.get_data() == "Jacob")
found = self.list.get("Pallymay")
self.assertTrue(found.get_data() == "Pallymay")
found = self.list.get("Jacob")
self.assertTrue(found.get_data() == "Jacob")
def test_getNone(self):
self.list.put("Jacob")
self.list.put("Pallymay")
# make sure reg get works
found = self.list.get("Jacob")
self.assertTrue(found.get_data() == "Jacob")
with self.assertRaises(ValueError):
self.list.get("Vincent")
def test_delete(self):
self.list.put("Jacob")
self.list.put("Pallymay")
self.list.put("Rasmus")
# Delete the list head
self.list.delete("Rasmus")
self.assertTrue(self.list.head.get_data() == "Pallymay")
# Delete the list tail
self.list.delete("Jacob")
self.assertTrue(self.list.head.get_next() is None)
def test_delete_value_not_in_list(self):
self.list.put("Jacob")
self.list.put("Pallymay")
self.list.put("Rasmus")
with self.assertRaises(ValueError):
self.list.delete("Sunny")
def test_delete_empty_list(self):
with self.assertRaises(ValueError):
self.list.delete("Sunny")
def test_delete_next_reassignment(self):
self.list.put("Jacob")
self.list.put("Cid")
self.list.put("Pallymay")
self.list.put("Rasmus")
self.list.delete("Pallymay")
self.list.delete("Cid")
self.assertTrue(self.list.head.next_node.get_data() == "Jacob")