commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aherb...@apache.org
Subject [commons-collections] 03/06: Hit all edge cases in the Shape.equals method.
Date Tue, 18 Feb 2020 16:36:33 GMT
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 6215948227b39308d59c624ffa2221e841fb0909
Author: aherbert <a.herbert@sussex.ac.uk>
AuthorDate: Tue Feb 18 13:40:22 2020 +0000

    Hit all edge cases in the Shape.equals method.
---
 .../collections4/bloomfilter/hasher/ShapeTest.java  | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/ShapeTest.java
b/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/ShapeTest.java
index 78ba037..c69e6f3 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/ShapeTest.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/ShapeTest.java
@@ -406,9 +406,22 @@ public class ShapeTest {
     @Test
     public void equalsTest() {
 
-        assertEquals(new Shape(testFunction, 5, 1.0 / 10), shape);
-        assertNotEquals(new Shape(testFunction, 5, 1.0 / 11), shape);
-        assertNotEquals(new Shape(testFunction, 4, 1.0 / 10), shape);
+        assertEquals(shape, shape);
+        assertEquals(shape, new Shape(testFunction, 5, 1.0 / 10));
+        assertNotEquals(shape, null);
+        assertNotEquals(shape, new Shape(testFunction, 5, 1.0 / 11));
+        assertNotEquals(shape, new Shape(testFunction, 4, 1.0 / 10));
+        // Number of bits does not change equality,
+        // only the number of bits and the number of hash functions
+        final int numberOfBits = 10000;
+        final int numberOfItems = 15;
+        final int numberOfHashFunctions = 4;
+        assertEquals(new Shape(testFunction, numberOfItems, numberOfBits, numberOfHashFunctions),
+                     new Shape(testFunction, numberOfItems + 1, numberOfBits, numberOfHashFunctions));
+        assertNotEquals(new Shape(testFunction, numberOfItems, numberOfBits, numberOfHashFunctions),
+                        new Shape(testFunction, numberOfItems, numberOfBits + 1, numberOfHashFunctions));
+        assertNotEquals(new Shape(testFunction, numberOfItems, numberOfBits, numberOfHashFunctions),
+                        new Shape(testFunction, numberOfItems, numberOfBits, numberOfHashFunctions
+ 1));
 
         final HashFunctionIdentity testFunction2 = new HashFunctionIdentity() {
 
@@ -438,7 +451,7 @@ public class ShapeTest {
             }
         };
 
-        assertNotEquals(new Shape(testFunction2, 4, 1.0 / 10), shape);
+        assertNotEquals(shape, new Shape(testFunction2, 4, 1.0 / 10));
     }
 
     /**


Mime
View raw message