You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by GitBox <gi...@apache.org> on 2022/03/28 22:02:49 UTC

[GitHub] [lucene] BaurzhanSakhariev commented on a change in pull request #770: Implement method to add all collection elements to a PriorityQueue

BaurzhanSakhariev commented on a change in pull request #770:
URL: https://github.com/apache/lucene/pull/770#discussion_r836886681



##########
File path: lucene/core/src/test/org/apache/lucene/util/TestPriorityQueue.java
##########
@@ -163,6 +163,43 @@ public void testInsertWithOverflow() {
     assertEquals((Integer) 2, pq.top());
   }
 
+  public void testAddAllToEmptyQueue() {
+    int size = 10;
+    List<Integer> list = new ArrayList<>();
+    for (int i = 0; i < size; i++) {
+      list.add(random().nextInt());
+    }
+    IntegerQueue pq = new IntegerQueue(size);
+    pq.addAll(list);
+    pq.checkValidity();
+  }
+
+  public void testAddAllToPartiallyFilledQueue() {
+    IntegerQueue pq = new IntegerQueue(20);
+    List<Integer> list = new ArrayList<>();
+    for (int i = 0; i < 10; i++) {
+      list.add(random().nextInt());
+      pq.add(random().nextInt());
+    }
+    pq.addAll(list);
+    pq.checkValidity();

Review comment:
       I added comparison with JDK `PriorityQueue` as implementations are same and internal states are comparable. 
   
   Wanted to compare with Lucene` PriorityQueue` built by calling `add` in loop:  their internal states were different but both were valid as one can build many valid heaps from the same array (for example, 1,2,3, 1 is root and children: 2/3 or 3/2) - didn't add case with `checkValidity` as it's already tested in other tests.
   
   Not sure how compare with `Set `- internally they are different, the only similarity is that removing top element `size` times gets sorted array - but in case of Set it's already tested API, in case of Lucene PQ - validity is tested and other stuff is also tested given that current PQ implementation works fine for heaps with valid internal array.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org