View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.collections4.bloomfilter;
18  
19  import static org.junit.jupiter.api.Assertions.assertEquals;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  
24  import org.junit.jupiter.api.Test;
25  
26  public class BitMapProducerFromLongArrayTest extends AbstractBitMapProducerTest {
27  
28      @Test
29      public void constructorTest() {
30          final List<Long> lst = new ArrayList<>();
31          createProducer().forEachBitMap(lst::add);
32          assertEquals(Long.valueOf(1), lst.get(0));
33          assertEquals(Long.valueOf(2), lst.get(1));
34          assertEquals(Long.valueOf(3), lst.get(2));
35          assertEquals(Long.valueOf(4), lst.get(3));
36          assertEquals(Long.valueOf(5), lst.get(4));
37      }
38  
39      @Override
40      protected BitMapProducer createEmptyProducer() {
41          return BitMapProducer.fromBitMapArray(new long[0]);
42      }
43  
44      @Override
45      protected BitMapProducer createProducer() {
46          final long[] ary = {1L, 2L, 3L, 4L, 5L};
47          return BitMapProducer.fromBitMapArray(ary);
48      }
49  
50      @Override
51      protected boolean emptyIsZeroLength() {
52          return true;
53      }
54  
55      @Test
56      public void testFromIndexProducer() {
57          final int limit = Integer.SIZE + Long.SIZE;
58          final IndexProducer iProducer = consumer -> {
59              for (int i = 0; i < limit; i++) {
60                  if (!consumer.test(i)) {
61                      return false;
62                  }
63              }
64              return true;
65          };
66          final BitMapProducer producer = BitMapProducer.fromIndexProducer(iProducer, limit);
67          final List<Long> lst = new ArrayList<>();
68          producer.forEachBitMap(lst::add);
69          long expected = ~0L;
70          assertEquals(expected, lst.get(0).longValue());
71          expected &= 0XFFFFFFFFL;
72          assertEquals(expected, lst.get(1).longValue());
73      }
74  }