Search in sources :

Example 16 with TestStringSetGenerator

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;
}
Also used : ImmutableSetUnsizedBuilderGenerator(com.google.common.collect.testing.google.SetGenerators.ImmutableSetUnsizedBuilderGenerator) Set(java.util.Set) Builder(com.google.common.collect.ImmutableSet.Builder) ListTestSuiteBuilder(com.google.common.collect.testing.ListTestSuiteBuilder) SetTestSuiteBuilder(com.google.common.collect.testing.SetTestSuiteBuilder) ImmutableSetTooBigBuilderGenerator(com.google.common.collect.testing.google.SetGenerators.ImmutableSetTooBigBuilderGenerator) ImmutableSetCopyOfGenerator(com.google.common.collect.testing.google.SetGenerators.ImmutableSetCopyOfGenerator) DegeneratedImmutableSetGenerator(com.google.common.collect.testing.google.SetGenerators.DegeneratedImmutableSetGenerator) ImmutableSetAsListGenerator(com.google.common.collect.testing.google.SetGenerators.ImmutableSetAsListGenerator) TestStringSetGenerator(com.google.common.collect.testing.TestStringSetGenerator) TestSuite(junit.framework.TestSuite) ImmutableSetWithBadHashesGenerator(com.google.common.collect.testing.google.SetGenerators.ImmutableSetWithBadHashesGenerator) ImmutableSetSizedBuilderGenerator(com.google.common.collect.testing.google.SetGenerators.ImmutableSetSizedBuilderGenerator) ImmutableSetTooSmallBuilderGenerator(com.google.common.collect.testing.google.SetGenerators.ImmutableSetTooSmallBuilderGenerator) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Example 17 with TestStringSetGenerator

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;
}
Also used : TreeSet(java.util.TreeSet) Set(java.util.Set) TestStringSetGenerator(com.google.common.collect.testing.TestStringSetGenerator) Helpers.mapEntry(com.google.common.collect.testing.Helpers.mapEntry) Entry(java.util.Map.Entry) TestSuite(junit.framework.TestSuite) TestStringListMultimapGenerator(com.google.common.collect.testing.google.TestStringListMultimapGenerator) TestStringMultisetGenerator(com.google.common.collect.testing.google.TestStringMultisetGenerator)

Example 18 with TestStringSetGenerator

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;
}
Also used : TestStringSetGenerator(com.google.common.collect.testing.TestStringSetGenerator) Sets.unmodifiableNavigableSet(com.google.common.collect.Sets.unmodifiableNavigableSet) NavigableSet(java.util.NavigableSet) SortedSet(java.util.SortedSet) Sets.unmodifiableNavigableSet(com.google.common.collect.Sets.unmodifiableNavigableSet) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) Sets.newEnumSet(com.google.common.collect.Sets.newEnumSet) EnumSet(java.util.EnumSet) Set(java.util.Set) NavigableSet(java.util.NavigableSet) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) Sets.powerSet(com.google.common.collect.Sets.powerSet) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Collections.emptySet(java.util.Collections.emptySet) Sets.newLinkedHashSet(com.google.common.collect.Sets.newLinkedHashSet) SafeTreeSet(com.google.common.collect.testing.SafeTreeSet) TestSuite(junit.framework.TestSuite) List(java.util.List) ArrayList(java.util.ArrayList) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Example 19 with TestStringSetGenerator

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;
}
Also used : SortedSet(java.util.SortedSet) Sets.unmodifiableNavigableSet(com.google.common.collect.Sets.unmodifiableNavigableSet) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) Sets.newEnumSet(com.google.common.collect.Sets.newEnumSet) EnumSet(java.util.EnumSet) Set(java.util.Set) NavigableSet(java.util.NavigableSet) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) Sets.powerSet(com.google.common.collect.Sets.powerSet) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Collections.emptySet(java.util.Collections.emptySet) Sets.newLinkedHashSet(com.google.common.collect.Sets.newLinkedHashSet) SafeTreeSet(com.google.common.collect.testing.SafeTreeSet) SafeTreeSet(com.google.common.collect.testing.SafeTreeSet) TestStringSetGenerator(com.google.common.collect.testing.TestStringSetGenerator) TestSuite(junit.framework.TestSuite) AnEnum(com.google.common.collect.testing.AnEnum) List(java.util.List) ArrayList(java.util.ArrayList) TestEnumSetGenerator(com.google.common.collect.testing.TestEnumSetGenerator) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Example 20 with TestStringSetGenerator

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;
}
Also used : TestStringSetGenerator(com.google.common.collect.testing.TestStringSetGenerator) Set(java.util.Set) TestSuite(junit.framework.TestSuite) TestStringMultisetGenerator(com.google.common.collect.testing.google.TestStringMultisetGenerator) List(java.util.List) Arrays.asList(java.util.Arrays.asList)

Aggregations

TestStringSetGenerator (com.google.common.collect.testing.TestStringSetGenerator)24 Set (java.util.Set)24 TestSuite (junit.framework.TestSuite)24 List (java.util.List)13 GwtIncompatible (com.google.common.annotations.GwtIncompatible)11 SortedSet (java.util.SortedSet)10 TestStringMultisetGenerator (com.google.common.collect.testing.google.TestStringMultisetGenerator)8 SafeTreeSet (com.google.common.collect.testing.SafeTreeSet)6 Collection (java.util.Collection)6 HashSet (java.util.HashSet)6 NavigableSet (java.util.NavigableSet)5 TreeSet (java.util.TreeSet)5 ArrayList (java.util.ArrayList)4 Sets.newEnumSet (com.google.common.collect.Sets.newEnumSet)3 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)3 Sets.powerSet (com.google.common.collect.Sets.powerSet)3 ListTestSuiteBuilder (com.google.common.collect.testing.ListTestSuiteBuilder)3 SampleElements (com.google.common.collect.testing.SampleElements)3 SetTestSuiteBuilder (com.google.common.collect.testing.SetTestSuiteBuilder)3 TestStringCollectionGenerator (com.google.common.collect.testing.TestStringCollectionGenerator)3