*/
public class SetOperationsTest extends TestCase {
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override protected Set<String> create(String[] elements) {
return Sets.union(
Sets.<String>newHashSet(), Sets.<String>newHashSet());
}
})
.named("empty U empty")
.withFeatures(CollectionSize.ZERO, CollectionFeature.NONE,
CollectionFeature.ALLOWS_NULL_VALUES)
.createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override protected Set<String> create(String[] elements) {
checkArgument(elements.length == 1);
return Sets.union(
Sets.<String>newHashSet(elements), Sets.newHashSet(elements));
}
})
.named("singleton U itself")
.withFeatures(CollectionSize.ONE, CollectionFeature.ALLOWS_NULL_VALUES)
.createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override protected Set<String> create(String[] elements) {
return Sets.union(
Sets.<String>newHashSet(), Sets.newHashSet(elements));
}
})
.named("empty U set")
.withFeatures(CollectionSize.ONE, CollectionSize.SEVERAL,
CollectionFeature.ALLOWS_NULL_VALUES)
.createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override protected Set<String> create(String[] elements) {
return Sets.union(
Sets.newHashSet(elements), Sets.<String>newHashSet());
}
})
.named("set U empty")
.withFeatures(CollectionSize.ONE, CollectionSize.SEVERAL,
CollectionFeature.ALLOWS_NULL_VALUES)
.createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override protected Set<String> create(String[] elements) {
checkArgument(elements.length == 3);
// Put the sets in different orders for the hell of it
return Sets.union(
Sets.newLinkedHashSet(asList(elements)),
Sets.newLinkedHashSet(
asList(elements[1], elements[0], elements[2])));
}
})
.named("set U itself")
.withFeatures(CollectionSize.SEVERAL,
CollectionFeature.ALLOWS_NULL_VALUES)
.createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override protected Set<String> create(String[] elements) {
checkArgument(elements.length == 3);
return Sets.union(
Sets.newHashSet(elements[0]),
Sets.newHashSet(elements[1], elements[2]));
}
})
.named("union of disjoint")
.withFeatures(CollectionSize.SEVERAL,
CollectionFeature.ALLOWS_NULL_VALUES)
.createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override protected Set<String> create(String[] elements) {
return Sets.union(
Sets.<String>newHashSet(elements[0], elements[1]),
Sets.newHashSet(elements[1], elements[2]));
}
})
.named("venn")
.withFeatures(CollectionSize.SEVERAL,
CollectionFeature.ALLOWS_NULL_VALUES)
.createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override protected Set<String> create(String[] elements) {
return Sets.intersection(
Sets.<String>newHashSet(), Sets.<String>newHashSet());
}
})
.named("empty & empty")
.withFeatures(CollectionSize.ZERO, CollectionFeature.NONE,
CollectionFeature.ALLOWS_NULL_VALUES)
.createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override protected Set<String> create(String[] elements) {
return Sets.intersection(
Sets.<String>newHashSet(), Sets.newHashSet((String) null));
}
})
.named("empty & singleton")
.withFeatures(CollectionSize.ZERO, CollectionFeature.NONE,
CollectionFeature.ALLOWS_NULL_VALUES)
.createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override protected Set<String> create(String[] elements) {
return Sets.intersection(
Sets.newHashSet("a", "b"), Sets.newHashSet("c", "d"));
}
})
.named("intersection of disjoint")
.withFeatures(CollectionSize.ZERO, CollectionFeature.NONE,
CollectionFeature.ALLOWS_NULL_VALUES)
.createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override protected Set<String> create(String[] elements) {
return Sets.intersection(
Sets.newHashSet(elements), Sets.newHashSet(elements));
}
})
.named("set & itself")
.withFeatures(CollectionSize.ONE, CollectionSize.SEVERAL,
CollectionFeature.ALLOWS_NULL_VALUES)
.createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override protected Set<String> create(String[] elements) {
return Sets.intersection(
Sets.newHashSet("a", elements[0], "b"),
Sets.newHashSet("c", elements[0], "d"));
}
})
.named("intersection with overlap of one")
.withFeatures(CollectionSize.ONE, CollectionFeature.ALLOWS_NULL_VALUES)
.createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override protected Set<String> create(String[] elements) {
return Sets.difference(
Sets.<String>newHashSet(), Sets.<String>newHashSet());
}
})
.named("empty - empty")
.withFeatures(CollectionSize.ZERO, CollectionFeature.NONE,
CollectionFeature.ALLOWS_NULL_VALUES)
.createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override protected Set<String> create(String[] elements) {
return Sets.difference(Sets.newHashSet("a"), Sets.newHashSet("a"));
}
})
.named("singleton - itself")
.withFeatures(CollectionSize.ZERO, CollectionFeature.NONE,
CollectionFeature.ALLOWS_NULL_VALUES)
.createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override protected Set<String> create(String[] elements) {
Set<String> set = Sets.newHashSet("b", "c");
Set<String> other = Sets.newHashSet("a", "b", "c", "d");
return Sets.difference(set, other);
}
})
.named("set - superset")
.withFeatures(CollectionSize.ZERO, CollectionFeature.NONE,
CollectionFeature.ALLOWS_NULL_VALUES)
.createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override protected Set<String> create(String[] elements) {
Set<String> set = Sets.newHashSet(elements);
Set<String> other = Sets.newHashSet("wz", "xq");
set.addAll(other);
other.add("pq");
return Sets.difference(set, other);
}
})
.named("set - set")
.withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_VALUES,
CollectionFeature.ALLOWS_NULL_VALUES)
.createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override protected Set<String> create(String[] elements) {
return Sets.difference(
Sets.newHashSet(elements), Sets.newHashSet());
}
})
.named("set - empty")
.withFeatures(CollectionSize.ONE, CollectionSize.SEVERAL,
CollectionFeature.ALLOWS_NULL_VALUES)
.createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override protected Set<String> create(String[] elements) {
return Sets.difference(
Sets.<String>newHashSet(elements), Sets.newHashSet("xx", "xq"));
}
})