Code example for BitSet

Methods: clear, nextClearBit, set, size

0
    /** 
     * @tests java.util.BitSet#nextClearBit(int) 
     */ 
    public void test_nextClearBitI() { 
        // Test for method int java.util.BitSet.nextSetBit() 
        BitSet bs = new BitSet(500);
        bs.set(0, bs.size() - 1); // ensure all the bits from 0 to bs.size()
                                    // -1 
        bs.set(bs.size() - 1); // are set to true
        bs.clear(5);
        bs.clear(32);
        bs.clear(63);
        bs.clear(64);
        bs.clear(71, 110);
        bs.clear(127, 130);
        bs.clear(193);
        bs.clear(450);
        try { 
            bs.nextClearBit(-1);
            fail("Expected IndexOutOfBoundsException for negative index");
        } catch (IndexOutOfBoundsException e) {
            // correct behavior 
        } 
        assertEquals("nextClearBit() returned the wrong value", 5, bs
                .nextClearBit(0));
        assertEquals("nextClearBit() returned the wrong value", 5, bs
                .nextClearBit(5));
        assertEquals("nextClearBit() returned the wrong value", 32, bs
                .nextClearBit(6));
        assertEquals("nextClearBit() returned the wrong value", 32, bs
                .nextClearBit(32));
        assertEquals("nextClearBit() returned the wrong value", 63, bs
                .nextClearBit(33));
 
        // boundary tests 
        assertEquals("nextClearBit() returned the wrong value", 63, bs
                .nextClearBit(63));
        assertEquals("nextClearBit() returned the wrong value", 64, bs