예제 #1
0
 def test_stack_copy(self):
     s = Stack([1, 2, 3])
     c = s.copy()
     s.push(4)
     c.push(5)
     actual = '{} {}'.format(s, c)
     expected = 'Stack(1, 2, 3, 4 ↔) Stack(1, 2, 3, 5 ↔)'
     self.assertEqual(expected, actual)
예제 #2
0
 def test_stack_peek(self):
     s = Stack()
     s.push(1)
     s.push(2)
     p = s.peek()
     actual = '{} {}'.format(p, s)
     expected = '2 Stack(1, 2 ↔)'
     self.assertEqual(expected, actual)
예제 #3
0
 def test_bounded_stack(self):
     s = Stack(maxlen=2)
     s.push(1)
     s.push(2)
     s.push(3)
     n = len(s)
     out = s.pop()
     actual = '{} {} {}'.format(n, out, s)
     expected = '2 3 Stack(2 ↔)'
     self.assertEqual(expected, actual)
예제 #4
0
 def test_stack(self):
     s = Stack()
     s.push(1)
     s.push(2)
     s.push(3)
     n = len(s)
     out = s.pop()
     actual = '{} {} {}'.format(n, out, s)
     expected = '3 3 Stack(1, 2 ↔)'
     self.assertEqual(expected, actual)
예제 #5
0
 def test_empty_stack(self):
     self.assertEqual('Stack()', str(Stack()))
예제 #6
0
 def test_stack_iter(self):
     actual = list(Stack([1, 2, 3]))
     expected = [1, 2, 3]
     self.assertEqual(expected, actual)
예제 #7
0
 def test_stack_reversed(self):
     actual = list(reversed(Stack([1, 2, 3])))
     expected = [3, 2, 1]
     self.assertEqual(expected, actual)