Example #1
0
 def test_stack_push_pop_ordering(self):
     s1 = Stack()
     s2 = s1.push(1)
     s3 = s2.push(10)
     s4 = s3.push(100)
     (sv4, s5) = s4.pop()
     (sv3, s6) = s5.pop()
     self.assertEqual(100, sv4)
     self.assertEqual(10, sv3)
     self.assertEqual(100, s4.pop()[0])
Example #2
0
 def test_stack_push_pop_ordering(self):
     s1 = Stack()
     s2 = s1.push(1)
     s3 = s2.push(10)
     s4 = s3.push(100)
     (sv4, s5) = s4.pop()
     (sv3, s6) = s5.pop()
     self.assertEqual(100, sv4)
     self.assertEqual(10, sv3)
     self.assertEqual(100, s4.pop()[0])
Example #3
0
 def test_stack_iterator(self):
     self.assertEqual([10, 5, 1], list(Stack().push(1).push(5).push(10)))
     self.assertEqual(6, sum(Stack().push(1).push(2).push(3)))
Example #4
0
 def test_pop_empty_stack_exception(self):
     self.assertRaises(ValueError, Stack().pop)
Example #5
0
 def test_stack_is_empty_check(self):
     self.assertTrue(Stack().push(100))
     self.assertFalse(Stack().push(100).is_empty())
     self.assertTrue(Stack().is_empty())
Example #6
0
 def test_stack_length(self):
     self.assertEqual(0, len(Stack()))
     self.assertEqual(3, len(Stack().push(1).push(2).push(3)))