@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); }
@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"))); }
@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"))); }
@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"))); }
@Test public void serializedForm() { Verify.assertSerializedForm( 1L, "rO0ABXNyAEdjb20uZ3MuY29sbGVjdGlvbnMuaW1wbC5ibG9jay5wcmVkaWNhdGUuY2hlY2tlZC5D\n" + "aGVja2VkUHJlZGljYXRlMlRlc3QkMQAAAAAAAAABAgAAeHIAQWNvbS5ncy5jb2xsZWN0aW9ucy5p\n" + "bXBsLmJsb2NrLnByZWRpY2F0ZS5jaGVja2VkLkNoZWNrZWRQcmVkaWNhdGUyAAAAAAAAAAECAAB4\n" + "cA==", CHECKED_PREDICATE_2); }
@Test public void serializedForm() { Verify.assertSerializedForm( 1L, "rO0ABXNyAEBjb20uZ3MuY29sbGVjdGlvbnMuaW1wbC5tYXAuc29ydGVkLm11dGFibGUuU3luY2hy\n" + "b25pemVkU29ydGVkTWFwAAAAAAAAAAECAAB4cgAzY29tLmdzLmNvbGxlY3Rpb25zLmltcGwubWFw\n" + "LlN5bmNocm9uaXplZE1hcEl0ZXJhYmxlAAAAAAAAAAECAAJMAARsb2NrdAASTGphdmEvbGFuZy9P\n" + "YmplY3Q7TAALbWFwSXRlcmFibGV0AChMY29tL2dzL2NvbGxlY3Rpb25zL2FwaS9tYXAvTWFwSXRl\n" + "cmFibGU7eHBxAH4ABHNyADhjb20uZ3MuY29sbGVjdGlvbnMuaW1wbC5tYXAuc29ydGVkLm11dGFi\n" + "bGUuVHJlZVNvcnRlZE1hcAAAAAAAAAABDAAAeHBwdwQAAAAAeA==", SynchronizedSortedMap.of(SortedMaps.mutable.of())); }
@Test public void cartesianProduct() { MutableSet<String> set = MultiReaderUnifiedSet.newSetWith("1", "2", "3", "4").asReadUntouchable(); LazyIterable<Pair<String, String>> cartesianProduct = set.cartesianProduct(UnifiedSet.newSetWith("One", "Two")); Verify.assertIterableSize(set.size() * 2, cartesianProduct); Assert.assertEquals( set, cartesianProduct .filter(Predicates.attributeEqual(Functions.<String>secondOfPair(), "One")) .transform(Functions.<String>firstOfPair()) .toSet()); }
@Override @Test public void testNewWith() { ImmutableSet<Integer> immutable = this.classUnderTest(); Verify.assertSize(1, immutable.newWith(1).castToSet()); }