def testPush(self): stack = StackLinkedList() stack.push(0) stack.push(1) self.assertEqual(2, stack.num_elements)
def testPopOnNonEmptyStack(self): stack = StackLinkedList() stack.push(0) stack.push(1) stack.push(2) self.assertEqual(2, stack.pop()) self.assertEqual(2, stack.size())
def testIsEmptyOnNonEmptyStack(self): stack = StackLinkedList() stack.push(0) stack.push(1) stack.push(2) self.assertFalse(stack.is_empty())
def testSizeMethod(self): stack = StackLinkedList() stack.push(0) stack.push(1) stack.push(2) self.assertEqual(3, stack.size())
def pre_order(root_node): s = StackLinkedList() t = root_node while t is not None or s.is_empty() != True: if t is not None: print(t.data) s.push(t) t = t.left_child else: t = s.pop() t = t.right_child
def testPopOnEmptyStack(self): stack = StackLinkedList() self.assertEqual(None, stack.pop())
def testIsEmptyOnEmptyStack(self): stack = StackLinkedList() self.assertTrue(stack.is_empty())