コード例 #1
0
  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));
  }
コード例 #2
0
  public void testContainsAll() throws Exception {

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

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

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

    List<Number> ints_list = new ArrayList<Number>();
    for (int element : ints) {
      ints_list.add(element);
    }

    for (int index = 0; index < ints.length; index++) {
      assertTrue(Integer.valueOf(ints[index]).toString(), set.contains(ints[index]));
    }

    assertTrue("containsAll(Collection<?>) failed: " + set, set.containsAll(ints_list));
    ints_list.remove(Integer.valueOf(42));
    ints_list.add(Long.valueOf(42));
    assertFalse("containsAll(Collection<?>) failed: " + set, set.containsAll(ints_list));

    assertTrue("containsAll(TIntSet) failed (same set): " + set, set.containsAll(set));

    assertTrue("containsAll(TIntSet) failed (other set): " + set, set.containsAll(other));

    assertTrue("containsAll(int[]) failed: " + set, set.containsAll(ints));

    int[] failed = {42, 86, 99, 123456};

    TIntSet failed_set = new TIntHashSet();
    failed_set.addAll(failed);

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

    assertFalse(
        "containsAll(Collection<?>) failed (false positive): " + set, set.containsAll(failed_list));

    assertFalse(
        "containsAll(TIntSet) failed (false positive): " + set, set.containsAll(failed_set));

    assertFalse("containsAll(int[]) failed (false positive): " + set, set.containsAll(failed));
  }
コード例 #3
0
  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));
  }