import unittest class TestStack(unittest.TestCase): # TODO: It would be better if we had unit tests for each # method in addition to the following end-to-end test def test_end_to_end(self): print('Test: Empty stack') stack = Stack() self.assertEqual(stack.peek(), None) self.assertEqual(stack.pop(), None) print('Test: One element') top = Node(5) stack = Stack(top) self.assertEqual(stack.pop(), 5) self.assertEqual(stack.peek(), None) print('Test: More than one element') stack = Stack() stack.push(1) stack.push(2) stack.push(3) self.assertEqual(stack.pop(), 3) self.assertEqual(stack.peek(), 2) self.assertEqual(stack.pop(), 2) self.assertEqual(stack.peek(), 1) self.assertEqual(stack.is_empty(), False) self.assertEqual(stack.pop(), 1) self.assertEqual(stack.peek(), None) self.assertEqual(stack.is_empty(), True) print('Success: test_end_to_end') def main(): test = TestStack() test.test_end_to_end() if __name__ == '__main__': main()