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 MultimapsCollectionTest method suite.
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(transformSuite());
suite.addTest(filterSuite());
suite.addTest(ListMultimapTestSuiteBuilder.using(new TestStringListMultimapGenerator() {
@Override
protected ListMultimap<String, String> create(Entry<String, String>[] entries) {
ListMultimap<String, String> multimap = Multimaps.synchronizedListMultimap(ArrayListMultimap.<String, String>create());
for (Entry<String, String> entry : entries) {
multimap.put(entry.getKey(), entry.getValue());
}
return multimap;
}
}).named("synchronized ArrayListMultimap").withFeatures(MapFeature.ALLOWS_NULL_KEYS, MapFeature.ALLOWS_NULL_VALUES, MapFeature.ALLOWS_ANY_NULL_QUERIES, MapFeature.GENERAL_PURPOSE, MapFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION, CollectionFeature.SUPPORTS_ITERATOR_REMOVE, CollectionSize.ANY).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
PopulatableMapAsMultimap<Integer, String> multimap = PopulatableMapAsMultimap.create();
populateMultimapForGet(multimap, elements);
return multimap.build().get(3);
}
}).named("Multimaps.forMap.get").withFeatures(FOR_MAP_FEATURES_ONE).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
PopulatableMapAsMultimap<String, Integer> multimap = PopulatableMapAsMultimap.create();
populateMultimapForKeySet(multimap, elements);
return multimap.build().keySet();
}
}).named("Multimaps.forMap.keySet").withFeatures(FOR_MAP_FEATURES_ANY).createTestSuite());
// TODO: use collection testers on Multimaps.forMap.values
suite.addTest(MultisetTestSuiteBuilder.using(new TestStringMultisetGenerator() {
@Override
protected Multiset<String> create(String[] elements) {
PopulatableMapAsMultimap<String, Integer> multimap = PopulatableMapAsMultimap.create();
populateMultimapForKeys(multimap, elements);
return multimap.build().keys();
}
}).named("Multimaps.forMap.keys").withFeatures(FOR_MAP_FEATURES_ANY).suppressing(getCountDuplicateInitializingMethods()).suppressing(getSetCountDuplicateInitializingMethods()).suppressing(getIteratorDuplicateInitializingMethods()).suppressing(getRemoveDuplicateInitializingMethods()).suppressing(getForEachEntryDuplicateInitializingMethods()).suppressing(getElementSetDuplicateInitializingMethods()).createTestSuite());
return suite;
}
use of com.google.common.collect.testing.TestStringSetGenerator in project guava by google.
the class SetsTest method testsForFilterNoNulls.
// suite
@GwtIncompatible
private static Test testsForFilterNoNulls() {
TestSuite suite = new TestSuite();
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
public Set<String> create(String[] elements) {
Set<String> unfiltered = Sets.newLinkedHashSet();
unfiltered.add("yyy");
unfiltered.addAll(ImmutableList.copyOf(elements));
unfiltered.add("zzz");
return Sets.filter(unfiltered, Collections2Test.LENGTH_1);
}
}).named("Sets.filter, no nulls").withFeatures(CollectionFeature.SUPPORTS_ADD, CollectionFeature.SUPPORTS_REMOVE, CollectionFeature.KNOWN_ORDER, CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
suite.addTest(NavigableSetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
public NavigableSet<String> create(String[] elements) {
NavigableSet<String> unfiltered = Sets.newTreeSet();
unfiltered.add("yyy");
unfiltered.addAll(ImmutableList.copyOf(elements));
unfiltered.add("zzz");
return Sets.filter(unfiltered, Collections2Test.LENGTH_1);
}
@Override
public List<String> order(List<String> insertionOrder) {
return Ordering.natural().sortedCopy(insertionOrder);
}
}).named("Sets.filter[NavigableSet]").withFeatures(CollectionFeature.SUPPORTS_ADD, CollectionFeature.SUPPORTS_REMOVE, CollectionFeature.KNOWN_ORDER, CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
return suite;
}
use of com.google.common.collect.testing.TestStringSetGenerator in project guava by google.
the class SetsTest method suite.
// suite
@GwtIncompatible
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) {
return Sets.newConcurrentHashSet(Arrays.asList(elements));
}
}).named("Sets.newConcurrentHashSet").withFeatures(CollectionSize.ANY, SetFeature.GENERAL_PURPOSE).createTestSuite());
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<>(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, CollectionFeature.SERIALIZABLE).createTestSuite());
suite.addTest(testsForFilter());
suite.addTest(testsForFilterNoNulls());
suite.addTest(testsForFilterFiltered());
return suite;
}
use of com.google.common.collect.testing.TestStringSetGenerator in project guava by hceylan.
the class ImmutableSortedMultisetTest method suite.
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(ImmutableSortedMultisetTest.class);
suite.addTest(SortedMultisetTestSuiteBuilder.using(new TestStringMultisetGenerator() {
@Override
protected Multiset<String> create(String[] elements) {
return ImmutableSortedMultiset.copyOf(elements);
}
@Override
public List<String> order(List<String> insertionOrder) {
return Ordering.natural().sortedCopy(insertionOrder);
}
}).named("ImmutableSortedMultiset").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 SerializableTester.reserialize(ImmutableSortedMultiset.copyOf(elements).elementSet());
}
@Override
public List<String> order(List<String> insertionOrder) {
return Ordering.natural().immutableSortedCopy(insertionOrder);
}
}).named("ImmutableSortedMultiset, element set").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
return suite;
}
Aggregations