public void testForEach() { TIntSet set = new TIntHashSet(10, 0.5f); int[] ints = {1138, 42, 86, 99, 101}; set.addAll(ints); class ForEach implements TIntProcedure { TIntSet built = new TIntHashSet(); @Override public boolean execute(int value) { built.add(value); return true; } TIntSet getBuilt() { return built; } } ForEach procedure = new ForEach(); set.forEach(procedure); TIntSet built = procedure.getBuilt(); assertEquals("inequal sizes: " + set + ", " + built, set.size(), built.size()); assertTrue("inequal sets: " + set + ", " + built, set.equals(built)); }
public void testEquals() { int[] ints = {1138, 42, 86, 99, 101}; TIntSet set = new TIntHashSet(); set.addAll(ints); TIntSet other = new TIntHashSet(); other.addAll(ints); assertTrue("sets incorrectly not equal: " + set + ", " + other, set.equals(other)); int[] mismatched = {72, 49, 53, 1024, 999}; TIntSet unequal = new TIntHashSet(); unequal.addAll(mismatched); assertFalse("sets incorrectly equal: " + set + ", " + unequal, set.equals(unequal)); // Change length, different code branch unequal.add(1); assertFalse("sets incorrectly equal: " + set + ", " + unequal, set.equals(unequal)); }
public void testConstructors() throws Exception { TIntSet set = new TIntHashSet(); assertNotNull(set); int[] ints = {1138, 42, 86, 99, 101}; set.addAll(ints); TIntSet copy = new TIntHashSet(set); assertTrue("set not a copy: " + set + ", " + copy, set.equals(copy)); TIntSet another = new TIntHashSet(20); another.addAll(ints); assertTrue("set not equal: " + set + ", " + copy, set.equals(another)); another = new TIntHashSet(2, 1.0f); another.addAll(ints); assertTrue("set not equal: " + set + ", " + copy, set.equals(another)); another = new TIntHashSet(ints); assertTrue("set not equal: " + set + ", " + copy, set.equals(another)); }