You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ah...@apache.org on 2020/02/18 16:36:35 UTC

[commons-collections] 05/06: Test edge case in SetOperations when shapes are different.

This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-collections.git

commit 0f78a9c9e806221f101557dd1b03bb4f0c8fb326
Author: aherbert <a....@sussex.ac.uk>
AuthorDate: Tue Feb 18 13:56:59 2020 +0000

    Test edge case in SetOperations when shapes are different.
---
 .../collections4/bloomfilter/SetOperationsTest.java  | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/SetOperationsTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/SetOperationsTest.java
index d492800..9b112d6 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/SetOperationsTest.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/SetOperationsTest.java
@@ -24,6 +24,7 @@ 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.Assert;
 import org.junit.Test;
 
 /**
@@ -61,6 +62,25 @@ public class SetOperationsTest {
 
     private final Shape shape = new Shape(testFunction, 3, 72, 17);
 
+    @Test
+    public void testDifferentShapesThrows() {
+        List<Integer> lst = Arrays.asList(1, 2);
+        Hasher hasher = new StaticHasher(lst.iterator(), shape);
+        BloomFilter filter1 = new HasherBloomFilter(hasher, shape);
+
+        final Shape shape2 = new Shape(testFunction, 3, 72, 18);
+        List<Integer> lst2 = Arrays.asList(2, 3);
+        Hasher hasher2 = new StaticHasher(lst2.iterator(), shape2);
+        BloomFilter filter2 = new HasherBloomFilter(hasher2, shape2);
+
+        try {
+            SetOperations.cosineDistance(filter1, filter2);
+            Assert.fail("Expected an IllegalArgumentException");
+        } catch (IllegalArgumentException expected) {
+            // Ignore
+        }
+    }
+
     /**
      * Tests that the Cosine similarity is correctly calculated.
      */