def test_length(self): self.linked_list.insert(Node(2)) self.linked_list.insert(Node(3)) self.linked_list.insert(Node(4)) self.linked_list.insert(Node(5)) self.linked_list.insert(Node(6)) assert_that(6).is_equal_to(len(self.linked_list))
def test_iteration(self): self.linked_list.insert(Node(2)) self.linked_list.insert(Node(3)) self.linked_list.insert(Node(4)) numbers = [1, 2, 3, 4] for val, num in zip(self.linked_list, numbers): assert_that(val).is_equal_to(num)
def add(self, value): hash = value.__hash__() index = hash % self._max_len linked_list = self._array[index] if linked_list.head is None: linked_list.head = Node(value) else: tmp = linked_list.head linked_list.head = Node(value) linked_list.head.nxt = tmp
def _get_multiple_intersected_lists(self): common_node = Node(1000) nodes_a = [Node(1), Node(2), Node(3), Node(4), common_node, Node(6)] nodes_b = [Node(7), Node(8), common_node, Node(9)] list_a = create_linked_list_with_list_of_nodes(nodes_a) list_b = create_linked_list_with_list_of_nodes(nodes_b) return [list_a, list_b]
def create_linked_list_with_list_of_values(values): linked_list = LinkedList(Node(values[0])) # head for value in values[1:]: linked_list.insert(Node(value)) return linked_list
def setUp(self): head = Node(1) self.linked_list = LinkedList(head)
def test_get_nth_node(self): nth = 3 self.linked_list.insert(Node(2)) self.linked_list.insert(Node(3)) self.linked_list.insert(Node(4)) assert_that(nth).is_equal_to(self.linked_list.get_nth_node(nth).value)
def test_remove_non_existing(self): self.linked_list.insert(Node(5)) self.linked_list.insert(Node(6)) with self.assertRaises(ValueError): self.linked_list.remove(100)
def test_remove(self): self.linked_list.insert(Node(5)) self.linked_list.insert(Node(6)) result = self.linked_list.remove(5) assert_that(result).is_true()
def test_find(self): self.linked_list.insert(Node(3)) self.linked_list.insert(Node(4)) result = self.linked_list.find(3) expected = Node(3) assert_that(expected.value).is_equal_to(result.value)
def test_insert(self): new_node = Node(2) self.linked_list.insert(new_node) expected = 2 result = self.linked_list.get_last_node().value assert_that(expected).is_equal_to(result)
def setUp(self): self.stack = StackWLinkedList(Node(1))
def test_overflow(self): stack_w_limit = StackWLinkedList(Node(1), 1) with self.assertRaises(StackOverflow): stack_w_limit.push(Node(2))
def test_pop(self): self.stack.push(Node(2)) self.stack.push(Node(3)) assert_that(3).is_equal_to(self.stack.pop().value)
def _get_circular_lst(self): circular_node = Node(1000) nodes = [Node(1), Node(2), circular_node, Node(3), circular_node] return create_linked_list_with_list_of_nodes(nodes)