Claudenw commented on a change in pull request #258:
URL:
https://github.com/apache/commons-collections/pull/258#discussion_r798327502
##########
File path:
src/test/java/org/apache/commons/collections4/bloomfilter/SetOperationsTest.java
##########
@@ -17,103 +17,50 @@
package org.apache.commons.collections4.bloomfilter;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
-import java.util.List;
import java.util.Arrays;
-import org.apache.commons.collections4.bloomfilter.hasher.HashFunctionIdentity;
-import org.apache.commons.collections4.bloomfilter.hasher.Hasher;
-import org.apache.commons.collections4.bloomfilter.hasher.Shape;
-import org.apache.commons.collections4.bloomfilter.hasher.StaticHasher;
+
+import org.apache.commons.collections4.bloomfilter.hasher.HasherCollection;
+import org.apache.commons.collections4.bloomfilter.hasher.SimpleHasher;
import org.junit.jupiter.api.Test;
/**
* Test {@link SetOperations}.
*/
public class SetOperationsTest {
- private final HashFunctionIdentity testFunction = new
HashFunctionIdentity() {
-
- @Override
- public String getName() {
- return "Test Function";
- }
-
- @Override
- public ProcessType getProcessType() {
- return ProcessType.CYCLIC;
- }
-
- @Override
- public String getProvider() {
- return "Apache Commons Collection Tests";
- }
-
- @Override
- public long getSignature() {
- return 0;
- }
-
- @Override
- public Signedness getSignedness() {
- return Signedness.SIGNED;
- }
- };
-
- private final Shape shape = new Shape(testFunction, 3, 72, 17);
-
- @Test
- public void testDifferentShapesThrows() {
- final List<Integer> lst = Arrays.asList(1, 2);
- final Hasher hasher = new StaticHasher(lst.iterator(), shape);
- final BloomFilter filter1 = new HasherBloomFilter(hasher, shape);
-
- final Shape shape2 = new Shape(testFunction, 3, 72, 18);
- final List<Integer> lst2 = Arrays.asList(2, 3);
- final Hasher hasher2 = new StaticHasher(lst2.iterator(), shape2);
- final BloomFilter filter2 = new HasherBloomFilter(hasher2, shape2);
-
- try {
- SetOperations.cosineDistance(filter1, filter2);
- fail("Expected an IllegalArgumentException");
- } catch (final IllegalArgumentException expected) {
- // Ignore
- }
- }
+ protected final SimpleHasher from1 = new SimpleHasher(1, 1);
+ protected final long from1Value = 0x3FFFEL;
+ protected final SimpleHasher from11 = new SimpleHasher(11, 1);
+ protected final long from11Value = 0xFFFF800L;
+ protected final HasherCollection bigHasher = new HasherCollection(from1,
from11);
+ protected final long bigHashValue = 0xFFFFFFEL;
+ private final Shape shape = new Shape(17, 72);
/**
* Tests that the Cosine similarity is correctly calculated.
*/
@Test
public final void cosineDistanceTest() {
- List<Integer> lst = Arrays.asList(1, 2);
- Hasher hasher = new StaticHasher(lst.iterator(), shape);
- BloomFilter filter1 = new HasherBloomFilter(hasher, shape);
-
- List<Integer> lst2 = Arrays.asList(2, 3);
- Hasher hasher2 = new StaticHasher(lst2.iterator(), shape);
- BloomFilter filter2 = new HasherBloomFilter(hasher2, shape);
-
- assertEquals(0.5, SetOperations.cosineDistance(filter1, filter2),
0.0001);
- assertEquals(0.5, SetOperations.cosineDistance(filter2, filter1),
0.0001);
-
- lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17);
- hasher = new StaticHasher(lst.iterator(), shape);
- filter1 = new HasherBloomFilter(hasher, shape);
- lst2 = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17);
- hasher2 = new StaticHasher(lst2.iterator(), shape);
- filter2 = new HasherBloomFilter(hasher2, shape);
+ BloomFilter filter1 = new SimpleBloomFilter(shape, from1);
+ BloomFilter filter2 = new SimpleBloomFilter(shape, from1);
assertEquals(0.0, SetOperations.cosineDistance(filter1, filter2),
0.0001);
assertEquals(0.0, SetOperations.cosineDistance(filter2, filter1),
0.0001);
- lst2 = Arrays.asList(10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
22, 23, 24, 25);
- hasher2 = new StaticHasher(lst2.iterator(), shape);
- filter2 = new HasherBloomFilter(hasher2, shape);
+ Shape shape2 = new Shape(2, 72);
+ filter1 = new SimpleBloomFilter(shape2, from1);
+ filter2 = new SimpleBloomFilter(shape2, new SimpleHasher(2, 1));
- assertEquals(0.514928749927334, SetOperations.cosineDistance(filter1,
filter2), 0.000000000000001);
- assertEquals(0.514928749927334, SetOperations.cosineDistance(filter2,
filter1), 0.000000000000001);
+ assertEquals(0.5, SetOperations.cosineDistance(filter1, filter2),
0.0001);
+ assertEquals(0.5, SetOperations.cosineDistance(filter2, filter1),
0.0001);
+
+ filter1 = new SimpleBloomFilter(shape, from1);
+ filter2 = new SimpleBloomFilter(shape, from11);
+
+ assertEquals(0.58823529, SetOperations.cosineDistance(filter1,
filter2), 0.00000001);
Review comment:
calculations now provided and explained in the code
--
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]