Code example for PriorityQueue

Methods: poll, size

0
 
    /** 
     * @tests java.util.PriorityQueue#poll() 
     */ 
    public void test_poll_empty() { 
        PriorityQueue<Object> queue = new PriorityQueue<Object>();
        assertEquals(0, queue.size());
        assertNull(queue.poll());
    } 
 
    /** 
     * @tests java.util.PriorityQueue#peek() 
     */ 
    public void test_peek() { 
        PriorityQueue<Integer> integerQueue = new PriorityQueue<Integer>();
        int[] array = { 2, 45, 7, -12, 9 };
        for (int i = 0; i < array.length; i++) {
            integerQueue.add(array[i]);
        } 
        Arrays.sort(array);
        assertEquals(new Integer(array[0]), integerQueue.peek());