Пример #1
0
 def test_traverse_from(self):
     dll = DoubleLinkedList()
     dll.add(12)
     dll.add(99)
     dll.add(37)
     dll.add(66)
     dll.add(44)
     self.assertEqual([37, 66, 44], dll.traverse(37))
     self.assertEqual(5, dll.count_links())
Пример #2
0
 def test_traverse_back_from(self):
     dll = DoubleLinkedList()
     dll.add(12)
     dll.add(99)
     dll.add(37)
     dll.add(66)
     dll.add(44)
     self.assertEqual([66, 37, 99, 12], dll.traverse_back(66))
     self.assertEqual(5, dll.count_links())
Пример #3
0
 def test_traverse(self):
     dll = DoubleLinkedList()
     dll.add(12)
     dll.add(99)
     dll.add(37)
     self.assertEqual([12, 99, 37], dll.traverse())
     self.assertEqual(3, dll.count_links())
Пример #4
0
 def test_traverse_back(self):
     dll = DoubleLinkedList()
     dll.add(12)
     dll.add(99)
     dll.add(37)
     self.assertEqual([37, 99, 12], dll.traverse_back())
     self.assertEqual(3, dll.count_links())
Пример #5
0
 def test_get_link_values(self):
     dll = DoubleLinkedList()
     dll.add(12)
     dll.add(99)
     dll.add(37)
     dll.add(66)
     items_expected = [12, 99, 37, 66]
     self.assertEqual(items_expected, dll.get_link_values())
     self.assertEqual(4, dll.count_links())
Пример #6
0
 def test_get_link(self):
     dll = DoubleLinkedList()
     dll.add(12)
     dll.add(99)
     dll.add(37)
     link = dll.get_link(99)
     self.assertEqual(99, link.value)
     self.assertEqual(37, link.next)
     self.assertEqual(12, link.prev)
     self.assertEqual(3, dll.count_links())
Пример #7
0
 def test_get_last(self):
     dll = DoubleLinkedList()
     dll.add(12)
     dll.add(99)
     dll.add(37)
     link = dll.get_last()
     self.assertEqual(37, link.value)
Пример #8
0
 def test_get_position(self):
     dll = DoubleLinkedList()
     dll.add(12)
     dll.add(99)
     dll.add(37)
     self.assertEqual(2, dll.get_position(37))
Пример #9
0
 def test_get_first(self):
     dll = DoubleLinkedList()
     dll.add(12)
     dll.add(99)
     link = dll.get_first()
     self.assertEqual(12, link.value)
Пример #10
0
 def test_not_empty(self):
     dll = DoubleLinkedList()
     dll.add(12)
     self.assertEqual(False, dll.empty())
Пример #11
0
 def test_update(self):
     dll = DoubleLinkedList()
     dll.add(12)
     dll.add(99)
     dll.add(37)
     dll.add(66)
     dll.update(99, 88)
     traverse_expected = [12, 88, 37, 66]
     self.assertEqual(traverse_expected, dll.traverse())
     traverse_expected.reverse()
     self.assertEqual(traverse_expected, dll.traverse_back())
     # items_expected = [12, 37, 66, 88]
     # self.assertEqual(items_expected, dll.get_link_values())
     self.assertEqual(4, dll.count_links())
Пример #12
0
 def test_delete_reconnect(self):
     dll = DoubleLinkedList()
     dll.add(12)
     dll.add(99)
     dll.add(37)
     dll.add(66)
     dll.add(44)
     dll.delete(37, reconnect=True)
     self.assertEqual([12, 99, 66, 44], dll.traverse())
     self.assertEqual([44, 66, 99, 12], dll.traverse_back())
     self.assertEqual([12, 99, 66, 44], dll.get_link_values())
     self.assertEqual(4, dll.count_links())
Пример #13
0
 def test_empty(self):
     dll = DoubleLinkedList()
     self.assertEqual(True, dll.empty())
Пример #14
0
def main():
  """
  print("### Node")
  node1 = Node(12)
  node2 = Node(99)
  node3 = Node(37)
  node4 = Node(66)

  node1.next = node2
  node2.next = node3
  node3.next = node4

  node1.traverse()

  print("### DoubleNode")
  dnode1 = DoubleNode(12)
  dnode2 = DoubleNode(99)
  dnode3 = DoubleNode(37)

  dnode1.next = dnode2
  dnode2.prev = dnode1
  dnode2.next = dnode3
  dnode3.prev = dnode2

  dnode1.traverse()
  dnode3.traverse_back()
  """

  """
  #items = [12, 99, 37, 66]
  #sll = SingleLinkedList(items)
  sll = SingleLinkedList()
  sll.add(12)
  sll.add(99)
  sll.add(37)
  sll.add(66)
  sll.traverse()
  sll.add(44)

  link66 = sll.get_link(66)
  print("link66: value=%s next=%s" % (link66.value, link66.next))
  print("links: %s" % (sll.links))
  link_last = sll.get_last()
  print("link_last: value=%s next=%s" % (link_last.value, link_last.next))

  sll.traverse(37)
  print("get_position 99")
  print(sll.get_position(99))

  #link37 = sll.get_by_next(37)
  #print("link37:", link37.value)

  print("update 99 - 88")
  sll.update(99, 88)
  print("links: %s" % (sll.links))
  sll.traverse()

  print("delete 66")
  sll.delete(66)
  print("links: %s" % (sll.links))
  sll.traverse()
  """

  dll = DoubleLinkedList()
  dll.add(12)
  dll.add(99)
  dll.add(37)
  dll.add(66)
  dll.add(44)
  print("links: %s" % (dll.links))
  dll.traverse()
  dll.traverse(99)

  dll.traverse_back()
  dll.traverse_back(37)

  link_by66 = dll.get_link(66)
  print("link_by66: value=%s next=%s prev=%s" % (link_by66.value, link_by66.next, link_by66.prev))
  link_next66 = dll.get_by_next(66)
  print("link_next66: value=%s next=%s prev=%s" % (link_next66.value, link_next66.next, link_next66.prev))
  link_prev66 = dll.get_by_prev(66)
  print("link_prev66: value=%s next=%s prev=%s" % (link_prev66.value, link_prev66.next, link_prev66.prev))