@Override @Test public void zipWithIndex() { ImmutableSet<Integer> immutableSet = this.classUnderTest(); ImmutableSet<Pair<Integer, Integer>> pairs = immutableSet.zipWithIndex(); Assert.assertEquals(immutableSet, pairs.transform(Functions.<Integer>firstOfPair())); Assert.assertEquals( UnifiedSet.<Integer>newSet(), pairs.transform(Functions.<Integer>secondOfPair())); Assert.assertEquals( immutableSet.zipWithIndex(), immutableSet.zipWithIndex(UnifiedSet.<Pair<Integer, Integer>>newSet())); }
@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 zip() { ImmutableSet<Integer> immutableSet = this.classUnderTest(); List<Object> nulls = Collections.nCopies(immutableSet.size(), null); List<Object> nullsPlusOne = Collections.nCopies(immutableSet.size() + 1, null); ImmutableSet<Pair<Integer, Object>> pairs = immutableSet.zip(nulls); Assert.assertEquals(immutableSet, pairs.transform(Functions.<Integer>firstOfPair())); Assert.assertEquals( UnifiedSet.<Object>newSet(nulls), pairs.transform(Functions.<Object>secondOfPair())); ImmutableSet<Pair<Integer, Object>> pairsPlusOne = immutableSet.zip(nullsPlusOne); Assert.assertEquals(immutableSet, pairsPlusOne.transform(Functions.<Integer>firstOfPair())); Assert.assertEquals( UnifiedSet.<Object>newSet(nulls), pairsPlusOne.transform(Functions.<Object>secondOfPair())); Assert.assertEquals( immutableSet.zip(nulls), immutableSet.zip(nulls, UnifiedSet.<Pair<Integer, Object>>newSet())); }
@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"))); }
@Override @Test(expected = NoSuchElementException.class) public void maxBy() { this.classUnderTest().maxBy(Functions.getToString()); }