use of com.google.common.collect.testing.TestStringSetGenerator in project guava by google.
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<>(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<>(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 boolean add(String element) {
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 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 google.
the class ForwardingNavigableSetTest method suite.
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(ForwardingNavigableSetTest.class);
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
return new StandardImplForwardingNavigableSet<>(new SafeTreeSet<String>(Arrays.asList(elements)));
}
@Override
public List<String> order(List<String> insertionOrder) {
return Lists.newArrayList(Sets.newTreeSet(insertionOrder));
}
}).named("ForwardingNavigableSet[SafeTreeSet] with standard implementations").withFeatures(CollectionSize.ANY, CollectionFeature.KNOWN_ORDER, CollectionFeature.GENERAL_PURPOSE).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
SafeTreeSet<String> set = new SafeTreeSet<>(Ordering.natural().nullsFirst());
Collections.addAll(set, elements);
return new StandardImplForwardingNavigableSet<>(set);
}
@Override
public List<String> order(List<String> insertionOrder) {
return Lists.newArrayList(Sets.newTreeSet(insertionOrder));
}
}).named("ForwardingNavigableSet[SafeTreeSet[Ordering.natural.nullsFirst]]" + " with standard implementations").withFeatures(CollectionSize.ANY, CollectionFeature.KNOWN_ORDER, CollectionFeature.GENERAL_PURPOSE, CollectionFeature.ALLOWS_NULL_VALUES).createTestSuite());
return suite;
}
use of com.google.common.collect.testing.TestStringSetGenerator in project guava by google.
the class ImmutableSetTest method suite.
// suite
@GwtIncompatible
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(SetTestSuiteBuilder.using(new ImmutableSetCopyOfGenerator()).named(ImmutableSetTest.class.getName()).withFeatures(CollectionSize.ANY, CollectionFeature.KNOWN_ORDER, CollectionFeature.SERIALIZABLE, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new ImmutableSetUnsizedBuilderGenerator()).named(ImmutableSetTest.class.getName() + ", with unsized builder").withFeatures(CollectionSize.ANY, CollectionFeature.KNOWN_ORDER, CollectionFeature.SERIALIZABLE, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
ImmutableSet.Builder<String> builder = ImmutableSet.builder();
builder.forceJdk();
builder.add(elements);
return builder.build();
}
}).named(ImmutableSetTest.class.getName() + ", with JDK builder").withFeatures(CollectionSize.ANY, CollectionFeature.KNOWN_ORDER, CollectionFeature.SERIALIZABLE, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new ImmutableSetSizedBuilderGenerator()).named(ImmutableSetTest.class.getName() + ", with exactly sized builder").withFeatures(CollectionSize.ANY, CollectionFeature.KNOWN_ORDER, CollectionFeature.SERIALIZABLE, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new ImmutableSetTooBigBuilderGenerator()).named(ImmutableSetTest.class.getName() + ", with oversized builder").withFeatures(CollectionSize.ANY, CollectionFeature.KNOWN_ORDER, CollectionFeature.SERIALIZABLE, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new ImmutableSetTooSmallBuilderGenerator()).named(ImmutableSetTest.class.getName() + ", with undersized builder").withFeatures(CollectionSize.ANY, CollectionFeature.KNOWN_ORDER, CollectionFeature.SERIALIZABLE, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new ImmutableSetWithBadHashesGenerator()).named(ImmutableSetTest.class.getName() + ", with bad hashes").withFeatures(CollectionSize.ANY, CollectionFeature.KNOWN_ORDER, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new DegeneratedImmutableSetGenerator()).named(ImmutableSetTest.class.getName() + ", degenerate").withFeatures(CollectionSize.ONE, CollectionFeature.KNOWN_ORDER, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
suite.addTest(ListTestSuiteBuilder.using(new ImmutableSetAsListGenerator()).named("ImmutableSet.asList").withFeatures(CollectionSize.ANY, CollectionFeature.REJECTS_DUPLICATES_AT_CREATION, CollectionFeature.SERIALIZABLE, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
suite.addTestSuite(ImmutableSetTest.class);
suite.addTestSuite(FloodingTest.class);
return suite;
}
use of com.google.common.collect.testing.TestStringSetGenerator in project guava by google.
the class CompactLinkedHashSetTest 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.KNOWN_ORDER, CollectionFeature.SUPPORTS_ADD, CollectionFeature.SUPPORTS_REMOVE);
TestSuite suite = new TestSuite();
suite.addTestSuite(CompactLinkedHashSetTest.class);
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
return CompactLinkedHashSet.create(Arrays.asList(elements));
}
}).named("CompactLinkedHashSet").withFeatures(allFeatures).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
CompactLinkedHashSet<String> set = CompactLinkedHashSet.create();
set.convertToHashFloodingResistantImplementation();
Collections.addAll(set, elements);
return set;
}
}).named("CompactLinkedHashSet with flooding protection").withFeatures(allFeatures).createTestSuite());
return suite;
}
use of com.google.common.collect.testing.TestStringSetGenerator in project guava by google.
the class ImmutableMultisetTest method suite.
// suite // TODO(cpovirk): add to collect/gwt/suites
@GwtIncompatible
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(ImmutableMultisetTest.class);
suite.addTestSuite(FloodingTest.class);
suite.addTest(MultisetTestSuiteBuilder.using(new TestStringMultisetGenerator() {
@Override
protected Multiset<String> create(String[] elements) {
return ImmutableMultiset.copyOf(elements);
}
}).named("ImmutableMultiset").withFeatures(CollectionSize.ANY, CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
suite.addTest(MultisetTestSuiteBuilder.using(new TestStringMultisetGenerator() {
@Override
protected Multiset<String> create(String[] elements) {
return ImmutableMultiset.<String>builder().add(elements).buildJdkBacked();
}
}).named("ImmutableMultiset [JDK backed]").withFeatures(CollectionSize.ANY, CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
return ImmutableMultiset.copyOf(elements).elementSet();
}
}).named("ImmutableMultiset, element set").withFeatures(CollectionSize.ANY, CollectionFeature.SERIALIZABLE, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {
@Override
protected List<String> create(String[] elements) {
return ImmutableMultiset.copyOf(elements).asList();
}
@Override
public List<String> order(List<String> insertionOrder) {
List<String> order = new ArrayList<>();
for (String s : insertionOrder) {
int index = order.indexOf(s);
if (index == -1) {
order.add(s);
} else {
order.add(index, s);
}
}
return order;
}
}).named("ImmutableMultiset.asList").withFeatures(CollectionSize.ANY, CollectionFeature.SERIALIZABLE, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {
@Override
protected List<String> create(String[] elements) {
Set<String> set = new HashSet<>();
ImmutableMultiset.Builder<String> builder = ImmutableMultiset.builder();
for (String s : elements) {
checkArgument(set.add(s));
builder.addCopies(s, 2);
}
ImmutableSet<String> elementSet = (ImmutableSet<String>) builder.build().elementSet();
return elementSet.asList();
}
}).named("ImmutableMultiset.elementSet.asList").withFeatures(CollectionSize.ANY, CollectionFeature.REJECTS_DUPLICATES_AT_CREATION, CollectionFeature.SERIALIZABLE, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
return suite;
}
Aggregations