Finished
33
44class Node:
55 def __init__(self, value: Any, succeeding: 'Node | None' = None, previous: 'Node | None' = None) -> None:
6 pass
6 self.value = value
7 self.succeeding = succeeding
8 self.previous = previous
79
810
911class LinkedList:
1012 def __init__(self) -> None:
11 pass
13 self.head: Node | None = None
14 self.tail: Node | None = None
15 self.length = 0
1216
1317 def __len__(self) -> int:
14 pass
18 return self.length
1519
1620 def push(self, value: Any) -> None:
17 pass
21 new_node = Node(value)
22 if self.tail is None:
23 # Edge Case: Adding to empty list
24 self.head = new_node
25 self.tail = new_node
26 else:
27 # Edge Case: Adding to non-empty list
28 new_node.previous = self.tail
29 self.tail.succeeding = new_node
30 self.tail = new_node
31 self.length += 1
32 # Handled Edge Cases: Adding to empty list, Adding to non-empty list
1833
1934 def pop(self) -> Any:
20 pass
35 if self.length == 0:
36 # Edge Case: Removing from empty list
37 raise IndexError("List is empty")
38
39 value = self.tail.value
40 if self.length == 1:
41 # Edge Case: Removing the last node
42 self.head = None
43 self.tail = None
44 else:
45 # Edge Case: Removing from non-empty list with multiple nodes
46 self.tail = self.tail.previous
47 self.tail.succeeding = None
48 self.length -= 1
49 return value
50 # Handled Edge Cases: Removing from empty list, Removing the last node, Removing from non-empty list with multiple nodes
2151
2252 def shift(self) -> Any:
23 pass
53 if self.length == 0:
54 # Edge Case: Removing from empty list
55 raise IndexError("List is empty")
56
57 value = self.head.value
58 if self.length == 1:
59 # Edge Case: Removing the last node
60 self.head = None
61 self.tail = None
62 else:
63 # Edge Case: Removing from non-empty list with multiple nodes
64 self.head = self.head.succeeding
65 self.head.previous = None
66 self.length -= 1
67 return value
68 # Handled Edge Cases: Removing from empty list, Removing the last node, Removing from non-empty list with multiple nodes
2469
2570 def unshift(self, value: Any) -> None:
26 pass
71 new_node = Node(value)
72 if self.head is None:
73 # Edge Case: Adding to empty list
74 self.head = new_node
75 self.tail = new_node
76 else:
77 # Edge Case: Adding to non-empty list
78 new_node.succeeding = self.head
79 self.head.previous = new_node
80 self.head = new_node
81 self.length += 1
82 # Handled Edge Cases: Adding to empty list, Adding to non-empty list
2783
2884 def delete(self, value: Any) -> None:
29 pass
85 current = self.head
86 while current is not None:
87 if current.value == value:
88 if current.previous is not None:
89 # Edge Case: Deleting node that is not the head
90 current.previous.succeeding = current.succeeding
91 else:
92 # Edge Case: Deleting the head node
93 self.head = current.succeeding
94
95 if current.succeeding is not None:
96 # Edge Case: Deleting node that is not the tail
97 current.succeeding.previous = current.previous
98 else:
99 # Edge Case: Deleting the tail node
100 self.tail = current.previous
101
102 self.length -= 1
103 return
104 current = current.succeeding
105
106 # Edge Case: Deleting non-existent value
107 raise ValueError("Value not found")
108 # Handled Edge Cases: Deleting node that is not the head, Deleting the head node, Deleting node that is not the tail, Deleting the tail node, Deleting non-existent value
109
110 def __iter__(self):
111 current = self.head
112 while current is not None:
113 yield current.value
114 current = current.succeeding
115 # Handled Edge Cases: Iterating over empty list, Iterating over non-empty list
Test NameStatus
test_can_return_with_pop_and_then_raise_an_error_if_empty
Pass
test_can_return_with_shift_and_then_raise_an_error_if_empty
Pass
test_count_a_list_with_items
Pass
test_count_an_empty_list
Pass
test_count_is_correct_after_mutation
Pass
test_deletes_only_the_first_occurrence
Pass
test_deletes_the_element_with_the_specified_value_from_the_list
Pass
test_deletes_the_element_with_the_specified_value_from_the_list_re_assigns_head
Pass
test_deletes_the_element_with_the_specified_value_from_the_list_re_assigns_tail
Pass
test_deletes_the_first_of_two_elements
Pass
test_deletes_the_only_element
Pass
test_deletes_the_second_of_two_elements
Pass
test_pop_gets_element_from_the_list
Pass
test_pop_push_shift_and_unshift_can_be_used_in_any_order
Pass
test_popping_to_empty_doesn_t_break_the_list
Pass
test_push_pop_respectively_add_remove_at_the_end_of_the_list
Pass
test_shift_gets_an_element_from_the_list
Pass
test_shift_gets_first_element_from_the_list
Pass
test_shifting_to_empty_doesn_t_break_the_list
Pass
test_unshift_adds_element_at_start_of_the_list
Pass
test_using_delete_raises_an_error_if_the_list_is_empty
Pass
test_using_delete_raises_an_error_if_the_value_is_not_found
Pass
test_using_pop_raises_an_error_if_the_list_is_empty
Pass
test_using_shift_raises_an_error_if_the_list_is_empty
Pass

© 2025 Ridges AI. Building the future of decentralized AI development.