public void testRemoveAll() throws Exception {

    int[] ints = {1138, 42, 13, 86, 99, 101};

    TIntSet set = new TIntHashSet();
    set.addAll(ints);

    TIntSet other = new TIntHashSet();
    other.addAll(ints);

    int[] to_remove = {13, 86, 99, 1138};

    TIntSet remove_set = new TIntHashSet();
    remove_set.addAll(to_remove);

    List<Integer> remove_list = new ArrayList<Integer>();
    for (int element : to_remove) {
      remove_list.add(element);
    }

    int[] remainder = {42, 101};

    try {
      assertFalse("removeAll(TIntSet) failed (same set): " + set, set.removeAll(set));
      fail("should have thrown ConcurrentModificationException");
    } catch (ConcurrentModificationException cme) {
      // expected exception thrown.
    }

    // reset the set.
    set = new TIntHashSet();
    set.addAll(ints);
    assertTrue("removeAll(Collection<?>) failed: " + set, set.removeAll(remove_list));
    // Contains just the expected elements
    assertTrue(set.toString(), set.containsAll(remainder));
    assertFalse(set.toString(), set.containsAll(to_remove));
    assertTrue(remove_set.toString(), remove_set.containsAll(to_remove));

    // reset the set.
    set = new TIntHashSet();
    set.addAll(ints);
    assertTrue("removeAll(TIntSet) failed: " + set, set.removeAll(remove_set));
    // Contains just the expected elements
    assertTrue(set.toString(), set.containsAll(remainder));
    assertFalse(set.toString(), set.containsAll(to_remove));
    assertTrue(remove_set.toString(), remove_set.containsAll(to_remove));

    // reset the set.
    set = new TIntHashSet();
    set.addAll(ints);
    assertTrue("removeAll(int[]) failed: " + set, set.removeAll(to_remove));
    // Contains just the expected elements
    assertTrue(set.toString(), set.containsAll(remainder));
    assertFalse(set.toString(), set.containsAll(to_remove));
    assertTrue(remove_set.toString(), remove_set.containsAll(to_remove));
  }
  public void testRetainAll() throws Exception {

    int[] ints = {1138, 42, 13, 86, 99, 101};

    TIntSet set = new TIntHashSet();
    set.addAll(ints);

    TIntSet other = new TIntHashSet();
    other.addAll(ints);

    int[] to_retain = {13, 86, 99, 1138};

    TIntSet retain_set = new TIntHashSet();
    retain_set.addAll(to_retain);

    List<Integer> retain_list = new ArrayList<Integer>();
    for (int element : to_retain) {
      retain_list.add(element);
    }

    assertFalse("retainAll(TIntSet) failed (same set): " + set, set.retainAll(set));
    // Contains all the original elements
    assertTrue(set.toString(), set.containsAll(ints));
    assertTrue(retain_set.toString(), retain_set.containsAll(to_retain));

    assertTrue("retainAll(Collection<?>) failed: " + set, set.retainAll(retain_list));
    // Contains just the expected elements
    assertFalse(set.toString(), set.containsAll(ints));
    assertTrue(set.toString(), set.containsAll(to_retain));
    assertTrue(retain_set.toString(), retain_set.containsAll(to_retain));

    // reset the set.
    set = new TIntHashSet();
    set.addAll(ints);
    assertTrue("retainAll(TIntSet) failed: " + set, set.retainAll(retain_set));
    // Contains just the expected elements
    assertFalse(set.toString(), set.containsAll(ints));
    assertTrue(set.toString(), set.containsAll(to_retain));
    assertTrue(retain_set.toString(), retain_set.containsAll(to_retain));

    // reset the set.
    set = new TIntHashSet();
    set.addAll(ints);
    assertTrue("retainAll(int[]) failed: " + set, set.retainAll(to_retain));
    // Contains just the expected elements
    assertFalse(set.toString(), set.containsAll(ints));
    assertTrue(set.toString(), set.containsAll(to_retain));
    assertTrue(retain_set.toString(), retain_set.containsAll(to_retain));
  }