Ejemplo n.º 1
0
 def breadthfirst(self):
     """Generate a breadth-first iteration of the positions of the tree."""
     if not self.is_empty():
         fringe = LinkedQueue()
         fringe.enqueue(self.root())
         while not fringe.is_empty():
             p = fringe.dequeue()
             yield p
             for c in self.children(p):
                 fringe.enqueue(c)
Ejemplo n.º 2
0
    def test_dequeue_returns_and_removes_first_element_from_queue(self):
        q = LinkedQueue()
        second_element = LinkedQueue._Node('bar', None)
        first_element = LinkedQueue._Node('foo', second_element)
        q._head = first_element
        q._tail = second_element
        q._size = 2
        expected_result = 'foo'

        result = q.dequeue()

        self.assertEqual(q._size, 1)
        self.assertEqual(result, expected_result)
        self.assertIsNot(q._head, first_element)