@Test(timeout = 60000)
public void testRemoveAll() {

  TestElement[] elements = generateElements(1 << 16);
  final LightWeightResizableGSet<TestKey, TestElement> set =
      new LightWeightResizableGSet<TestKey, TestElement>();
  assertThat(set.size()).isZero();
  // put all elements
  for (int i = 0; i < elements.length; i++) {
    TestElement element = set.put(elements[i]);
    assertThat(element).isNull();
  }
  // check the set size
  assertThat(set.size()).isEqualTo(elements.length);
  // remove all through clear
  {
    set.clear();
    assertThat(set.size()).isZero();
    // check all elements removed
    for (int i = 0; i < elements.length; i++) {
      assertThat(set.contains(elements[i])).isFalse();
    }
    assertThat(set.iterator().hasNext()).isFalse();
  }
  // put all elements back
  for (int i = 0; i < elements.length; i++) {
    TestElement element = set.put(elements[i]);
    assertThat(element).isNull();
  }
  // remove all through iterator
  {
    for (Iterator<TestElement> iter = set.iterator(); iter.hasNext(); ) {
      TestElement element = iter.next();
      // element should be there before removing
      assertThat(set.contains(element)).isTrue();
      iter.remove();
      // element should not be there now
      assertThat(set.contains(element)).isFalse();
    }
    // the deleted elements should not be there
    for (int i = 0; i < elements.length; i++) {
      assertThat(set.contains(elements[i])).isFalse();
    }
    // iterator should not have next
    assertThat(set.iterator().hasNext()).isFalse();
    // check the set size
    assertThat(set.size()).isZero();
  }
}