def test_peek(self): stacka = StackArray() self.assertRaises(IndexError, stacka.peek) stacka.num_items = 2 stacka.arr_list.arr = [1, 2] stacka.arr_list.num_items = 2 self.assertEqual(stacka.peek(), 2) stackl = StackLinked() self.assertRaises(IndexError, stackl.peek) stackl.top = stacks.Node(1, None) stackl.num_items = 1 self.assertEqual(stackl.peek(), 1)
def test_push(self): stack_1a = StackArray() stack_1a.push(7) stack_2a = StackArray() stack_2a.arr_list.arr = [7, None] stack_2a.arr_list.num_items = 1 stack_2a.num_items = 1 self.assertEqual(stack_1a, stack_2a) stack_1l = StackLinked() stack_1l.push(7) stack_2l = StackLinked() stack_2l.top = stacks.Node(7, None) stack_2l.num_items = 1 self.assertEqual(stack_1l, stack_2l)