aherbert commented on a change in pull request #258: URL: https://github.com/apache/commons-collections/pull/258#discussion_r804943880
########## File path: src/test/java/org/apache/commons/collections4/bloomfilter/hasher/AbstractHasherTest.java ########## @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.collections4.bloomfilter.hasher; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.apache.commons.collections4.bloomfilter.AbstractIndexProducerTest; +import org.apache.commons.collections4.bloomfilter.IndexProducer; +import org.apache.commons.collections4.bloomfilter.Shape; +import org.junit.Test; + +public abstract class AbstractHasherTest extends AbstractIndexProducerTest { + + protected abstract Hasher createHasher(); + + protected abstract Hasher createEmptyHasher(); + + /** + * The shape of the Hashers filters for testing. + * <ul> + * <li>Hash functions (k) = 17 + * <li>Number of bits (m) = 72 + * </ul> + * @return the testing shape. + */ + protected final Shape getTestShape() { + return Shape.fromKM(17, 72); + } + + @Override + protected IndexProducer createProducer() { + return createHasher().indices(getTestShape()); + } + + @Override + protected IndexProducer createEmptyProducer() { + return createEmptyHasher().indices(getTestShape()); + } + + @Test + public void testSize() { + assertEquals(1, createHasher().size()); + assertEquals(0, createEmptyHasher().size()); + } + + @Test + public void testIsEmpty() { + assertFalse(createHasher().isEmpty()); + assertTrue(createEmptyHasher().isEmpty()); + } +} Review comment: If it functions as per `HasherCollection` called with `uniqueIndices` then what is the point? IIUC a hasher should return (up to accounting for duplicates) `k` indices where `k` is specified by the shape. If it returns more then all the probability assumptions made when constructing the filter shape are void. I build a bloom filter to store up to 3000 items with a FP probability of 1e-6. You send me 1000 SingleItemHasherCollections, each composed of 10 Hashers then my filter will be over filled and will not provide the desired FP rate. -- 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]
