}
/** Assert that the content of the {@link DocIdSet} is the same as the content of the {@link BitSet}. */
public void assertEquals(int numBits, BitSet ds1, T ds2) throws IOException {
// nextDoc
DocIdSetIterator it2 = ds2.iterator();
if (it2 == null) {
assertEquals(-1, ds1.nextSetBit(0));
} else {
assertEquals(-1, it2.docID());
for (int doc = ds1.nextSetBit(0); doc != -1; doc = ds1.nextSetBit(doc + 1)) {
assertEquals(doc, it2.nextDoc());
assertEquals(doc, it2.docID());
}
assertEquals(DocIdSetIterator.NO_MORE_DOCS, it2.nextDoc());
assertEquals(DocIdSetIterator.NO_MORE_DOCS, it2.docID());
}
// nextDoc / advance
it2 = ds2.iterator();
if (it2 == null) {
assertEquals(-1, ds1.nextSetBit(0));
} else {
for (int doc = -1; doc != DocIdSetIterator.NO_MORE_DOCS;) {
if (random().nextBoolean()) {
doc = ds1.nextSetBit(doc + 1);
if (doc == -1) {
doc = DocIdSetIterator.NO_MORE_DOCS;
}
assertEquals(doc, it2.nextDoc());
assertEquals(doc, it2.docID());
} else {
final int target = doc + 1 + random().nextInt(random().nextBoolean() ? 64 : Math.max(numBits / 8, 1));
doc = ds1.nextSetBit(target);
if (doc == -1) {
doc = DocIdSetIterator.NO_MORE_DOCS;
}
assertEquals(doc, it2.advance(target));
assertEquals(doc, it2.docID());
}
}
}
// bits()
final Bits bits = ds2.bits();
if (bits != null) {
// test consistency between bits and iterator
it2 = ds2.iterator();
for (int previousDoc = -1, doc = it2.nextDoc(); ; previousDoc = doc, doc = it2.nextDoc()) {
final int max = doc == DocIdSetIterator.NO_MORE_DOCS ? bits.length() : doc;
for (int i = previousDoc + 1; i < max; ++i) {
assertEquals(false, bits.get(i));
}
if (doc == DocIdSetIterator.NO_MORE_DOCS) {