Skip to content

Commit

Permalink
Remove duplicate test code (#13982)
Browse files Browse the repository at this point in the history
The only diff between doIterate1  and doIterate2  is bb < b.length() in doIterate1 , but this condition is always true, so we should remove it
  • Loading branch information
LuXugang committed Nov 15, 2024
1 parent 98918aa commit a5d44d8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 29 deletions.
2 changes: 1 addition & 1 deletion lucene/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Build

Other
---------------------
(No changes)
* GITHUB#13982: Remove duplicate test code. (Lu Xugang)

======================== Lucene 10.0.1 =======================

Expand Down
36 changes: 8 additions & 28 deletions lucene/core/src/test/org/apache/lucene/util/TestFixedBitSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,26 +98,7 @@ void doPrevSetBit(java.util.BitSet a, FixedBitSet b) {
}

// test interleaving different FixedBitSetIterator.next()/skipTo()
void doIterate(java.util.BitSet a, FixedBitSet b, int mode) throws IOException {
if (mode == 1) doIterate1(a, b);
if (mode == 2) doIterate2(a, b);
}

void doIterate1(java.util.BitSet a, FixedBitSet b) throws IOException {
assertEquals(a.cardinality(), b.cardinality());
int aa = -1, bb = -1;
DocIdSetIterator iterator = new BitSetIterator(b, 0);
do {
aa = a.nextSetBit(aa + 1);
bb =
(bb < b.length() && random().nextBoolean())
? iterator.nextDoc()
: iterator.advance(bb + 1);
assertEquals(aa == -1 ? DocIdSetIterator.NO_MORE_DOCS : aa, bb);
} while (aa >= 0);
}

void doIterate2(java.util.BitSet a, FixedBitSet b) throws IOException {
void doIterate(java.util.BitSet a, FixedBitSet b) throws IOException {
assertEquals(a.cardinality(), b.cardinality());
int aa = -1, bb = -1;
DocIdSetIterator iterator = new BitSetIterator(b, 0);
Expand All @@ -128,7 +109,7 @@ void doIterate2(java.util.BitSet a, FixedBitSet b) throws IOException {
} while (aa >= 0);
}

void doRandomSets(int maxSize, int iter, int mode) throws IOException {
void doRandomSets(int maxSize, int iter) throws IOException {
java.util.BitSet a0 = null;
FixedBitSet b0 = null;

Expand Down Expand Up @@ -181,7 +162,7 @@ void doRandomSets(int maxSize, int iter, int mode) throws IOException {
FixedBitSet bb = b.clone();
bb.flip(fromIndex, toIndex);

doIterate(aa, bb, mode); // a problem here is from flip or doIterate
doIterate(aa, bb); // a problem here is from flip or doIterate

fromIndex = random().nextInt(sz / 2);
toIndex = fromIndex + random().nextInt(sz - fromIndex);
Expand Down Expand Up @@ -230,10 +211,10 @@ void doRandomSets(int maxSize, int iter, int mode) throws IOException {
assertEquals(a0.cardinality(), b0.cardinality());
assertEquals(a_or.cardinality(), b_or.cardinality());

doIterate(a_and, b_and, mode);
doIterate(a_or, b_or, mode);
doIterate(a_andn, b_andn, mode);
doIterate(a_xor, b_xor, mode);
doIterate(a_and, b_and);
doIterate(a_or, b_or);
doIterate(a_andn, b_andn);
doIterate(a_xor, b_xor);

assertEquals(a_and.cardinality(), b_and.cardinality());
assertEquals(a_or.cardinality(), b_or.cardinality());
Expand All @@ -250,8 +231,7 @@ void doRandomSets(int maxSize, int iter, int mode) throws IOException {
// larger testsuite.
public void testSmall() throws IOException {
final int iters = TEST_NIGHTLY ? atLeast(1000) : 100;
doRandomSets(atLeast(1200), iters, 1);
doRandomSets(atLeast(1200), iters, 2);
doRandomSets(atLeast(1200), iters);
}

// uncomment to run a bigger test (~2 minutes).
Expand Down

0 comments on commit a5d44d8

Please sign in to comment.