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