Claudenw commented on code in PR #358:
URL:
https://github.com/apache/commons-collections/pull/358#discussion_r1032802990
##########
src/test/java/org/apache/commons/collections4/bloomfilter/DefaultBloomFilterTest.java:
##########
@@ -67,6 +68,110 @@ public void testHasherBasedMergeWithDifferingSparseness() {
.forEachBitMapPair(bf1, (x, y) -> x == y));
}
+ @Test
+ public void testEstimateNWithBrokenCardinality() {
+ // build a filter
+ BloomFilter filter1 = TestingHashers.populateEntireFilter(new
BrokenCardinality(getTestShape()));
+ assertThrows(IllegalArgumentException.class, ()->filter1.estimateN());
+ }
+
+ @Test
+ public void testLargeBitmapAsArray() {
+ Shape s = Shape.fromKM(1, Integer.MAX_VALUE);
+ // create a very large filter with Integer.MAX_VALUE-1 bit set.
+ BloomFilter bf1 = new SimpleBloomFilter(s);
+ bf1.merge(new BitMapProducer() {
+ @Override
+ public boolean forEachBitMap(LongPredicate predicate) {
+ int limit = Integer.MAX_VALUE-1;
+ while (limit>64) {
+ predicate.test(0xFFFFFFFFFFFFFFFFL);
+ limit -= 64;
+ }
+ long last = 0L;
+ for (int i=0; i<limit; i++) {
+ last |= BitMap.getLongBit(i);
+ }
+ predicate.test(last);
+ return true;
+ }} );
+ // the actual result of the calculation is: 46144189292
+ long[] ary = bf1.asBitMapArray();
+ for (int i=0; i<ary.length-2; i++) {
+ assertEquals(0xFFFFFFFFFFFFFFFFL, ary[i]);
+ }
+ int lastBits = (Integer.MAX_VALUE-1) % 64;
+ long last = 0L;
+ for (int i=0; i<lastBits; i++) {
+ last |= BitMap.getLongBit(i);
+ }
+ assertEquals(last, ary[ary.length-1]);
+ }
+
+ @Test
+ public void testEstimateLargeN() {
+ Shape s = Shape.fromKM(1, Integer.MAX_VALUE);
+ // create a very large filter with Integer.MAX_VALUE-1 bit set.
+ BloomFilter bf1 = new SimpleBloomFilter(s);
+ bf1.merge(new BitMapProducer() {
+ @Override
+ public boolean forEachBitMap(LongPredicate predicate) {
+ int limit = Integer.MAX_VALUE-1;
+ while (limit>64) {
+ predicate.test(0xFFFFFFFFFFFFFFFFL);
+ limit -= 64;
+ }
+ long last = 0L;
+ for (int i=0; i<limit; i++) {
+ last |= BitMap.getLongBit(i);
+ }
+ predicate.test(last);
+ return true;
+ }} );
+ // the actual result of the calculation is: 46144189292
Review Comment:
It is noted here so that the test is understood to be verifying that larger
than max int are returned as max int..
Comment updated.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]