private static boolean equals(MergeState.DocMap map1, MergeState.DocMap map2) {
   if (map1.maxDoc() != map2.maxDoc()) {
     return false;
   }
   for (int i = 0; i < map1.maxDoc(); ++i) {
     if (map1.get(i) != map2.get(i)) {
       return false;
     }
   }
   return true;
 }
  public void testBuildDocMap() {
    final int maxDoc = TestUtil.nextInt(random(), 1, 128);
    final int numDocs = TestUtil.nextInt(random(), 0, maxDoc);
    final int numDeletedDocs = maxDoc - numDocs;
    final FixedBitSet liveDocs = new FixedBitSet(maxDoc);
    for (int i = 0; i < numDocs; ++i) {
      while (true) {
        final int docID = random().nextInt(maxDoc);
        if (!liveDocs.get(docID)) {
          liveDocs.set(docID);
          break;
        }
      }
    }

    final MergeState.DocMap docMap = MergeState.DocMap.build(maxDoc, liveDocs);

    assertEquals(maxDoc, docMap.maxDoc());
    assertEquals(numDocs, docMap.numDocs());
    assertEquals(numDeletedDocs, docMap.numDeletedDocs());
    // assert the mapping is compact
    for (int i = 0, del = 0; i < maxDoc; ++i) {
      if (!liveDocs.get(i)) {
        assertEquals(-1, docMap.get(i));
        ++del;
      } else {
        assertEquals(i - del, docMap.get(i));
      }
    }
  }