@Test
public void testToArray() {

    IntSet intSet = new BitSetIntSet();
    assertEquals(0, intSet.toArray().length);
    intSet.add(1);
    intSet.add(10);
    intSet.add(10);
    intSet.add(11);
    intSet.add(1025);
    Object[] arr = intSet.toArray();
    assertEquals(4, arr.length);
    assertEquals(1, (int)arr[0]);
    assertEquals(10, (int)arr[1]);
    assertEquals(11, (int)arr[2]);
    assertEquals(1025, (int)arr[3]);
    Integer[] input = new Integer[1];
    Integer[] output = intSet.toArray(input);
    assertNotSame(input, output);
    assertEquals(4, arr.length);
    assertEquals(1, arr[0]);
    assertEquals(10, arr[1]);
    assertEquals(11, arr[2]);
    assertEquals(1025, arr[3]);
    input = new Integer[6];
    output = intSet.toArray(input);
    assertSame(input, output);
    assertEquals(6, output.length);
    assertEquals(1, (int)output[0]);
    assertEquals(10, (int)output[1]);
    assertEquals(11, (int)output[2]);
    assertEquals(1025, (int)output[3]);
    assertNull(output[4]);
    assertNull(output[5]);
}