mirror of https://github.com/apache/lucene.git
LUCENE-8402: Remove invalid identityHashCode assertions in TestPriorityQueue.
This commit is contained in:
parent
f6e9d00b90
commit
a19bc5ecb6
|
@ -32,13 +32,6 @@ public class TestPriorityQueue extends LuceneTestCase {
|
|||
|
||||
@Override
|
||||
protected 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");
|
||||
|
||||
// start = 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;
|
||||
}
|
||||
|
||||
assertEquals(sum, sum2);
|
||||
// end = new Date();
|
||||
|
||||
// System.out.print(((float)(end.getTime()-start.getTime()) / count) * 1000);
|
||||
// System.out.println(" microseconds/pop");
|
||||
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;
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
assertEquals(sum, sum2);
|
||||
// end = new Date();
|
||||
|
||||
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());
|
||||
}
|
||||
// System.out.print(((float)(end.getTime()-start.getTime()) / count) * 1000);
|
||||
// System.out.println(" microseconds/pop");
|
||||
}
|
||||
|
||||
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;
|
||||
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());
|
||||
}
|
||||
|
||||
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 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 testRemovalsAndInsertions() {
|
||||
Random random = random();
|
||||
|
@ -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;
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue