public void testSanityRandomUnsetBit(){
  final int max=atLeast(100);
  BitSet bits=new BitSet(max + 1);
  for (int i=0; i <= max; i++) {
    assertFalse("how is bitset already full? iter=" + i + " card="+ bits.cardinality()+ "/max="+ max,bits.cardinality() == max + 1);
    final int nextBit=randomUnsetBit(random(),bits,max);
    assertTrue("nextBit shouldn't be negative yet: " + nextBit,0 <= nextBit);
    assertTrue("nextBit can't exceed max: " + nextBit,nextBit <= max);
    assertFalse("expect unset: " + nextBit,bits.get(nextBit));
    bits.set(nextBit);
  }
  assertEquals("why isn't bitset full?",max + 1,bits.cardinality());
  final int firstClearBit=bits.nextClearBit(0);
  assertTrue("why is there a clear bit? = " + firstClearBit,max < firstClearBit);
  assertEquals("why is a bit set above max?",-1,bits.nextSetBit(max + 1));
  assertEquals("wrong nextBit at end of all iters",-1,randomUnsetBit(random(),bits,max));
  assertEquals("wrong nextBit at redundant end of all iters",-1,randomUnsetBit(random(),bits,max));
}

public void testSanityRandomUnsetBit ( ) { final int max = atLeast ( 100 ) ; BitSet bits = new BitSet ( max + 1 ) ; for ( int i = 0 ; i <= max ; i ++ ) { assertFalse ( "how is bitset already full? iter=" + i + " card=" + bits . cardinality ( ) + "/max=" + max , bits . cardinality ( ) == max + 1 ) ; final int nextBit = randomUnsetBit ( random ( ) , bits , max ) ; assertTrue ( "nextBit shouldn't be negative yet: " + nextBit , 0 <= nextBit ) ; assertTrue ( "nextBit can't exceed max: " + nextBit , nextBit <= max ) ; assertFalse ( "expect unset: " + nextBit , bits . get ( nextBit ) ) ; bits . set ( nextBit ) ; } assertEquals ( "why isn't bitset full?" , max + 1 , bits . cardinality ( ) ) ; final int firstClearBit = bits . nextClearBit ( 0 ) ; assertTrue ( "why is there a clear bit? = " + firstClearBit , max < firstClearBit ) ; assertEquals ( "why is a bit set above max?" , - 1 , bits . nextSetBit ( max + 1 ) ) ; assertEquals ( "wrong nextBit at end of all iters" , - 1 , randomUnsetBit ( random ( ) , bits , max ) ) ; assertEquals ( "wrong nextBit at redundant end of all iters" , - 1 , randomUnsetBit ( random ( ) , bits , max ) ) ; }
sanity check that randomunsetbit works as expected
