/*
 * Copyright 2011 - 2015 Metamarkets Group Inc.
 *
 * Licensed 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 com.metamx.collections.bitmap;

import com.google.common.base.Function;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import junit.framework.Assert;
import org.junit.Test;
import org.roaringbitmap.IntIterator;

import java.util.Arrays;

public class RoaringBitmapFactoryTest
{
    
  // testing https://github.com/metamx/bytebuffer-collections/issues/26
  @Test
  public void testIssue26() throws Exception
  {
    printBitMap(new ConciseBitmapFactory());
    printBitMap(new RoaringBitmapFactory());
  }

  // used by issue 26
  private void printBitMap(BitmapFactory bitmapFactory) throws Exception
  {
    int numRow = 5104234;
    ImmutableBitmap bitmap = bitmapFactory.complement(bitmapFactory.makeEmptyImmutableBitmap(), numRow);
    ImmutableBitmap notBitmap = bitmapFactory.complement(bitmap,numRow);
    if(notBitmap.size() != 0) throw new RuntimeException("should be empty");
    IntIterator intIter = notBitmap.iterator();
    while(intIter.hasNext()) {
        throw new RuntimeException("should be empty");
    }
  }
  
  @Test
  public void testUnwrapWithNull() throws Exception
  {
    RoaringBitmapFactory factory = new RoaringBitmapFactory();

    ImmutableBitmap bitmap = factory.union(
        Iterables.transform(
            Lists.newArrayList(new WrappedRoaringBitmap()),
            new Function<WrappedRoaringBitmap, ImmutableBitmap>()
            {
              @Override
              public ImmutableBitmap apply(WrappedRoaringBitmap input)
              {
                return null;
              }
            }
        )
    );

    Assert.assertEquals(0, bitmap.size());
  }

  @Test
  public void testUnwrapMerge() throws Exception
  {
    RoaringBitmapFactory factory = new RoaringBitmapFactory();

    WrappedRoaringBitmap set = new WrappedRoaringBitmap();
    set.add(1);
    set.add(3);
    set.add(5);

    ImmutableBitmap bitmap = factory.union(
        Arrays.asList(
            factory.makeImmutableBitmap(set),
            null
        )
    );

    Assert.assertEquals(3, bitmap.size());
  }
}

@@ -782,24 +782,18 @@
 ort 
+org.
 junit.
-framework.
 Asse
@@ -1058,35 +1058,44 @@
 ion%0A  %7B%0A    
-printBitMap
+checkEmptyComplement
 (new Concise
@@ -1116,27 +1116,36 @@
 ));%0A    
-printBitMap
+checkEmptyComplement
 (new Roa
@@ -1212,19 +1212,28 @@
 oid 
-printBitMap
+checkEmptyComplement
 (Bit
@@ -1487,18 +1487,33 @@
 w);%0A    
-if
+Assert.assertTrue
 (notBitm
@@ -1526,58 +1526,56 @@
 e() 
-!
+=
 = 0)
- throw new RuntimeException(%22should be e
+;%0A    Assert.assertTrue(notBitmap.isE
 mpty
-%22
+()
 );%0A 
@@ -1629,12 +1629,25 @@
     
-whil
+Assert.assertFals
 e(in
@@ -1666,71 +1666,9 @@
 t())
- %7B%0A        throw new RuntimeException(%22should be empty%22);%0A    %7D
+;
 %0A  %7D

Make test for issue 26 more junit-y