/**
   * Run some random insertions/ deletions and compare the results against <code>java.util.HashSet
   * </code>.
   */
  @Test
  public void testAgainstHashMap() {
    final java.util.Random rnd = new Random(0xBADCAFE);
    final java.util.HashSet<KType> other = new java.util.HashSet<KType>();

    for (int size = 1000; size < 20000; size += 4000) {
      other.clear();
      this.set.clear();

      for (int round = 0; round < size * 20; round++) {
        final KType key = cast(rnd.nextInt(size));

        if (rnd.nextBoolean()) {
          other.add(key);
          this.set.add(key);

          Assert.assertTrue(this.set.contains(key));
        } else {
          Assert.assertTrue(
              "size= " + size + ", round = " + round, other.remove(key) == this.set.remove(key));
        }

        Assert.assertEquals(other.size(), this.set.size());
      }
    }
  }
  /**
   * Run some random insertions/ deletions and compare the results against <code>java.util.HashSet
   * </code>.
   */
  @Test
  public void testAgainstHashMap() {
    final java.util.Random rnd = new java.util.Random(0x11223344);
    final java.util.HashSet<Integer> other = new java.util.HashSet<Integer>();

    for (int size = 1000; size < 20000; size += 4000) {
      other.clear();
      set.clear();

      for (int round = 0; round < size * 20; round++) {
        Integer key = rnd.nextInt(size);

        if (rnd.nextBoolean()) {
          assertEquals(other.add(key), set.add(key));
          assertTrue(set.contains(key));
        } else {
          assertEquals(other.remove(key), set.remove(key));
        }

        assertEquals(other.size(), set.size());
      }

      int[] actual = set.toArray();
      int[] expected = new int[other.size()];
      int i = 0;
      for (Integer v : other) expected[i++] = v;
      Arrays.sort(expected);
      Arrays.sort(actual);
      assertArrayEquals(expected, actual);
    }
  }