Ejemplo n.º 1
0
 def test_util_sublist_start_greater_than_end(self):
     with pytest.raises(IndexError):
         items = 10
         dll = LinkedList()
         for i in range(items):
             dll.push(i)
         sublist(dll, 3, 2)
Ejemplo n.º 2
0
 def test_sublist(self):
     dll = LinkedList()
     items = 10
     start, end = 0, 3
     assert dll.head is None
     assert dll.size == 0
     for i in range(items):
         assert dll.push(i) is None
     assert type(dll.head) is Node
     assert dll.size == 10
     sl = sublist(dll, start, end)
     assert type(sl) is LinkedList
     assert type(sl.head) is Node
     assert sl.size == (end - start)
     compare = items - 1
     for node in sl:
         assert node.data == compare
         compare -= 1
Ejemplo n.º 3
0
 def halves(linked_list, begin, end):
     mid = linked_list.size // 2
     left = sublist(linked_list, begin, mid)
     right = sublist(linked_list, mid, end)
     return left, right
Ejemplo n.º 4
0
 def test_util_sublist_equal_start_and_end(self):
     with pytest.raises(IndexError):
         sublist(LinkedList(), 0, 0)
Ejemplo n.º 5
0
 def test_util_sublist_end_out_of_bounds(self):
     with pytest.raises(IndexError):
         sublist(LinkedList(), 0, 1)
Ejemplo n.º 6
0
 def test_util_sublist_negative_end(self):
     with pytest.raises(IndexError):
         sublist(LinkedList(), 0, -1)
Ejemplo n.º 7
0
 def test_util_sublist_negative_start(self):
     with pytest.raises(IndexError):
         sublist(LinkedList(), -1, 0)
Ejemplo n.º 8
0
 def test_util_sublist_invalid_type(self):
     with pytest.raises(TypeError):
         sublist(None)