Exemple #1
0
 def test_del_none_from_one_down(self):
     n1 = 3
     ls = OrderedList(False)
     ls.add(n1)
     ls.delete(1)
     data = ls.get_head_tail() + ls.get_list()
     res = [n1, n1, n1]
     self.assertEqual(data, res)
Exemple #2
0
 def test_del_one_from_one_up(self):
     n1 = 3
     ls = OrderedList(True)
     ls.add(n1)
     ls.delete(n1)
     data = ls.get_head_tail() + ls.get_list()
     res = [None, None]
     self.assertEqual(data, res)
Exemple #3
0
 def test_del_one_last_from_many(self):
     n1 = 1
     n2 = 2
     n3 = 3
     ls = OrderedList(True)
     ls.add(n1)
     ls.add(n2)
     ls.add(n3)
     ls.delete(3)
     data = ls.get_head_tail() + ls.get_list()
     res = [n1, n2, 1, 2]
     self.assertEqual(data, res)
Exemple #4
0
 def test_del_one_middle_from_many_down(self):
     n1 = 2
     n2 = 2
     n3 = 3
     ls = OrderedList(False)
     ls.add(n1)
     ls.add(n2)
     ls.add(n3)
     ls.delete(n2)
     data = ls.get_head_tail() + ls.get_list()
     res = [n3, n2, n3, n2]
     self.assertEqual(data, res)
Exemple #5
0
 def test_del_one_first_from_many_up(self):
     n1 = 2
     n2 = 1
     n3 = 3
     ls = OrderedList(True)
     ls.add(n1)
     ls.add(n2)
     ls.add(n3)
     ls.delete(n2)
     data = ls.get_head_tail() + ls.get_list()
     res = [n1, n3, n1, n3]
     self.assertEqual(data, res)
Exemple #6
0
 def test_random_del_down(self):  # не работает с удалением всех элементов
     for t in range(1000):
         ls = OrderedList(False)
         node_count = random.randint(0, 10)
         l = []
         for i in range(node_count):
             node = random.randint(-100, 100)
             ls.add(node)
             l.append(node)
         l = sorted(l, reverse=True)
         del_node = random.randint(-100, 100)
         ls.delete(del_node)
         data = data = ls.get_head_tail() + ls.get_list()
         try:
             l.remove(del_node)
         except:
             pass
         if l:
             res = [l[0], l[-1]] + l
         else:
             res = [None, None]
         self.assertEqual(data, res)
Exemple #7
0
 def test_random_del_up(self):
     for t in range(1000):
         ls = OrderedList(True)
         node_count = random.randint(0, 10)
         l = []
         for i in range(node_count):
             node = random.randint(-100, 100)
             ls.add(node)
             l.append(node)
         l = sorted(l)
         del_node = random.randint(-100, 100)
         ls.delete(del_node)
         data = data = ls.get_head_tail() + ls.get_list()
         try:
             l.remove(del_node)
         except:
             pass
         if l:
             res = [l[0], l[-1]] + l
         else:
             res = [None, None]
         self.assertEqual(data, res)