Example #1
0
	def test_is_empty(self):
		s = Stack()
		self.assertEqual(s.is_empty(), True)

		s.push(2)
		self.assertEqual(s.is_empty(), False)

		s.pop()
		self.assertEqual(s.is_empty(), True)
Example #2
0
 def test_peek(self):
     s = Stack()
     self.assertRaises(EmptyStack, s.peek)
     s.push(3)
     s.push('a')
     self.assertEqual(s.peek(), 'a')
     self.assertNotEqual(s.peek(), 3)
Example #3
0
 def test_size(self):
     s = Stack()
     s.push(5)
     s.push(6)
     self.assertEqual(s.size(), 2)
     s.push(123123123)
     self.assertEqual(s.size(), 3)
Example #4
0
 def test_pop(self):
     s = Stack()
     self.assertRaises(EmptyStack, s.pop)
     s.push(3)
     s.push("a")
     self.assertEqual(s.pop(), "a")
     self.assertEqual(s.pop(), 3)
Example #5
0
	def test_pop_empty(self):
		s = Stack()
		self.assertRaises(EmptyStack, s.pop)
Example #6
0
	def test_peek(self):
		s = Stack()
		s.push(2)
		s.push(4)
		self.assertEqual(s.peek(), 4)
Example #7
0
	def test_pop(self):
		s = Stack()
		s.push(2)
		self.assertEqual(s.pop(), 2)
Example #8
0
	def test_size(self):
		s = Stack()

		s.push(2)
		self.assertEqual(s.size(), 1)
Example #9
0
 def setUp(self):
     self.stack = Stack()
Example #10
0
class StackTests(unittest.TestCase):
    def setUp(self):
        self.stack = Stack()

    def test_pop(self):
        self.assertRaises(EmptyStack, self.stack.pop)
        self.stack.push('test')
        self.stack.push('a')
        self.assertEqual(self.stack.pop(), 'a')
        self.assertEqual(self.stack.size(), 1)

    def test_peek(self):
        self.assertRaises(EmptyStack, self.stack.peek)
        self.stack.push('test')
        self.assertEqual(self.stack.peek(), 'test')
        self.assertEqual(self.stack.size(), 1)

    def test_is_empty(self):
        self.assertTrue(self.stack.is_empty())

    def test_size(self):
        self.stack.push('test')
        self.assertEqual(self.stack.size(), 1)
Example #11
0
 def test_push(self):
     s = Stack()
     self.assertTrue(s.push(5))
Example #12
0
 def test_is_empty(self):
     s = Stack()
     self.assertTrue(s.is_empty())
     s.push(5)
     self.assertFalse(s.is_empty())
Example #13
0
 def setUp(self):
     self.stack = Stack()
Example #14
0
class StackTests(unittest.TestCase):

    def setUp(self):
        self.stack = Stack()

    def test_pop(self):
        self.assertRaises(EmptyStack, self.stack.pop)
        self.stack.push('test')
        self.stack.push('a')
        self.assertEqual(self.stack.pop(), 'a')
        self.assertEqual(self.stack.size(), 1)

    def test_peek(self):
        self.assertRaises(EmptyStack, self.stack.peek)
        self.stack.push('test')
        self.assertEqual(self.stack.peek(), 'test')
        self.assertEqual(self.stack.size(), 1)

    def test_is_empty(self):
        self.assertTrue(self.stack.is_empty())

    def test_size(self):
        self.stack.push('test')
        self.assertEqual(self.stack.size(), 1)
Example #15
0
 def test_Stack(self):
     self.assertIn('__init__', dir(Stack))
     self.assertIn('pop', dir(Stack))
     self.assertIn('is_empty', dir(Stack))
     testins = Stack()
     testins.push("first")
     testins.push(2)
     testins.push(3)
     self.assertEqual(testins.data, [3, 2, "first"])
     testins.pop()
     self.assertEqual(testins.data, [2, "first"])
     self.assertEqual(testins.peek(), 2)
     self.assertEqual(testins.size(), 2)
     self.assertEqual(testins.is_empty(), False)
     testins.pop()
     testins.pop()
     self.assertEqual(testins.is_empty(), True)
     self.assertRaises(EmptyStack, testins.pop)
     self.assertRaises(EmptyStack, testins.peek)
Example #16
0
 def test_Stack(self):
     self.assertIn('__init__', dir(Stack))
     self.assertIn('pop', dir(Stack))
     self.assertIn('is_empty', dir(Stack))
     testins = Stack()
     testins.push("first")
     testins.push(2)
     testins.push(3)
     self.assertEqual(testins.data, [3, 2, "first"])
     testins.pop()
     self.assertEqual(testins.data, [2, "first"])
     self.assertEqual(testins.peek(), 2)
     self.assertEqual(testins.size(), 2)
     self.assertEqual(testins.is_empty(), False)
     testins.pop()
     testins.pop()
     self.assertEqual(testins.is_empty(), True)
     self.assertRaises(EmptyStack, testins.pop)
     self.assertRaises(EmptyStack, testins.peek)