Ejemplo n.º 1
0
 def test_stack_array3(self):
     stack = StackArray()
     for i in range(3):
         stack.push(i)
     self.assertEqual(stack.size(), 3)
     self.assertFalse(stack.is_empty())
     self.assertEqual(stack.pop(), 2)
     self.assertEqual(stack.pop(), 1)
     self.assertEqual(stack.pop(), 0)
     self.assertEqual(stack.size(), 0)
     self.assertTrue(stack.is_empty())
Ejemplo n.º 2
0
 def test_size(self):
     stk_a = StackArray(4)
     stk_a.push(6)
     stk_a.push(7)
     stk_a.push(8)
     stk_a.push(9)
     self.assertTrue(stk_a.is_full())
     with self.assertRaises(IndexError): 
         stk_a.push(0)
     self.assertEqual(stk_a.size(), 4 )
     self.assertEqual(stk_a.pop(), 9 )
     self.assertEqual(stk_a.size(), 3 )
     self.assertFalse(stk_a.is_empty())
Ejemplo n.º 3
0
 def test_stack_array(self):
     arr1 = StackArray()
     arr1.push(4)
     arr1.push(5)
     self.assertEqual(arr1.size(), 2)
     self.assertEqual(arr1.is_full(), True)
     arr1.enlarge()
     self.assertEqual(arr1.is_full(), False)
     arr1.push(6)
     arr1.push(7)
     self.assertEqual(arr1.is_full(), True)
     self.assertEqual(arr1.pop(), 7)
     arr1.pop()
     arr1.pop()
     arr1.pop()
     self.assertEqual(arr1.is_empty(), True)
     arr2 = StackArray()
     arr2.enlarge()
     arr2.enlarge()
     arr2.shrink()
     self.assertEqual(arr2.capacity, 4)
     arr2.enlarge()
     arr2.push(5)
     arr2.push(9)
     arr2.push(10)
     self.assertEqual(arr2.peek(), 10)
     arr3 = StackArray()
     self.assertEqual(arr3.peek(), None)
     print(arr2.arr)
     arr4 = StackArray()
     with self.assertRaises(IndexError):
         arr4.pop()
Ejemplo n.º 4
0
 def test_stack_array2(self):
     stack = StackArray()
     for i in range(3):
         stack.push(i)
     self.assertEqual(stack.size(), 3)
     self.assertFalse(stack.is_empty())
     self.assertEqual(stack.peek(), 2)
Ejemplo n.º 5
0
 def test_StackArray(self):
     stack = StackArray(3)
     self.assertRaises(IndexError, stack.pop)
     self.assertEqual(stack.is_empty(), True)
     stack.push('book1')
     stack.push('book2')
     self.assertEqual(stack.peek(), 'book2')
     self.assertEqual(stack.pop(), 'book2')
     self.assertEqual(stack.peek(), 'book1')
     stack.push('book2_2')
     stack.push('book3')
     self.assertRaises(IndexError, stack.push, 'book4')
     self.assertEqual(stack.size(), 3)
     self.assertEqual(stack.is_full(), True)
Ejemplo n.º 6
0
 def test_size(self):
     stacka = StackArray()
     self.assertEqual(stacka.size(), 0)
     stackl = StackLinked()
     stackl.num_items = 20
     self.assertEqual(stackl.size(), 20)
Ejemplo n.º 7
0
 def test_stack_array1(self):
     stack = StackArray()
     self.assertEqual(stack.size(), 0)
     self.assertTrue(stack.is_empty())