@Test public void whenCalculateUnionOfSets_thenCorrect() { final Set<Character> first = ImmutableSet.of('a', 'b', 'c'); final Set<Character> second = ImmutableSet.of('b', 'c', 'd'); final Set<Character> union = Sets.union(first, second); assertThat(union, containsInAnyOrder('a', 'b', 'c', 'd')); }
public void testContainsAll() { ImmutableSortedSet<Integer> set = ContiguousSet.create(Range.closed(1, 3), integers()); for (Set<Integer> subset : Sets.powerSet(ImmutableSet.of(1, 2, 3))) { assertTrue(set.containsAll(subset)); } for (Set<Integer> subset : Sets.powerSet(ImmutableSet.of(1, 2, 3))) { assertFalse(set.containsAll(Sets.union(subset, ImmutableSet.of(9)))); } assertFalse(set.containsAll(ImmutableSet.of("blah"))); }
@Test public void shouldReturnTheSetUnionOfTheSuppliedIterables() throws Exception { // Given Iterable<String> firstIterable = setWith("a", "b", "c"); Iterable<String> secondIterable = listWith("c", "d", "c", "e"); Iterable<String> thirdIterable = multisetWith("a", "c", "f", "f"); Set<String> expectedUnionSet = setWith("a", "b", "c", "d", "e", "f"); // When Set<String> actualUnionSet = Sets.union(firstIterable, secondIterable, thirdIterable); // Then assertThat(actualUnionSet, is(expectedUnionSet)); }
@Test public void shouldAllowSetUnionOfIterablesWithDifferentConcreteTypes() throws Exception { // Given Dog fido = dog(colour("black"), name("fido")); Dog spud = dog(colour("brown"), name("spud")); Cat snowy = cat(colour("white"), name("snowy")); Cat smudge = cat(colour("grey"), name("smudge")); Iterable<Dog> dogs = setWith(fido, spud); Iterable<Cat> cats = iterableWith(snowy, smudge, snowy); Set<Animal> expectedMenagerie = setBuilderOf(Animal.class).with(fido, smudge, spud, snowy).build(); // When Set<Animal> actualMenagerie = Sets.union(dogs, cats); // Then assertThat(actualMenagerie, is(expectedMenagerie)); }