Exemple #1
0
 def test_is_empty_2(self):
     dll = LinkedList()
     assert dll.head is None
     assert dll.tail is None
     assert dll.size == 0
     assert dll.append(1) is None
     assert dll.is_empty() is False
Exemple #2
0
 def test_reverse(self):
     dll = LinkedList()
     items = 100
     assert dll.is_empty()
     assert dll.reverse() is None
     assert dll.is_empty()
     for i in range(items):
         assert dll.append(i) is None
     assert isinstance(dll.head, Node)
     assert isinstance(dll.tail, Node)
     assert dll.size == items
     assert dll.head is not dll.tail
     assert dll.head.data == 0
     assert dll.head.prev is None
     assert dll.tail.data == items - 1
     assert dll.tail.next is None
     assert dll.reverse() is None
     assert isinstance(dll.head, Node)
     assert isinstance(dll.tail, Node)
     assert dll.size == items
     assert dll.head is not dll.tail
     assert dll.head.data == items - 1
     assert dll.head.prev is None
     assert dll.tail.data == 0
     assert dll.tail.next is None
     match = items - 1
     for node in dll:
         assert node.data == match
         match -= 1
     assert dll.reverse() is None
     match = 0
     for node in dll:
         assert node.data == match
         match += 1
Exemple #3
0
 def test_extend_another_linked_list(self):
     first = LinkedList()
     second = LinkedList()
     items = 100
     for i in range(items):
         assert first.append(i) is None
     for j in range(items, items * 2):
         assert second.append(j) is None
     assert first.extend(second) is None
     assert isinstance(first.head, Node)
     assert isinstance(first.tail, Node)
     assert first.head is not second.head
     assert first.tail is not second.tail
     assert first.size == items * 2
     match = 0
     for node in first:
         assert node.data == match
         match += 1
Exemple #4
0
 def test_remove_tail(self):
     dll = LinkedList()
     items = 2
     assert dll.is_empty()
     for i in range(items):
         assert dll.append(i) is None
     assert dll.size == items
     assert dll.tail is not dll.head
     assert dll.remove(1) is None
     assert dll.head is dll.tail
     assert dll.size == items - 1
Exemple #5
0
 def test_append_empty(self):
     dll = LinkedList()
     assert dll.head is None
     assert dll.tail is None
     assert dll.size == 0
     assert dll.append(1) is None
     assert isinstance(dll.head, Node)
     assert isinstance(dll.tail, Node)
     assert dll.head.data == dll.tail.data
     assert dll.head is dll.tail
     assert dll.size == 1
Exemple #6
0
 def test_clear(self):
     dll = LinkedList()
     items = 100
     assert dll.is_empty()
     for i in range(items):
         assert dll.append(i) is None
     assert isinstance(dll.head, Node)
     assert isinstance(dll.tail, Node)
     assert dll.size == items
     assert dll.clear() is None
     assert dll.head is None
     assert dll.tail is None
     assert dll.size == 0
Exemple #7
0
 def test_remove_mid(self):
     dll = LinkedList()
     items = 3
     assert dll.is_empty()
     for i in range(items):
         assert dll.append(i) is None
     assert dll.size == items
     assert dll.head is not dll.tail
     assert dll.remove(1) is None
     assert dll.head is not dll.tail
     assert dll.head.data == 0
     assert dll.tail.data == 2
     assert dll.head.next is dll.tail
     assert dll.tail.prev is dll.head
     assert dll.head.prev is None
     assert dll.tail.next is None
     assert dll.size == items - 1
Exemple #8
0
 def test_iter(self):
     dll = LinkedList()
     items = 10
     counter = 0
     assert dll.head is None
     assert dll.tail is None
     assert dll.size == 0
     for i in range(items):
         assert dll.append(i) is None
     assert isinstance(dll.head, Node)
     assert isinstance(dll.tail, Node)
     assert dll.size == items
     for node in dll:
         assert isinstance(node, Node)
         assert isinstance(node.data, int)
         counter += 1
     assert counter == items
Exemple #9
0
 def test_append_multiple(self):
     dll = LinkedList()
     items = 100
     assert dll.head is None
     assert dll.tail is None
     assert dll.size == 0
     for i in range(items):
         assert dll.append(i) is None
         assert dll.size == i + 1
         assert dll.tail.data == i
     assert isinstance(dll.head, Node)
     assert isinstance(dll.tail, Node)
     assert dll.head is not dll.tail
     assert dll.size == items
     for j in range(items):
         assert dll.pop().data == j
     assert dll.head is None
     assert dll.tail is None
     assert dll.size == 0
Exemple #10
0
 def test_insert_end_negative(self):
     dll = LinkedList()
     assert dll.is_empty()
     assert dll.append(0) is None
     assert dll.append(1) is None
     assert isinstance(dll.head, Node)
     assert isinstance(dll.tail, Node)
     assert dll.head is not dll.tail
     assert dll.size == 2
     assert dll.insert(-1, 2) is None
     assert isinstance(dll.head, Node)
     assert isinstance(dll.tail, Node)
     assert dll.head is not dll.tail
     assert dll.head.data == 0
     assert dll.tail.data == 1
     assert dll.head.next is not dll.tail
     assert dll.head.next.data == 2
     assert dll.head.prev is None
     assert dll.tail.prev is not dll.head
     assert dll.tail.prev.data == 2
     assert dll.tail.next is None
     assert dll.size == 3