boolean validate(MappeableBitmapContainer bc, MappeableArrayContainer ac) { // Checking the cardinalities of each container if (bc.getCardinality() != ac.getCardinality()) { System.out.println("cardinality differs"); return false; } // Checking that the two containers contain the same values int counter = 0; int i = bc.nextSetBit(0); while (i >= 0) { ++counter; if (!ac.contains((short) i)) { System.out.println("content differs"); System.out.println(bc); System.out.println(ac); return false; } i = bc.nextSetBit(i + 1); } // checking the cardinality of the BitmapContainer return counter == bc.getCardinality(); }
@Test public void BitmapContainerCardinalityTest() { final MappeableBitmapContainer ac = new MappeableBitmapContainer(); for (short k = 0; k < 100; ++k) { ac.add(k); Assert.assertEquals(ac.getCardinality(), k + 1); } for (short k = 0; k < 100; ++k) { ac.add(k); Assert.assertEquals(ac.getCardinality(), 100); } }
@Test public void bitmaptest() { final MappeableBitmapContainer rr = new MappeableBitmapContainer(); rr.add((short) 110); rr.add((short) 114); rr.add((short) 115); final short[] array = new short[3]; int pos = 0; for (final short i : rr) array[pos++] = i; Assert.assertEquals(array[0], (short) 110); Assert.assertEquals(array[1], (short) 114); Assert.assertEquals(array[2], (short) 115); }
@Test public void ContainerFactory() { MappeableBitmapContainer bc1, bc2, bc3; MappeableArrayContainer ac1, ac2, ac3; bc1 = new MappeableBitmapContainer(); bc2 = new MappeableBitmapContainer(); bc3 = new MappeableBitmapContainer(); ac1 = new MappeableArrayContainer(); ac2 = new MappeableArrayContainer(); ac3 = new MappeableArrayContainer(); for (short i = 0; i < 5000; i++) bc1.add((short) (i * 70)); for (short i = 0; i < 5000; i++) bc2.add((short) (i * 70)); for (short i = 0; i < 5000; i++) bc3.add((short) (i * 70)); for (short i = 0; i < 4000; i++) ac1.add((short) (i * 50)); for (short i = 0; i < 4000; i++) ac2.add((short) (i * 50)); for (short i = 0; i < 4000; i++) ac3.add((short) (i * 50)); MappeableBitmapContainer rbc; rbc = ac1.clone().toBitmapContainer(); Assert.assertTrue(validate(rbc, ac1)); rbc = ac2.clone().toBitmapContainer(); Assert.assertTrue(validate(rbc, ac2)); rbc = ac3.clone().toBitmapContainer(); Assert.assertTrue(validate(rbc, ac3)); }