1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
/*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 2002,2010 Oracle. All rights reserved.
*
* $Id: BitMapTest.java,v 1.7.2.2 2010/01/04 15:30:48 cwl Exp $
*/
package com.sleepycat.je.utilint;
import junit.framework.TestCase;
public class BitMapTest extends TestCase {
public void testSegments() {
BitMap bmap = new BitMap();
int startBit = 15;
int endBit = 62;
assertEquals(0, bmap.cardinality());
assertEquals(0, bmap.getNumSegments());
assertFalse(bmap.get(1001L));
assertEquals(0, bmap.getNumSegments());
/* set a bit in different segments. */
for (int i = startBit; i <= endBit; i++) {
long index = 1L << i;
index += 17;
bmap.set(index);
}
assertEquals((endBit - startBit +1), bmap.cardinality());
assertEquals((endBit - startBit + 1), bmap.getNumSegments());
/* should be set. */
for (int i = startBit; i <= endBit; i++) {
long index = 1L << i;
index += 17;
assertTrue(bmap.get(index));
}
/* should be clear. */
for (int i = startBit; i <= endBit; i++) {
long index = 7 + (1L << i);
assertFalse(bmap.get(index));
}
/* checking for non-set bits should not create more segments. */
assertEquals((endBit - startBit +1), bmap.cardinality());
assertEquals((endBit - startBit + 1), bmap.getNumSegments());
}
public void testNegative() {
BitMap bMap = new BitMap();
try {
bMap.set(-300);
fail("should have thrown exception");
} catch (IndexOutOfBoundsException expected) {
}
}
}
|