Claudenw commented on a change in pull request #258:
URL: 
https://github.com/apache/commons-collections/pull/258#discussion_r775449828



##########
File path: 
src/test/java/org/apache/commons/collections4/bloomfilter/ShapeFactoryTest.java
##########
@@ -0,0 +1,224 @@
+/*
+ * 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;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.fail;
+
+
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests the {@link Shape} class.
+ */
+public class ShapeFactoryTest {
+
+
+    /*
+     * values from https://hur.st/bloomfilter/?n=5&p=.1&m=&k=
+     *
+     * n = 5
+     *
+     * p = 0.100375138 (1 in 10)
+     *
+     * m = 24 (3B)
+     *
+     * k = 3
+     */
+
+
+    /**
+     * Tests that if the number of items less than 1 an 
IllegalArgumentException is thrown.
+     */
+    @Test
+    public void badNumberOfItemsTest() {
+        try {
+            Shape.Factory.fromNM(0, 24);
+            fail("Should have thrown IllegalArgumentException");
+        } catch (final IllegalArgumentException expected) {
+            // expected
+        }
+        try {
+            Shape.Factory.fromNMK(0, 24, 5);
+            fail("Should have thrown IllegalArgumentException");
+        } catch (final IllegalArgumentException expected) {
+            // expected
+        }
+        try {
+            Shape.Factory.fromNP(0, 0.02 );
+            fail("Should have thrown IllegalArgumentException");
+        } catch (final IllegalArgumentException expected) {
+            // expected
+        }
+    }
+
+    /**
+     * Tests that if the number of bits is less than 1 an exception is thrown
+     */
+    @Test
+    public void badNumberOfBitsTest() {
+        try {
+            Shape.Factory.fromNM( 5, 0 );
+            fail("Should have thrown IllegalArgumentException");
+        } catch (final IllegalArgumentException expected) {
+            // expected
+        }
+        try {
+            Shape.Factory.fromNMK( 5, 0, 7 );
+            fail("Should have thrown IllegalArgumentException");
+        } catch (final IllegalArgumentException expected) {
+            // expected
+        }
+        try {
+            Shape.Factory.fromPMK( 0.035, 0, 7 );
+            fail("Should have thrown IllegalArgumentException");
+        } catch (final IllegalArgumentException expected) {
+            // expected
+        }
+    }
+
+    /**
+     * Tests that if the number of hash functions is less than 1 an exception 
is thrown.
+     */
+    @Test
+    public void badNumberOfHashFunctionsTest() {
+        try {
+            Shape.Factory.fromNMK(5, 26, 0);
+            fail("Should have thrown IllegalArgumentException");
+        } catch (final IllegalArgumentException expected) {
+            // expected
+        }
+        try {
+            Shape.Factory.fromPMK(0.35, 26, 0);
+            fail("Should have thrown IllegalArgumentException");
+        } catch (final IllegalArgumentException expected) {
+            // expected
+        }
+    }
+
+    /**
+     * Tests that if the calculated probability is greater than or equal to 1 
an IllegalArgumentException is thrown
+     */
+    @Test
+    public void badProbabilityTest() {
+        try {
+            Shape.Factory.fromNMK( 4000, 8, 1);
+            fail("Should have thrown IllegalArgumentException");
+        } catch (final IllegalArgumentException expected) {
+            // expected
+        }
+        try {
+            Shape.Factory.fromNP(10, 0.0);
+            fail("Should have thrown IllegalArgumentException");
+        } catch (final IllegalArgumentException expected) {
+            // do nothing.
+        }
+        try {
+            Shape.Factory.fromNP( 10, 1.0);
+            fail("Should have thrown IllegalArgumentException");
+        } catch (final IllegalArgumentException expected) {
+            // do nothing.
+        }
+        try {
+            Shape.Factory.fromNP( 10, Double.NaN);
+            fail("Should have thrown IllegalArgumentException");
+        } catch (final IllegalArgumentException expected) {
+            // do nothing.
+        }

Review comment:
       fixed




-- 
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: issues-unsubscr...@commons.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to