示例#1
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")));
 }
  @Test
  public void whenCalculatingPowerSet_thenCorrect() {
    final Set<Character> chars = ImmutableSet.of('a', 'b');
    final Set<Set<Character>> result = Sets.powerSet(chars);

    final Set<Character> empty = ImmutableSet.<Character>builder().build();
    final Set<Character> a = ImmutableSet.of('a');
    final Set<Character> b = ImmutableSet.of('b');
    final Set<Character> aB = ImmutableSet.of('a', 'b');

    assertThat(result, contains(empty, a, b, aB));
  }
 @Test
 public void powerSet() {
   MutableSet<Integer> set = UnifiedSet.newSetWith(1, 2, 3);
   MutableSet<MutableSet<Integer>> expectedPowerSet =
       UnifiedSet.<MutableSet<Integer>>newSetWith(
           UnifiedSet.<Integer>newSet(),
           UnifiedSet.newSetWith(1),
           UnifiedSet.newSetWith(2),
           UnifiedSet.newSetWith(3),
           UnifiedSet.newSetWith(1, 2),
           UnifiedSet.newSetWith(1, 3),
           UnifiedSet.newSetWith(2, 3),
           UnifiedSet.newSetWith(1, 2, 3));
   Assert.assertEquals(expectedPowerSet, Sets.powerSet(set));
 }
 @Test
 public void powerSet_empty() {
   Assert.assertEquals(
       UnifiedSet.newSetWith(UnifiedSet.newSet()), Sets.powerSet(UnifiedSet.newSet()));
 }