Ejemplo n.º 1
0
def test_if_peek_needs_no_inputs():
    """Test that an unnecessary parameter will raise a TypeError."""
    import pytest
    from que_ import Queue
    q = Queue()
    q.enqueue(5)
    with pytest.raises(TypeError):
        q.peek(5)
Ejemplo n.º 2
0
 def test_5(self):
     """ Check that peek gives the value of the top node """
     q = Queue()
     n1 = Node(1)
     n2 = Node(2)
     q.enqueue(n1)
     q.enqueue(n2)
     q.peek()
     self.assertEqual(q.top._value, 1)
Ejemplo n.º 3
0
def test_peek():
    """Test if next value to be removed is accurate."""
    from que_ import Queue
    test_q = Queue()
    test_q.enqueue(99)
    test_q.enqueue(5)
    assert test_q.peek() == 99
Ejemplo n.º 4
0
def test_queue_peek_with_data():
    """Test the queue peek method displays the tail."""
    from que_ import Queue
    q = Queue()
    q.enqueue('one')
    q.enqueue('two')
    assert q.peek() == 'one'
Ejemplo n.º 5
0
    def breadth_first_traversal(self, val):
        """
        Perform a breadth first traversal.

        The breadth first traversal starts at the user input val
        and explores the neighbor nodes first before moving on to
        the next depth of neighbors.
        """
        search_order = []
        children_queue = Queue()
        children_queue.enqueue(val)
        while children_queue.peek():
            if self.graph[children_queue.peek()] == {}:
                child = children_queue.dequeue()
                if child not in search_order:
                    search_order.append(child)
            else:
                for child in self.graph[children_queue.peek()].keys():
                    if child not in search_order:
                        children_queue.enqueue(child)
                search_order.append(children_queue.dequeue())
        return search_order
Ejemplo n.º 6
0
    def breadth_first(self):
        """Return a generator that returns values tree breadth first order."""
        if self.size_count == 0:
            raise IndexError("Cannot traverse empty tree.")

        breadth_list = Queue()
        breadth_list.enqueue(self.root)
        yield breadth_list.peek().val

        while breadth_list.peek():
            if breadth_list.peek().left:
                breadth_list.enqueue(breadth_list.peek().left)
                yield breadth_list.peek().left.val
            if breadth_list.peek().right:
                breadth_list.enqueue(breadth_list.peek().right)
                yield breadth_list.peek().right.val
            breadth_list.dequeue()
Ejemplo n.º 7
0
def test_output_of_peek_exists():
    """Test that the output exists."""
    from que_ import Queue
    q = Queue()
    q.enqueue(5)
    assert q.peek() is not None
Ejemplo n.º 8
0
def test_peek_finds_value_of_front_of_queue(itr):
    """Test that peek finds the value of the front of the queue."""
    from que_ import Queue
    q = Queue(itr)
    assert q.peek() == itr[0]
    assert q._values.length == len(itr)
Ejemplo n.º 9
0
def test_peek_empty():
    """Test calling peek on empty returns None."""
    from que_ import Queue
    test_q = Queue()
    assert test_q.peek() is None
Ejemplo n.º 10
0
def test_queue_peek_with_no_data():
    """Test the queue peek returns None."""
    from que_ import Queue
    q = Queue()
    assert q.peek() is None