예제 #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)
예제 #2
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)
예제 #3
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)
예제 #4
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)
예제 #5
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)
예제 #6
0
 def test_is_empty(self):
     s = Stack()
     self.assertTrue(s.is_empty())
     s.push(5)
     self.assertFalse(s.is_empty())