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

  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);
  // check all elements exist in the set and the data is correct
  for (int i = 0; i < elements.length; i++) {
    assertThat(set.contains(elements[i])).isTrue();
    TestElement element = set.get(elements[i]);
    assertThat(elements[i].getData()).isEqualTo(element.getData());
  }
  TestKey[] keys = getKeys(elements);
  // generate new elements with same key, but new data
  TestElement[] newElements = generateElements(keys);
  // update the set
  for (int i = 0; i < newElements.length; i++) {
    TestElement element = set.put(newElements[i]);
    assertThat(element).isNotNull();
  }
  // check the set size
  assertThat(set.size()).isEqualTo(elements.length);
  // check all elements exist in the set and the data is updated to new value
  for (int i = 0; i < keys.length; i++) {
    assertThat(set.contains(keys[i])).isTrue();
    TestElement element = set.get(keys[i]);
    assertThat(newElements[i].getData()).isEqualTo(element.getData());
  }
  // test LightWeightHashGSet#values
  Collection<TestElement> cElements = set.values();
  assertThat(cElements.size()).isEqualTo(elements.length);
  for (TestElement element : cElements) {
    assertThat(set.contains(element)).isTrue();
  }
  // remove elements
  for (int i = 0; i < keys.length; i++) {
    TestElement element = set.remove(keys[i]);
    assertThat(element).isNotNull();
    // the element should not exist after remove
    assertThat(set.contains(keys[i])).isFalse();
  }
  // check the set size
  assertThat(set.size()).isZero();
}