1 8 9 package com.sleepycat.je.utilint; 10 11 import junit.framework.TestCase; 12 13 14 public class BitMapTest extends TestCase { 15 16 public void testSegments() { 17 18 BitMap bmap = new BitMap(); 19 int startBit = 15; 20 int endBit = 62; 21 assertEquals(0, bmap.cardinality()); 22 assertEquals(0, bmap.getNumSegments()); 23 24 assertFalse(bmap.get(1001L)); 25 assertEquals(0, bmap.getNumSegments()); 26 27 28 for (int i = startBit; i <= endBit; i++) { 29 long index = 1L << i; 30 index += 17; 31 bmap.set(index); 32 } 33 34 assertEquals((endBit - startBit +1), bmap.cardinality()); 35 assertEquals((endBit - startBit + 1), bmap.getNumSegments()); 36 37 38 for (int i = startBit; i <= endBit; i++) { 39 long index = 1L << i; 40 index += 17; 41 assertTrue(bmap.get(index)); 42 } 43 44 45 for (int i = startBit; i <= endBit; i++) { 46 long index = 7 + (1L << i); 47 assertFalse(bmap.get(index)); 48 } 49 50 51 assertEquals((endBit - startBit +1), bmap.cardinality()); 52 assertEquals((endBit - startBit + 1), bmap.getNumSegments()); 53 } 54 55 public void testNegative() { 56 BitMap bMap = new BitMap(); 57 58 try { 59 bMap.set(-300); 60 fail("should have thrown exception"); 61 } catch (IndexOutOfBoundsException expected) { 62 } 63 } 64 } 65 | Popular Tags |