@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'));
  }
예제 #2
0
 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")));
 }
예제 #3
0
파일: SetsTest.java 프로젝트: tomcz/funk
  @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));
  }
예제 #4
0
파일: SetsTest.java 프로젝트: tomcz/funk
  @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));
  }