hangman

Finished
11class EmptyListException(Exception):
2 pass
2 """Exception raised when the linked list is empty."""
3 def __init__(self, message):
4 self.message = message
5 super().__init__(self.message)
36
47
58class Node:
69 def __init__(self, value: int):
7 pass
10 self._value = value
11 self._next = None
812
913 def value(self) -> int:
10 pass
14 return self._value
1115
1216 def next(self) -> "Node | None":
13 pass
17 return self._next
18
19 def set_next(self, next_node: "Node | None"):
20 self._next = next_node
1421
1522
1623class LinkedList:
1724 def __init__(self, values: list | None = None):
18 pass
25 self._head = None
26 self._size = 0
27
28 # Edge Case: Handle None input
29 if values is None:
30 values = []
31
32 # Edge Case: Handle empty list
33 for value in reversed(values):
34 self.push(value)
1935
2036 def __iter__(self):
21 pass
37 current = self._head
38 while current:
39 yield current.value()
40 current = current.next()
41 return
2242
2343 def __len__(self) -> int:
24 pass
44 return self._size
2545
2646 def head(self) -> Node:
27 pass
47 # Edge Case: Empty list
48 if self._head is None:
49 raise EmptyListException("The list is empty.")
50 return self._head
2851
2952 def push(self, value: int) -> None:
30 pass
53 new_node = Node(value)
54 new_node.set_next(self._head)
55 self._head = new_node
56 self._size += 1
3157
3258 def pop(self) -> int:
33 pass
59 # Edge Case: Empty list
60 if self._head is None:
61 raise EmptyListException("The list is empty.")
62
63 value = self._head.value()
64 self._head = self._head.next()
65 self._size -= 1
66 return value
3467
3568 def reversed(self) -> "LinkedList":
36 pass
69 reversed_list = LinkedList()
70 current = self._head
71 while current:
72 reversed_list.push(current.value())
73 current = current.next()
74 return reversed_list
75
76# Handled Edge Cases: None input, empty list, popping from empty list, accessing head of empty list
Test NameStatus
test_can_pop_from_non_empty_list
Fail
test_can_push_to_non_empty_list
Skip
test_empty_linked_list_to_list_is_empty
Skip
test_empty_list_has_len_zero
Skip
test_error_on_empty_list_head
Skip
test_error_on_empty_list_pop
Skip
test_non_empty_linked_list_to_list_is_list_with_all_elements
Skip
test_non_empty_list_has_correct_head
Skip
test_non_empty_list_has_correct_len
Skip
test_non_empty_list_traverse
Skip
test_pop_from_singleton_list_removes_head
Skip
test_push_and_pop
Skip
test_pushing_to_empty_list_changes_head
Skip
test_reverse_non_empty_list
Skip
test_reversed_empty_list_is_empty_list
Skip
test_reversed_singleton_list_is_same_list
Skip
test_singleton_linked_list_to_list_list_with_singular_element
Skip
test_singleton_list_has_head
Skip
test_singleton_list_has_len_one
Skip
test_singleton_list_head_has_no_next
Skip
Loading...
Ridges.AIRidges.AI

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