}
}
@Test
public void testToArray() {
IntHashSet set = new IntHashSet();
for (int j = 0; j < 100; ++j) {
for (int i = 0; i < ArrayHashMapTest.RANDOM_TEST_NUM_ITERATIONS; ++i) {
int value = random().nextInt() % 5000;
boolean shouldAdd = random().nextBoolean();
if (shouldAdd) {
set.add(value);
} else {
set.remove(value);
}
}
int[] vals = set.toArray();
assertEquals(set.size(), vals.length);
int[] realValues = new int[set.size()];
int[] unrealValues = set.toArray(realValues);
assertEquals(realValues, unrealValues);
for (int value : vals) {
assertTrue(set.remove(value));
}
for (int i = 0; i < vals.length; ++i) {
assertEquals(vals[i], realValues[i]);
}
}