import datastructures.PriorityQueue;
import java.util.*;

public class PriorityQueueTest {
    public static void main(String[] args) throws Exception {
        for (int i = 0; i < 5; i ++) {
            testRandomSort(10000 + ((int) (Math.random() * 10000)));
        }
    }

    private static void testRandomSort(int count) throws Exception {
        System.out.printf("\tRandomSort (n = %d)\n", count);
        PriorityQueue<Integer> q = new PriorityQueue<>();
        for (int i = 0; i < count; i ++) {
            q.add((int) (Math.random() * Integer.MAX_VALUE));
        }

        if (q.isEmpty()) {
            throw new Exception("Queue is empty");
        }

        if (q.size() != count) {
            throw new Exception("Queue size is incorrect");
        }

        int prev = q.poll();

        while (!q.isEmpty()) {
            int curr = q.poll();

            if (curr < prev) {
                throw new Exception("Incorrect poll order");
            }
            prev = curr;
        }
    }
}
@@ -250,24 +250,102 @@
 * 10000)));%0A
+            testRandomSortAndInsert(10000 + ((int) (Math.random() * 10000)));%0A
         %7D%0A  
@@ -338,24 +338,24 @@
 ;%0A        %7D%0A
-
     %7D%0A%0A    p
@@ -974,25 +974,772 @@
 ev) 
-%7B%0A               
+throw new Exception(%22Incorrect poll order%22);%0A            prev = curr;%0A        %7D%0A    %7D%0A%0A    private static void testRandomSortAndInsert(int count) throws Exception %7B%0A        System.out.printf(%22%5CtRandomSortAndInsert (n = %25d)%5Cn%22, count);%0A        PriorityQueue%3CInteger%3E q = new PriorityQueue%3C%3E();%0A        for (int i = 0; i %3C count; i ++) %7B%0A            q.add((int) (Math.random() * Integer.MAX_VALUE));%0A        %7D%0A%0A        if (q.isEmpty()) %7B%0A            throw new Exception(%22Queue is empty%22);%0A        %7D%0A%0A        if (q.size() != count) %7B%0A            throw new Exception(%22Queue size is incorrect%22);%0A        %7D%0A%0A        while (!q.isEmpty()) %7B%0A            int curr = q.poll();%0A            if (q.isEmpty()) break;%0A            int next = q.poll();%0A%0A            if (curr %3E next)
  thr
@@ -1772,32 +1772,33 @@
 t poll order%22);%0A
+%0A
             %7D%0A  
@@ -1797,34 +1797,114 @@
     
-%7D%0A            prev = curr;
+if (Math.random() %3C 0.5) %7B%0A                q.add((int) (Math.random() * Integer.MAX_VALUE));%0A            %7D
 %0A   

Add sort and insert heap test