public void rTest(final int N) { System.out.println("rtest N=" + N); for (int gap = 1; gap <= 65536; gap *= 2) { final BitSet bs1 = new BitSet(); final RoaringBitmap rb1 = new RoaringBitmap(); for (int x = 0; x <= N; ++x) { bs1.set(x); rb1.add(x); } if (bs1.cardinality() != rb1.getCardinality()) throw new RuntimeException("different card"); if (!equals(bs1, rb1)) throw new RuntimeException("basic bug"); for (int offset = 1; offset <= gap; offset *= 2) { final BitSet bs2 = new BitSet(); final RoaringBitmap rb2 = new RoaringBitmap(); for (int x = 0; x <= N; ++x) { bs2.set(x + offset); rb2.add(x + offset); } if (bs2.cardinality() != rb2.getCardinality()) throw new RuntimeException("different card"); if (!equals(bs2, rb2)) throw new RuntimeException("basic bug"); BitSet clonebs1; // testing AND clonebs1 = (BitSet) bs1.clone(); clonebs1.and(bs2); if (!equals(clonebs1, RoaringBitmap.and(rb1, rb2))) throw new RuntimeException("bug and"); { final RoaringBitmap t = rb1.clone(); t.and(rb2); if (!equals(clonebs1, t)) throw new RuntimeException("bug inplace and"); if (!t.equals(RoaringBitmap.and(rb1, rb2))) { System.out.println( t.highlowcontainer.getContainerAtIndex(0).getClass().getCanonicalName()); System.out.println( RoaringBitmap.and(rb1, rb2) .highlowcontainer .getContainerAtIndex(0) .getClass() .getCanonicalName()); throw new RuntimeException("bug inplace and"); } } // testing OR clonebs1 = (BitSet) bs1.clone(); clonebs1.or(bs2); if (!equals(clonebs1, RoaringBitmap.or(rb1, rb2))) throw new RuntimeException("bug or"); { final RoaringBitmap t = rb1.clone(); t.or(rb2); if (!equals(clonebs1, t)) throw new RuntimeException("bug or"); if (!t.equals(RoaringBitmap.or(rb1, rb2))) throw new RuntimeException("bug or"); if (!t.toString().equals(RoaringBitmap.or(rb1, rb2).toString())) throw new RuntimeException("bug or"); } // testing XOR clonebs1 = (BitSet) bs1.clone(); clonebs1.xor(bs2); if (!equals(clonebs1, RoaringBitmap.xor(rb1, rb2))) { throw new RuntimeException("bug xor"); } { final RoaringBitmap t = rb1.clone(); t.xor(rb2); if (!equals(clonebs1, t)) throw new RuntimeException("bug xor"); if (!t.equals(RoaringBitmap.xor(rb1, rb2))) throw new RuntimeException("bug xor"); } // testing NOTAND clonebs1 = (BitSet) bs1.clone(); clonebs1.andNot(bs2); if (!equals(clonebs1, RoaringBitmap.andNot(rb1, rb2))) { throw new RuntimeException("bug andnot"); } clonebs1 = (BitSet) bs2.clone(); clonebs1.andNot(bs1); if (!equals(clonebs1, RoaringBitmap.andNot(rb2, rb1))) { throw new RuntimeException("bug andnot"); } { final RoaringBitmap t = rb2.clone(); t.andNot(rb1); if (!equals(clonebs1, t)) { throw new RuntimeException("bug inplace andnot"); } final RoaringBitmap g = RoaringBitmap.andNot(rb2, rb1); if (!equals(clonebs1, g)) { throw new RuntimeException("bug andnot"); } if (!t.equals(g)) throw new RuntimeException("bug"); } clonebs1 = (BitSet) bs1.clone(); clonebs1.andNot(bs2); if (!equals(clonebs1, RoaringBitmap.andNot(rb1, rb2))) { throw new RuntimeException("bug andnot"); } { final RoaringBitmap t = rb1.clone(); t.andNot(rb2); if (!equals(clonebs1, t)) { throw new RuntimeException("bug andnot"); } final RoaringBitmap g = RoaringBitmap.andNot(rb1, rb2); if (!equals(clonebs1, g)) { throw new RuntimeException("bug andnot"); } if (!t.equals(g)) throw new RuntimeException("bug"); } } } }