Apache Lucene open-source search software
LUCENE-8402: Remove invalid identityHashCode assertions in TestPriorityQueue.
Jim Ferenczia19bc5ecb64a
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestPriorityQueue.java b/lucene/core/src/test/org/apache/lucene/util/TestPriorityQueue.javaindex 08a0cf1acd7..d4859cc0a99 100644--- a/lucene/core/src/test/org/apache/lucene/util/TestPriorityQueue.java+++ b/lucene/core/src/test/org/apache/lucene/util/TestPriorityQueue.java@@ -32,13 +32,6 @@ public class TestPriorityQueue extends LuceneTestCase {@Overrideprotected boolean lessThan(Integer a, Integer b) {- if (a.equals(b)) {- assert (a != b);- int hashA = System.identityHashCode(a);- int hashB = System.identityHashCode(b);- assert (hashA != hashB);- return hashA < hashB;- }return (a < b);}@@ -47,93 +40,91 @@ public class TestPriorityQueue extends LuceneTestCase {for (int i = 1; i <= size(); i++) {int parent = i >>> 1;if (parent > 1) {- assertTrue(lessThan((Integer) heapArray[parent],- (Integer) heapArray[i]));+ if (lessThan((Integer) heapArray[parent], (Integer) heapArray[i]) == false) {+ assertEquals(heapArray[parent], heapArray[i]);+ }}}}+ }+ public void testPQ() throws Exception {+ testPQ(atLeast(10000), random());}- public void testPQ() throws Exception {- testPQ(atLeast(10000), random());+ public static void testPQ(int count, Random gen) {+ PriorityQueue<Integer> pq = new IntegerQueue(count);+ int sum = 0, sum2 = 0;++ for (int i = 0; i < count; i++) {+ int next = gen.nextInt();+ sum += next;+ pq.add(next);}- public static void testPQ(int count, Random gen) {- PriorityQueue<Integer> pq = new IntegerQueue(count);- int sum = 0, sum2 = 0;+ // Date end = new Date();- for (int i = 0; i < count; i++)- {- int next = gen.nextInt();- sum += next;- pq.add(next);- }+ // System.out.print(((float)(end.getTime()-start.getTime()) / count) * 1000);+ // System.out.println(" microseconds/put");- // Date end = new Date();+ // start = new Date();- // System.out.print(((float)(end.getTime()-start.getTime()) / count) * 1000);- // System.out.println(" microseconds/put");+ int last = Integer.MIN_VALUE;+ for (int i = 0; i < count; i++) {+ Integer next = pq.pop();+ assertTrue(next.intValue() >= last);+ last = next.intValue();+ sum2 += last;+ }- // start = new Date();+ assertEquals(sum, sum2);+ // end = new Date();- int last = Integer.MIN_VALUE;- for (int i = 0; i < count; i++)- {- Integer next = pq.pop();- assertTrue(next.intValue() >= last);- last = next.intValue();- sum2 += last;- }+ // System.out.print(((float)(end.getTime()-start.getTime()) / count) * 1000);+ // System.out.println(" microseconds/pop");+ }- assertEquals(sum, sum2);- // end = new Date();+ public void testClear() {+ PriorityQueue<Integer> pq = new IntegerQueue(3);+ pq.add(2);+ pq.add(3);+ pq.add(1);+ assertEquals(3, pq.size());+ pq.clear();+ assertEquals(0, pq.size());+ }- // System.out.print(((float)(end.getTime()-start.getTime()) / count) * 1000);- // System.out.println(" microseconds/pop");- }+ public void testFixedSize() {+ PriorityQueue<Integer> pq = new IntegerQueue(3);+ pq.insertWithOverflow(2);+ pq.insertWithOverflow(3);+ pq.insertWithOverflow(1);+ pq.insertWithOverflow(5);+ pq.insertWithOverflow(7);+ pq.insertWithOverflow(1);+ assertEquals(3, pq.size());+ assertEquals((Integer) 3, pq.top());+ }- public void testClear() {- PriorityQueue<Integer> pq = new IntegerQueue(3);- pq.add(2);- pq.add(3);- pq.add(1);- assertEquals(3, pq.size());- pq.clear();- assertEquals(0, pq.size());- }-- public void testFixedSize() {- PriorityQueue<Integer> pq = new IntegerQueue(3);- pq.insertWithOverflow(2);- pq.insertWithOverflow(3);- pq.insertWithOverflow(1);- pq.insertWithOverflow(5);- pq.insertWithOverflow(7);- pq.insertWithOverflow(1);- assertEquals(3, pq.size());- assertEquals((Integer) 3, pq.top());- }-- public void testInsertWithOverflow() {- int size = 4;- PriorityQueue<Integer> pq = new IntegerQueue(size);- Integer i1 = 2;- Integer i2 = 3;- Integer i3 = 1;- Integer i4 = 5;- Integer i5 = 7;- Integer i6 = 1;-- assertNull(pq.insertWithOverflow(i1));- assertNull(pq.insertWithOverflow(i2));- assertNull(pq.insertWithOverflow(i3));- assertNull(pq.insertWithOverflow(i4));- assertTrue(pq.insertWithOverflow(i5) == i3); // i3 should have been dropped- assertTrue(pq.insertWithOverflow(i6) == i6); // i6 should not have been inserted- assertEquals(size, pq.size());- assertEquals((Integer) 2, pq.top());- }+ public void testInsertWithOverflow() {+ int size = 4;+ PriorityQueue<Integer> pq = new IntegerQueue(size);+ Integer i1 = 2;+ Integer i2 = 3;+ Integer i3 = 1;+ Integer i4 = 5;+ Integer i5 = 7;+ Integer i6 = 1;++ assertNull(pq.insertWithOverflow(i1));+ assertNull(pq.insertWithOverflow(i2));+ assertNull(pq.insertWithOverflow(i3));+ assertNull(pq.insertWithOverflow(i4));+ assertTrue(pq.insertWithOverflow(i5) == i3); // i3 should have been dropped+ assertTrue(pq.insertWithOverflow(i6) == i6); // i6 should not have been inserted+ assertEquals(size, pq.size());+ assertEquals((Integer) 2, pq.top());+ }public void testRemovalsAndInsertions() {Random random = random();@@ -193,14 +184,14 @@ public class TestPriorityQueue extends LuceneTestCase {public void testIteratorEmpty() {IntegerQueue queue = new IntegerQueue(3);-+Iterator<Integer> it = queue.iterator();assertFalse(it.hasNext());expectThrows(NoSuchElementException.class, () -> {it.next();});}-+public void testIteratorOne() {IntegerQueue queue = new IntegerQueue(3);@@ -213,7 +204,7 @@ public class TestPriorityQueue extends LuceneTestCase {it.next();});}-+public void testIteratorTwo() {IntegerQueue queue = new IntegerQueue(3);@@ -230,7 +221,6 @@ public class TestPriorityQueue extends LuceneTestCase {});}- @AwaitsFix(bugUrl="https://issues.apache.org/jira/browse/LUCENE-8402")public void testIteratorRandom() {final int maxSize = TestUtil.nextInt(random(), 1, 20);IntegerQueue queue = new IntegerQueue(maxSize);@@ -256,13 +246,13 @@ public class TestPriorityQueue extends LuceneTestCase {public void testMaxIntSize() {expectThrows(IllegalArgumentException.class, () -> {- new PriorityQueue<Boolean>(Integer.MAX_VALUE) {- @Override- public boolean lessThan(Boolean a, Boolean b) {- // uncalled- return true;- }- };- });+ new PriorityQueue<Boolean>(Integer.MAX_VALUE) {+ @Override+ public boolean lessThan(Boolean a, Boolean b) {+ // uncalled+ return true;+ }+ };+ });}}