コード例 #1
0
 @Test
 public void powerSet() {
   MutableSet<String> set =
       MultiReaderUnifiedSet.newSetWith("1", "2", "3", "4").asReadUntouchable();
   MutableSet<UnsortedSetIterable<String>> powerSet = set.powerSet();
   Verify.assertSize((int) StrictMath.pow(2, set.size()), powerSet);
   Verify.assertContains(UnifiedSet.<String>newSet(), powerSet);
   Verify.assertContains(set, powerSet);
 }
コード例 #2
0
  @Test
  public void intersect() {
    MutableSet<String> set =
        MultiReaderUnifiedSet.newSetWith("1", "2", "3", "4").asReadUntouchable();
    MutableSet<String> intersect = set.intersect(UnifiedSet.newSetWith("a", "b", "c", "1"));
    Verify.assertSize(1, intersect);
    Assert.assertEquals(UnifiedSet.newSetWith("1"), intersect);

    Verify.assertEmpty(set.intersect(UnifiedSet.newSetWith("not present")));
  }
コード例 #3
0
  @Test
  public void union() {
    MutableSet<String> set =
        MultiReaderUnifiedSet.newSetWith("1", "2", "3", "4").asReadUntouchable();
    MutableSet<String> union = set.union(UnifiedSet.newSetWith("a", "b", "c", "1"));
    Verify.assertSize(set.size() + 3, union);
    Assert.assertTrue(
        union.containsAllIterable(Interval.oneTo(set.size()).transform(Functions.getToString())));
    Verify.assertContainsAll(union, "a", "b", "c");

    Assert.assertEquals(set, set.union(UnifiedSet.newSetWith("1")));
  }
コード例 #4
0
  @Test
  public void symmetricDifference() {
    MutableSet<String> set =
        MultiReaderUnifiedSet.newSetWith("1", "2", "3", "4").asReadUntouchable();
    MutableSet<String> difference =
        set.symmetricDifference(UnifiedSet.newSetWith("2", "3", "4", "5", "not present"));
    Verify.assertContains("1", difference);
    Assert.assertTrue(
        difference.containsAllIterable(
            Interval.fromTo(set.size() + 1, 5).transform(Functions.getToString())));
    for (int i = 2; i <= set.size(); i++) {
      Verify.assertNotContains(String.valueOf(i), difference);
    }

    Verify.assertSize(
        set.size() + 1, set.symmetricDifference(UnifiedSet.newSetWith("not present")));
  }
コード例 #5
0
 @Override
 @Test
 public void testNewWith() {
   ImmutableSet<Integer> immutable = this.classUnderTest();
   Verify.assertSize(1, immutable.newWith(1).castToSet());
 }