Search in sources :

Example 6 with TestStringListGenerator

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

the class ForwardingListTest method suite.

public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTestSuite(ForwardingListTest.class);
    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {

        @Override
        protected List<String> create(String[] elements) {
            return new StandardImplForwardingList<String>(Lists.newArrayList(elements));
        }
    }).named("ForwardingList[ArrayList] with standard implementations").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_VALUES, ListFeature.GENERAL_PURPOSE).createTestSuite());
    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {

        @Override
        protected List<String> create(String[] elements) {
            return new StandardImplForwardingList<String>(ImmutableList.copyOf(elements));
        }
    }).named("ForwardingList[ImmutableList] with standard implementations").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
    return suite;
}
Also used : TestSuite(junit.framework.TestSuite) List(java.util.List) TestStringListGenerator(com.google.common.collect.testing.TestStringListGenerator)

Example 7 with TestStringListGenerator

use of com.google.common.collect.testing.TestStringListGenerator 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

TestStringListGenerator (com.google.common.collect.testing.TestStringListGenerator)7 List (java.util.List)7 TestSuite (junit.framework.TestSuite)7 ListTestSuiteBuilder (com.google.common.collect.testing.ListTestSuiteBuilder)5 ArrayList (java.util.ArrayList)4 Arrays.asList (java.util.Arrays.asList)4 GwtIncompatible (com.google.common.annotations.GwtIncompatible)3 TestStringMultisetGenerator (com.google.common.collect.testing.google.TestStringMultisetGenerator)3 Set (java.util.Set)3 SetTestSuiteBuilder (com.google.common.collect.testing.SetTestSuiteBuilder)2 TestStringSetGenerator (com.google.common.collect.testing.TestStringSetGenerator)2 MultisetTestSuiteBuilder (com.google.common.collect.testing.google.MultisetTestSuiteBuilder)2 Collections.singletonList (java.util.Collections.singletonList)2 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 CollectionTestSuiteBuilder (com.google.common.collect.testing.CollectionTestSuiteBuilder)1 SampleElements (com.google.common.collect.testing.SampleElements)1 TestStringCollectionGenerator (com.google.common.collect.testing.TestStringCollectionGenerator)1 TestStringSortedSetGenerator (com.google.common.collect.testing.TestStringSortedSetGenerator)1