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)
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)
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)
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)
def test_pop_empty(self): s = Stack() self.assertRaises(EmptyStack, s.pop)
def test_peek(self): s = Stack() s.push(2) s.push(4) self.assertEqual(s.peek(), 4)
def test_pop(self): s = Stack() s.push(2) self.assertEqual(s.pop(), 2)
def test_size(self): s = Stack() s.push(2) self.assertEqual(s.size(), 1)
def setUp(self): self.stack = Stack()
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)
def test_push(self): s = Stack() self.assertTrue(s.push(5))
def test_is_empty(self): s = Stack() self.assertTrue(s.is_empty()) s.push(5) self.assertFalse(s.is_empty())
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)