@Test @SuppressWarnings("deprecation") public void testDeprecatedIteratorAndNot() { MutableRoaringBitmap rb1 = new MutableRoaringBitmap(); MutableRoaringBitmap rb2 = new MutableRoaringBitmap(); List<MutableRoaringBitmap> list = new ArrayList<>(); list.add(rb1); list.add(rb2); rb1.add(200000L, 400000L); // two normal positive ranges rb2.add(300000L, 500000L); // full andNOToverlap is on 200000 to 299999 MutableRoaringBitmap result = ImmutableRoaringBitmap.andNot(rb1, rb2, 250000L, 450000L); MutableRoaringBitmap resultInt = ImmutableRoaringBitmap.andNot(rb1, rb2, 250000, 450000); Assert.assertTrue(result.equals(resultInt)); Assert.assertEquals(50000, result.getCardinality()); // empty ranges get empty result resultInt = ImmutableRoaringBitmap.andNot(rb1, rb2, 300000, 200000); result = ImmutableRoaringBitmap.andNot(rb1, rb2, 300000L, 200000L); Assert.assertTrue(result.equals(resultInt)); Assert.assertEquals(0, resultInt.getCardinality()); }
@Test public void testRangedAndNot() { int length = 1000; int NUM_ITER = 10; Random random = new Random(1234); // please use deterministic tests for (int test = 0; test < 50; ++test) { final MutableRoaringBitmap rb1 = new MutableRoaringBitmap(); final MutableRoaringBitmap rb2 = new MutableRoaringBitmap(); Set<Integer> set1 = new HashSet<>(); Set<Integer> set2 = new HashSet<>(); int numBitsToSet = length / 2; for (int i = 0; i < numBitsToSet; i++) { int val1 = random.nextInt(length); int val2 = random.nextInt(length); rb1.add(val1); set1.add(val1); rb2.add(val2); set2.add(val2); } Set<Integer> andNotSet = new TreeSet<>(); for (int i : set1) { if (!set2.contains(i)) { andNotSet.add(i); } } for (int iter = 0; iter < NUM_ITER; iter++) { int rangeStart = random.nextInt(length - 1); // +1 to ensure rangeEnd >rangeStart, may int rangeLength = random.nextInt(length - rangeStart) + 1; int rangeEnd = rangeStart + rangeLength; Set<Integer> expectedResultSet = new TreeSet<>(); for (int i = rangeStart; i < rangeEnd; i++) { if (andNotSet.contains(i)) { expectedResultSet.add(i); } } MutableRoaringBitmap result = ImmutableRoaringBitmap.andNot(rb1, rb2, rangeStart, rangeEnd); Set<Integer> actualResultSet = new TreeSet<>(); IntIterator intIterator = result.getIntIterator(); while (intIterator.hasNext()) { actualResultSet.add(intIterator.next()); } Assert.assertEquals(expectedResultSet, actualResultSet); } } }