Beispiel #1
0
 def test_pop_all_e(self):
     my_stack = Stack()
     my_stack.push_to_end(1)
     my_stack.push_to_end(2)
     my_stack.push_to_end(3)
     pop_el1 = my_stack.pop_from_end()
     pop_el2 = my_stack.pop_from_end()
     pop_el3 = my_stack.pop_from_end()
     data = my_stack.stack + [pop_el1] + [pop_el2] + [pop_el3]
     res =  [3, 2, 1]
     self.assertEqual( data, res)
Beispiel #2
0
 def test_random_e(self):
     for i in range(10000):
         s = Stack()
         res = []
         comand = random.randint(0, 1) # 0 - pop, 1 - push
         if comand:
             t = random.randint(0,9)
             s.push_to_end(t)
             res.append(t)
         else:
             s.pop_from_end()
             try:
                 res.pop()
             except:
                 pass
         data = s.stack + [s.size()]
         res =  res + [len(res)]
         self.assertEqual( data, res)
Beispiel #3
0
 def test_pop_in_middle_e(self):
     my_stack = Stack()
     my_stack.push_to_end(1)
     my_stack.push_to_end(2)
     pop_el = my_stack.pop_from_end()
     my_stack.push_to_end(3)
     data = my_stack.stack + [pop_el]
     res =  [1, 3, 2]
     self.assertEqual( data, res)
Beispiel #4
0
 def test_pop_one_e(self):
     my_stack = Stack()
     my_stack.push_to_end(1)
     my_stack.push_to_end(2)
     my_stack.push_to_end(3)
     pop_el = my_stack.pop_from_end()
     data = my_stack.stack + [pop_el]
     res =  [1, 2, 3]
     self.assertEqual( data, res)
Beispiel #5
0
 def test_pop_none_e(self):
     my_stack = Stack()
     pop_el = my_stack.pop_from_end()
     data = my_stack.stack + [pop_el]
     res =  [None]
     self.assertEqual( data, res)