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)
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)
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)
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)
def test_empty_stack(self): self.assertEqual('Stack()', str(Stack()))
def test_stack_iter(self): actual = list(Stack([1, 2, 3])) expected = [1, 2, 3] self.assertEqual(expected, actual)
def test_stack_reversed(self): actual = list(reversed(Stack([1, 2, 3]))) expected = [3, 2, 1] self.assertEqual(expected, actual)