class Test_Predictable_Stack_Top_With_4_Elements(unittest.TestCase):
    def setUp(self):
        self._stack = Stack()
        self._stack.push(1)
        self._stack.push(2)
        self._stack.push(3)
        self._stack.push(4)

    def test_stack_top_with_4_elements(self):
        self.assertEqual(self._stack.top, 4, 'NA')

    def tearDown(self):
        del self._stack
class Test_Iterator_With_Stack_Of_4_Elements(unittest.TestCase):
    def setUp(self):
        self._stack = Stack()
        self._stack.push(1)
        self._stack.push(2)
        self._stack.push(3)
        self._stack.push(4)

    def test_iterator_with_stack_with_4_elements(self):
        elements = [4, 3, 2, 1]
        for stack_element in self._stack:
            self.assertEqual(stack_element, elements[0],
                             'stack Iterator must match expected elements.')
            del elements[0]

    def tearDown(self):
        del self._stack
 def inorder_traversal_with_stack(self):
     '''
     this inorder traversal uses a stack and yields (key, value) pairs. this was added since link-
     inversion traversal modifies the tree during traversal. This is a bummer as we use tree as a
     hash bucket in hash tables. There are instances in MutableMapping where you iterate over the
     key (tree has changed temporarily) and do d[key] which duly fails. 
     '''
     stack = Stack()
     current_node = self._root_node
     while 1 == 1:
         while(current_node != None):
             stack.push(current_node)
             current_node = current_node.left_child
         if stack.size == 0:
             break
         popped_node = stack.pop()
         yield (popped_node.key, popped_node.value)
         current_node = popped_node.right_child
class Test_Pop_To_Empty_With_Predictable_Stack_Of_4_Elements(
        unittest.TestCase):
    def setUp(self):
        self._stack = Stack()
        self._stack.push(1)
        self._stack.push(2)
        self._stack.push(3)
        self._stack.push(4)

    def test_pop_to_empty_stack_with_4_elements(self):
        self.assertEqual(self._stack.size, 4, 'NA')

        elements = [4, 3, 2, 1]
        for element in elements:  #pop 4 times
            self.assertEqual(self._stack.pop(), element)

        self.assertEqual(self._stack.pop(), None,
                         'Empty stack must return None')
        self.assertEqual(self._stack.size, 0, 'NA')

    def tearDown(self):
        del self._stack
'''
Created on Oct 25, 2015
@author: hari
'''
from __future__ import print_function
from builtins import str
from pycoils.stackNqueues.stack import Stack

if __name__ == '__main__':
    stack = Stack()
    # count items
    print('stack items count: %s' % str(stack.size))
    #Push items
    stack.push(item=1)
    stack.push(item=2)
    stack.push(item=3)
    stack.push(item=4)
    stack.push(item=5)
    stack.push(item=6)
    #top
    print('stack top is %s' % str(stack.top))
    #pop
    popped = stack.pop()
    print('Popped item is %s' % str(popped))
    #iterate over the stack popping items one by one
    print('Iterate over stack popping items')
    for item in stack:
        print('item %s' % str(item))