use of com.google.common.collect.testing.TestStringSetGenerator in project guava by hceylan.
the class ForwardingMultisetTest method suite.
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(ForwardingMultisetTest.class);
suite.addTest(MultisetTestSuiteBuilder.using(new TestStringMultisetGenerator() {
@Override
protected Multiset<String> create(String[] elements) {
return new StandardImplForwardingMultiset<String>(LinkedHashMultiset.create(Arrays.asList(elements)));
}
}).named("ForwardingMultiset[LinkedHashMultiset] with standard " + "implementations").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_VALUES, CollectionFeature.GENERAL_PURPOSE).createTestSuite());
suite.addTest(MultisetTestSuiteBuilder.using(new TestStringMultisetGenerator() {
@Override
protected Multiset<String> create(String[] elements) {
return new StandardImplForwardingMultiset<String>(ImmutableMultiset.copyOf(elements));
}
}).named("ForwardingMultiset[ImmutableMultiset] with standard " + "implementations").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
/**
* Returns a Multiset that throws an exception on any attempt to use a
* method not specifically authorized by the elementSet() or hashCode()
* docs.
*/
@Override
protected Set<String> create(String[] elements) {
final Multiset<String> inner = LinkedHashMultiset.create(Arrays.asList(elements));
return new ForwardingMultiset<String>() {
@Override
protected Multiset<String> delegate() {
return inner;
}
@Override
public Set<String> elementSet() {
return new StandardElementSet();
}
@Override
public int add(String element, int occurrences) {
throw new UnsupportedOperationException();
}
@Override
public Set<Entry<String>> entrySet() {
final Set<Entry<String>> backingSet = super.entrySet();
return new ForwardingSet<Entry<String>>() {
@Override
protected Set<Entry<String>> delegate() {
return backingSet;
}
@Override
public boolean add(Entry<String> element) {
throw new UnsupportedOperationException();
}
@Override
public boolean addAll(Collection<? extends Entry<String>> collection) {
throw new UnsupportedOperationException();
}
@Override
public void clear() {
throw new UnsupportedOperationException();
}
@Override
public boolean contains(Object object) {
throw new UnsupportedOperationException();
}
@Override
public boolean containsAll(Collection<?> collection) {
throw new UnsupportedOperationException();
}
@Override
public boolean isEmpty() {
throw new UnsupportedOperationException();
}
@Override
public boolean remove(Object object) {
throw new UnsupportedOperationException();
}
@Override
public boolean removeAll(Collection<?> collection) {
throw new UnsupportedOperationException();
}
@Override
public boolean retainAll(Collection<?> collection) {
throw new UnsupportedOperationException();
}
};
}
@Override
public boolean equals(Object object) {
throw new UnsupportedOperationException();
}
@Override
public boolean remove(Object element) {
throw new UnsupportedOperationException();
}
@Override
public boolean setCount(String element, int oldCount, int newCount) {
throw new UnsupportedOperationException();
}
@Override
public int setCount(String element, int count) {
throw new UnsupportedOperationException();
}
@Override
public boolean add(String element) {
throw new UnsupportedOperationException();
}
@Override
public boolean addAll(Collection<? extends String> collection) {
throw new UnsupportedOperationException();
}
@Override
public Iterator<String> iterator() {
throw new UnsupportedOperationException();
}
@Override
public boolean removeAll(Collection<?> collection) {
throw new UnsupportedOperationException();
}
@Override
public boolean retainAll(Collection<?> collection) {
throw new UnsupportedOperationException();
}
@Override
public int size() {
throw new UnsupportedOperationException();
}
}.elementSet();
}
}).named("standardElementSet tripwire").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_VALUES, CollectionFeature.REMOVE_OPERATIONS).createTestSuite());
return suite;
}
use of com.google.common.collect.testing.TestStringSetGenerator in project guava by hceylan.
the class SetsTest method suite.
@GwtIncompatible("suite")
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(SetsTest.class);
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
int size = elements.length;
// Remove last element, if size > 1
Set<String> set1 = (size > 1) ? Sets.newHashSet(Arrays.asList(elements).subList(0, size - 1)) : Sets.newHashSet(elements);
// Remove first element, if size > 0
Set<String> set2 = (size > 0) ? Sets.newHashSet(Arrays.asList(elements).subList(1, size)) : Sets.<String>newHashSet();
return Sets.union(set1, set2);
}
}).named("Sets.union").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_VALUES).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
Set<String> set1 = Sets.newHashSet(elements);
set1.add(samples().e3);
Set<String> set2 = Sets.newHashSet(elements);
set2.add(samples().e4);
return Sets.intersection(set1, set2);
}
}).named("Sets.intersection").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_VALUES).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
Set<String> set1 = Sets.newHashSet(elements);
set1.add(samples().e3);
Set<String> set2 = Sets.newHashSet(samples().e3);
return Sets.difference(set1, set2);
}
}).named("Sets.difference").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_VALUES).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestEnumSetGenerator() {
@Override
protected Set<AnEnum> create(AnEnum[] elements) {
AnEnum[] otherElements = new AnEnum[elements.length - 1];
System.arraycopy(elements, 1, otherElements, 0, otherElements.length);
return Sets.immutableEnumSet(elements[0], otherElements);
}
}).named("Sets.immutableEnumSet").withFeatures(CollectionSize.ONE, CollectionSize.SEVERAL, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
suite.addTest(NavigableSetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
SafeTreeSet<String> set = new SafeTreeSet<String>(Arrays.asList(elements));
return Sets.unmodifiableNavigableSet(set);
}
@Override
public List<String> order(List<String> insertionOrder) {
return Ordering.natural().sortedCopy(insertionOrder);
}
}).named("Sets.unmodifiableNavigableSet[TreeSet]").withFeatures(CollectionSize.ANY, CollectionFeature.KNOWN_ORDER).createTestSuite());
suite.addTest(NavigableSetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
SafeTreeSet<String> set = new SafeTreeSet<String>(Arrays.asList(elements));
return SerializableTester.reserialize(Sets.unmodifiableNavigableSet(set));
}
@Override
public List<String> order(List<String> insertionOrder) {
return Ordering.natural().sortedCopy(insertionOrder);
}
}).named("Sets.unmodifiableNavigableSet[TreeSet], reserialized").withFeatures(CollectionSize.ANY, CollectionFeature.KNOWN_ORDER).createTestSuite());
suite.addTest(testsForFilter());
suite.addTest(testsForFilterNoNulls());
suite.addTest(testsForFilterFiltered());
return suite;
}
use of com.google.common.collect.testing.TestStringSetGenerator in project guava by google.
the class CompactHashSetTest method suite.
public static Test suite() {
List<Feature<?>> allFeatures = Arrays.<Feature<?>>asList(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_VALUES, CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION, CollectionFeature.GENERAL_PURPOSE, CollectionFeature.REMOVE_OPERATIONS, CollectionFeature.SERIALIZABLE, CollectionFeature.SUPPORTS_ADD, CollectionFeature.SUPPORTS_REMOVE);
TestSuite suite = new TestSuite();
suite.addTestSuite(CompactHashSetTest.class);
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
return CompactHashSet.create(Arrays.asList(elements));
}
}).named("CompactHashSet").withFeatures(allFeatures).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
CompactHashSet<String> set = CompactHashSet.create();
set.convertToHashFloodingResistantImplementation();
Collections.addAll(set, elements);
return set;
}
}).named("CompactHashSet with flooding protection").withFeatures(allFeatures).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
CompactHashSet set = CompactHashSet.create(Arrays.asList(elements));
for (int i = 0; i < 100; i++) {
set.add(i);
}
for (int i = 0; i < 100; i++) {
set.remove(i);
}
set.trimToSize();
return set;
}
}).named("CompactHashSet#TrimToSize").withFeatures(allFeatures).createTestSuite());
return suite;
}
use of com.google.common.collect.testing.TestStringSetGenerator in project guava by google.
the class SetOperationsTest method suite.
// suite
@GwtIncompatible
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"));
}
}).named("set - disjoint").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_VALUES).createTestSuite());
suite.addTestSuite(SetOperationsTest.class);
return suite;
}
Aggregations