@Test
public void testToArray() {

  int[] indices = new int[] { 0, 1, 4, 10, 6, 9, 11 };
  BitSet bitSet = new BitSet(20);
  for (int i: indices) {
    bitSet.set(i);
  }
  boolean[] array = BitSetUtils.toArray(bitSet, bitSet.size());
  Assert.assertEquals(bitSet.size(), array.length);
  for (int i = 0; i < bitSet.size(); i++) {
    Assert.assertEquals(bitSet.get(i), array[i]);
  }
  boolean[] shortArray = BitSetUtils.toArray(bitSet, 5);
  Assert.assertEquals(5, shortArray.length);
  for (int i = 0; i < 5; i++) {
    Assert.assertEquals(bitSet.get(i), shortArray[i]);
  }
  boolean[] longArray = BitSetUtils.toArray(bitSet, bitSet.size() + 10);
  Assert.assertEquals(bitSet.size() + 10, longArray.length);
  for (int i = 0; i < bitSet.size() + 10; i++) {
    Assert.assertEquals(bitSet.get(i), longArray[i]);
  }
  boolean exception = false;
  try {
    BitSetUtils.toArray(bitSet, -2);
  } catch (IllegalArgumentException e) {
    exception = true;
  }
  Assert.assertTrue(exception);
}