Esempio n. 1
0
 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))
Esempio n. 2
0
 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)
Esempio n. 3
0
 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
Esempio n. 4
0
 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]
Esempio n. 5
0
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
Esempio n. 6
0
 def setUp(self):
     head = Node(1)
     self.linked_list = LinkedList(head)
Esempio n. 7
0
 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)
Esempio n. 8
0
 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)
Esempio n. 9
0
 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()
Esempio n. 10
0
 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)
Esempio n. 11
0
 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)
Esempio n. 12
0
 def setUp(self):
     self.stack = StackWLinkedList(Node(1))
Esempio n. 13
0
 def test_overflow(self):
     stack_w_limit = StackWLinkedList(Node(1), 1)
     with self.assertRaises(StackOverflow):
         stack_w_limit.push(Node(2))
Esempio n. 14
0
 def test_pop(self):
     self.stack.push(Node(2))
     self.stack.push(Node(3))
     assert_that(3).is_equal_to(self.stack.pop().value)
Esempio n. 15
0
 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)