def testPush(self): stack = StackArray() stack.push(0) stack.push(1) self.assertEqual( [0, 1, None, None, None, None, None, None, None, None], stack.arr) self.assertEqual(2, stack.next_index) self.assertEqual(2, stack.num_elements)
def testSizeMethod(self): stack = StackArray() stack.push(0) stack.push(1) stack.push(2) self.assertEqual(3, stack.size())
def testPopOnNonEmptyStack(self): stack = StackArray() stack.push(0) stack.push(1) stack.push(2) self.assertEqual(2, stack.pop())
def testIsEmptyOnNonEmptyStack(self): stack = StackArray() stack.push(0) stack.push(1) stack.push(2) self.assertFalse(stack.is_empty())
def test_full(): s = StackArray(5) le = [] la = [] for i in range(20,201,10): s.push(i) le.insert(0,i) while not s.is_empty(): la.append(s.pop()) assert le == la
def test_clear_empty(): s = StackArray() s.push(5) s.clear() assert s.is_empty()
def test_pop_empty(): s = StackArray() assert s.pop() is None
def test_enq_many_pop(): s = StackArray() s.push(15) s.push(16) s.push(17) assert s.pop() == 17
def test_enq_many_empty(): s = StackArray() s.push(15) s.push(16) s.push(17) assert not s.is_empty()
def test_pop_empty(): s = StackArray() s.push(5) s.pop() assert s.is_empty()
#! /usr/bin/env python from StackArray import StackArray my_stack = StackArray() my_stack.push(2) my_stack.push(8) my_stack.push(9) my_stack.push(2) my_stack.push(4) my_stack.push(5) my_stack.push(1) print(my_stack) print("peek: {}".format(my_stack.peek())) ret = my_stack.pop() print("pop: {}".format(ret)) print("my_stack: {}".format(my_stack))
def test_enq_peek(): s = StackArray() s.push(5) assert s.peek() == 5
def testPopOnEmptyStack(self): stack = StackArray() self.assertEqual(None, stack.pop())
def testIsEmptyOnEmptyStack(self): stack = StackArray() self.assertTrue(stack.is_empty())
def test_pop(): s = StackArray() s.push(5) assert s.pop() == 5
def test_enq_empty(): s = StackArray() s.push(5) assert not s.is_empty()
def test_is_empty(): s = StackArray() assert s.is_empty()
from StackArray import StackArray stack = StackArray() print(stack.isempty()) def char_range(c1, c2): s = '' for c in range(ord(c1), ord(c2) + 1): s = s + chr(c) return s str1 = char_range('a', 'b') str2 = char_range('c', 'f') #print(str1) #print(str2) stack.push(str1) print(stack.top()) stack.push(str2) print(stack.top()) def depth(stack): num = 0 s = []
def testPushingTooManyItems(self): stack = StackArray() stack.push(0) stack.push(1) stack.push(2) stack.push(3) stack.push(4) stack.push(5) stack.push(6) stack.push(7) stack.push(8) stack.push(9) stack.push(10) self.assertEqual([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, None, None, None, None, None, None, None, None, None ], stack.arr)