aherbert commented on code in PR #335:
URL: 
https://github.com/apache/commons-collections/pull/335#discussion_r1014603229


##########
src/test/java/org/apache/commons/collections4/bloomfilter/DefaultIndexProducerTest.java:
##########
@@ -36,22 +38,41 @@ protected int[] getExpectedIndices() {
 
     @Override
     protected IndexProducer createProducer() {
-        return IndexProducer.fromIndexArray(values);
+        return new IndexProducer() {
+            @Override
+            public boolean forEachIndex(IntPredicate predicate) {
+                Objects.requireNonNull(predicate);
+                for (int i : values) {
+                    if (!predicate.test(i)) {
+                        return false;
+                    }
+                }
+                return true;
+            }
+        };
     }
 
     @Override
     protected IndexProducer createEmptyProducer() {
         return new IndexProducer() {
-
             @Override
             public boolean forEachIndex(IntPredicate predicate) {
+                Objects.requireNonNull(predicate);
                 return true;
             }
         };
     }
 
     @Override
-    protected int getBehaviour() {
+    protected int getAsIndexArrayBehaviour() {
+        // The default method streams a BitSet so is distinct and ordered.
+        // However the forEachIndex may not be distinct and ordered and

Review Comment:
   Again can you move this comment to `getForEachIndexBehaviour` as:
   ```Java
   // The forEachIndex output is intentionally unordered and contains duplicates
   ```



##########
src/test/java/org/apache/commons/collections4/bloomfilter/DefaultBitCountProducerTest.java:
##########
@@ -0,0 +1,94 @@
+/*
+ * 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 java.util.Arrays;
+import java.util.Objects;
+import java.util.function.IntPredicate;
+
+public class DefaultBitCountProducerTest extends AbstractBitCountProducerTest {
+
+    /** Make forEachIndex unordered and contain duplicates. */
+    private int[] values = {10, 1, 10, 1};
+
+    @Override
+    protected int[] getExpectedIndices() {
+        return values;
+    }
+
+    @Override
+    protected BitCountProducer createProducer() {
+        return new BitCountProducer() {
+            @Override
+            public boolean forEachIndex(IntPredicate predicate) {
+                Objects.requireNonNull(predicate);
+                for (int i : values) {
+                    if (!predicate.test(i)) {
+                        return false;
+                    }
+                }
+                return true;
+            }
+
+            @Override
+            public boolean forEachCount(BitCountConsumer consumer) {
+                int[] vals = values.clone();
+                Arrays.sort(vals);
+                for (int i : vals) {
+                    if (!consumer.test(i, 1)) {
+                        return false;
+                    }
+                }
+                return true;
+            }
+        };
+    }
+
+    @Override
+    protected BitCountProducer createEmptyProducer() {
+        return new BitCountProducer() {
+            @Override
+            public boolean forEachIndex(IntPredicate predicate) {
+                Objects.requireNonNull(predicate);
+                return true;
+            }
+            @Override
+            public boolean forEachCount(BitCountConsumer consumer) {
+                return true;
+            }
+        };
+    }
+
+    @Override
+    protected int getAsIndexArrayBehaviour() {
+        // The default method streams a BitSet so is distinct and ordered.
+        // However the forEachIndex may not be distinct and ordered and

Review Comment:
   This comment is outdated. The comment should be moved to 
`getForEachIndexBehaviour` as:
   ```Java
   // The forEachIndex output is intentionally unordered and contains duplicates
   ```
   
   If you wish to test forEachCount can use different flags then add some 
comments:
   ```Java
   // Force to be ordered
   int[] vals = values.clone();
   Arrays.sort(vals);
   
   // ...
   
   // The forEachCount output is intentionally ordered and contains duplicates
   ```



##########
src/test/java/org/apache/commons/collections4/bloomfilter/DefaultBitCountProducerTest.java:
##########
@@ -0,0 +1,94 @@
+/*
+ * 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 java.util.Arrays;
+import java.util.Objects;
+import java.util.function.IntPredicate;
+
+public class DefaultBitCountProducerTest extends AbstractBitCountProducerTest {
+
+    /** Make forEachIndex unordered and contain duplicates. */
+    private int[] values = {10, 1, 10, 1};
+
+    @Override
+    protected int[] getExpectedIndices() {
+        return values;
+    }
+
+    @Override
+    protected BitCountProducer createProducer() {
+        return new BitCountProducer() {
+            @Override
+            public boolean forEachIndex(IntPredicate predicate) {
+                Objects.requireNonNull(predicate);
+                for (int i : values) {
+                    if (!predicate.test(i)) {
+                        return false;
+                    }
+                }
+                return true;
+            }
+
+            @Override
+            public boolean forEachCount(BitCountConsumer consumer) {
+                int[] vals = values.clone();

Review Comment:
   There are no comments as to why you are doing this. Was it for testing?
   
   I suggest leaving forEachCount to not be ordered and match the forEachIndex 
order. This should test the default implementations of BitCountProducer, not 
add in extra tests for convenience.



-- 
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]

Reply via email to