Search in sources :

Example 6 with SampleElements

use of com.google.common.collect.testing.SampleElements in project guava by hceylan.

the class ListsTest method suite.

@GwtIncompatible("suite")
public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTestSuite(ListsTest.class);
    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {

        @Override
        protected List<String> create(String[] elements) {
            String[] rest = new String[elements.length - 1];
            System.arraycopy(elements, 1, rest, 0, elements.length - 1);
            return Lists.asList(elements[0], rest);
        }
    }).named("Lists.asList, 2 parameter").withFeatures(CollectionSize.SEVERAL, CollectionSize.ONE, CollectionFeature.SERIALIZABLE, CollectionFeature.ALLOWS_NULL_VALUES).createTestSuite());
    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {

        @Override
        protected List<String> create(String[] elements) {
            String[] rest = new String[elements.length - 2];
            System.arraycopy(elements, 2, rest, 0, elements.length - 2);
            return Lists.asList(elements[0], elements[1], rest);
        }
    }).named("Lists.asList, 3 parameter").withFeatures(CollectionSize.SEVERAL, CollectionFeature.SERIALIZABLE, CollectionFeature.ALLOWS_NULL_VALUES).createTestSuite());
    final Function<String, String> removeFirst = new RemoveFirstFunction();
    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {

        @Override
        protected List<String> create(String[] elements) {
            List<String> fromList = Lists.newArrayList();
            for (String element : elements) {
                fromList.add("q" + checkNotNull(element));
            }
            return Lists.transform(fromList, removeFirst);
        }
    }).named("Lists.transform, random access, no nulls").withFeatures(CollectionSize.ANY, ListFeature.REMOVE_OPERATIONS, CollectionFeature.SERIALIZABLE, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {

        @Override
        protected List<String> create(String[] elements) {
            List<String> fromList = Lists.newLinkedList();
            for (String element : elements) {
                fromList.add("q" + checkNotNull(element));
            }
            return Lists.transform(fromList, removeFirst);
        }
    }).named("Lists.transform, sequential access, no nulls").withFeatures(CollectionSize.ANY, ListFeature.REMOVE_OPERATIONS, CollectionFeature.SERIALIZABLE, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {

        @Override
        protected List<String> create(String[] elements) {
            List<String> fromList = Lists.newArrayList(elements);
            return Lists.transform(fromList, Functions.<String>identity());
        }
    }).named("Lists.transform, random access, nulls").withFeatures(CollectionSize.ANY, ListFeature.REMOVE_OPERATIONS, CollectionFeature.SERIALIZABLE, CollectionFeature.ALLOWS_NULL_VALUES).createTestSuite());
    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {

        @Override
        protected List<String> create(String[] elements) {
            List<String> fromList = Lists.newLinkedList(asList(elements));
            return Lists.transform(fromList, Functions.<String>identity());
        }
    }).named("Lists.transform, sequential access, nulls").withFeatures(CollectionSize.ANY, ListFeature.REMOVE_OPERATIONS, CollectionFeature.SERIALIZABLE, CollectionFeature.ALLOWS_NULL_VALUES).createTestSuite());
    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {

        @Override
        protected List<String> create(String[] elements) {
            List<String> list = Lists.newArrayList();
            for (int i = elements.length - 1; i >= 0; i--) list.add(elements[i]);
            return Lists.reverse(list);
        }
    }).named("Lists.reverse[ArrayList]").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_VALUES, ListFeature.GENERAL_PURPOSE).createTestSuite());
    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {

        @Override
        protected List<String> create(String[] elements) {
            String[] reverseElements = new String[elements.length];
            for (int i = elements.length - 1, j = 0; i >= 0; i--, j++) reverseElements[j] = elements[i];
            return Lists.reverse(asList(reverseElements));
        }
    }).named("Lists.reverse[Arrays.asList]").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_VALUES, ListFeature.SUPPORTS_SET).createTestSuite());
    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {

        @Override
        protected List<String> create(String[] elements) {
            List<String> list = Lists.newLinkedList();
            for (int i = elements.length - 1; i >= 0; i--) list.add(elements[i]);
            return Lists.reverse(list);
        }
    }).named("Lists.reverse[LinkedList]").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_VALUES, ListFeature.GENERAL_PURPOSE).createTestSuite());
    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {

        @Override
        protected List<String> create(String[] elements) {
            ImmutableList.Builder<String> builder = ImmutableList.builder();
            for (int i = elements.length - 1; i >= 0; i--) builder.add(elements[i]);
            return Lists.reverse(builder.build());
        }
    }).named("Lists.reverse[ImmutableList]").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
    suite.addTest(ListTestSuiteBuilder.using(new TestListGenerator<Character>() {

        @Override
        public List<Character> create(Object... elements) {
            char[] chars = new char[elements.length];
            for (int i = 0; i < elements.length; i++) chars[i] = (Character) elements[i];
            return Lists.charactersOf(String.copyValueOf(chars));
        }

        @Override
        public Character[] createArray(int length) {
            return new Character[length];
        }

        @Override
        public Iterable<Character> order(List<Character> insertionOrder) {
            return ImmutableList.copyOf(insertionOrder);
        }

        @Override
        public SampleElements<Character> samples() {
            return new SampleElements<Character>('a', 'b', 'c', 'd', 'e');
        }
    }).named("Lists.charactersOf[String]").withFeatures(CollectionSize.ANY, CollectionFeature.SERIALIZABLE, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
    suite.addTest(ListTestSuiteBuilder.using(new TestListGenerator<Character>() {

        @Override
        public List<Character> create(Object... elements) {
            char[] chars = new char[elements.length];
            for (int i = 0; i < elements.length; i++) chars[i] = (Character) elements[i];
            StringBuilder str = new StringBuilder();
            str.append(chars);
            return Lists.charactersOf(str);
        }

        @Override
        public Character[] createArray(int length) {
            return new Character[length];
        }

        @Override
        public Iterable<Character> order(List<Character> insertionOrder) {
            return ImmutableList.copyOf(insertionOrder);
        }

        @Override
        public SampleElements<Character> samples() {
            return new SampleElements<Character>('a', 'b', 'c', 'd', 'e');
        }
    }).named("Lists.charactersOf[CharSequence]").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
    return suite;
}
Also used : ListTestSuiteBuilder(com.google.common.collect.testing.ListTestSuiteBuilder) TestStringListGenerator(com.google.common.collect.testing.TestStringListGenerator) TestSuite(junit.framework.TestSuite) SampleElements(com.google.common.collect.testing.SampleElements) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) LinkedList(java.util.LinkedList) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Aggregations

SampleElements (com.google.common.collect.testing.SampleElements)6 TestSuite (junit.framework.TestSuite)6 GwtIncompatible (com.google.common.annotations.GwtIncompatible)4 List (java.util.List)4 Set (java.util.Set)4 Function (com.google.common.base.Function)3 TestStringSetGenerator (com.google.common.collect.testing.TestStringSetGenerator)3 Collection (java.util.Collection)3 Entry (java.util.Map.Entry)3 SortedSet (java.util.SortedSet)3 Cell (com.google.common.collect.Table.Cell)2 Helpers.mapEntry (com.google.common.collect.testing.Helpers.mapEntry)2 TestStringCollectionGenerator (com.google.common.collect.testing.TestStringCollectionGenerator)2 TestStringSortedSetGenerator (com.google.common.collect.testing.TestStringSortedSetGenerator)2 Map (java.util.Map)2 NavigableMap (java.util.NavigableMap)2 NavigableSet (java.util.NavigableSet)2 ListTestSuiteBuilder (com.google.common.collect.testing.ListTestSuiteBuilder)1 SafeTreeMap (com.google.common.collect.testing.SafeTreeMap)1 TestStringListGenerator (com.google.common.collect.testing.TestStringListGenerator)1