def test_is_empty_returns_correct_boolean_value(self):
        q = LinkedQueue()

        self.assertTrue(q.is_empty())

        q._size = 1

        self.assertFalse(q.is_empty())
    def test_len_returns_correct_queue_length(self):
        q = LinkedQueue()
        expected_size = 0
        actual_size = len(q)

        self.assertEqual(actual_size, expected_size)

        q._size = 1
        expected_size = 1
        actual_size = len(q)

        self.assertEqual(actual_size, expected_size)
Beispiel #3
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)
    def test_enqueue_adds_an_element_to_the_back_of_queue(self):
        q = LinkedQueue()
        first_element = LinkedQueue._Node('foo', None)
        q._head = first_element
        q._tail = first_element
        q._size = 1
        second_element = 'bar'

        q.enqueue(second_element)
        result = q._tail._element

        self.assertEqual(result, second_element)
    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)
    def test_first_returns_first_element_without_removing_it(self):
        q = LinkedQueue()
        q._head = LinkedQueue._Node('foo', None)
        q._size = 1
        expected_result = 'foo'

        result = q.first()

        self.assertEqual(result, expected_result)
        self.assertIn(expected_result, q._head._element)
    def test_dequeue_raises_Empty_exception_if_queue_is_empty(self):
        q = LinkedQueue()

        self.assertRaises(Empty, q.dequeue)