Claudenw commented on code in PR #258:
URL:
https://github.com/apache/commons-collections/pull/258#discussion_r897750551
##########
src/test/java/org/apache/commons/collections4/bloomfilter/SetOperationsTest.java:
##########
@@ -17,338 +17,265 @@
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.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 = Shape.fromKM(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);
-
- 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);
-
- assertEquals(0.514928749927334, SetOperations.cosineDistance(filter1,
filter2), 0.000000000000001);
- assertEquals(0.514928749927334, SetOperations.cosineDistance(filter2,
filter1), 0.000000000000001);
- }
-
- /**
- * Tests that the Cosine distance is correctly calculated when one or
- * both filters are empty
- */
- @Test
- public final void cosineDistanceTest_NoValues() {
- final BloomFilter filter1 = new HasherBloomFilter(shape);
- final BloomFilter filter2 = new HasherBloomFilter(shape);
- // build a filter
- final List<Integer> lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17);
- final Hasher hasher = new StaticHasher(lst.iterator(), shape);
- final BloomFilter filter3 = new HasherBloomFilter(hasher, shape);
-
- assertEquals(1.0, SetOperations.cosineDistance(filter1, filter2),
0.0001);
- assertEquals(1.0, SetOperations.cosineDistance(filter2, filter1),
0.0001);
- assertEquals(1.0, SetOperations.cosineDistance(filter1, filter3),
0.0001);
- assertEquals(1.0, SetOperations.cosineDistance(filter3, filter1),
0.0001);
+ public final void testCosineDistance() {
+
+ BloomFilter filter1 = new SimpleBloomFilter(shape, from1);
+ BloomFilter filter2 = new SimpleBloomFilter(shape, from1);
+
+ int dotProduct = /* [1..17] & [1..17] = [1..17] = */ 17;
Review Comment:
done
--
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]