Search in sources :

Example 1 with SafeTreeMap

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

the class ForwardingNavigableMapTest method suite.

public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTestSuite(ForwardingNavigableMapTest.class);
    suite.addTest(NavigableMapTestSuiteBuilder.using(new TestStringSortedMapGenerator() {

        @Override
        protected SortedMap<String, String> create(Entry<String, String>[] entries) {
            NavigableMap<String, String> map = new SafeTreeMap<String, String>();
            for (Entry<String, String> entry : entries) {
                map.put(entry.getKey(), entry.getValue());
            }
            return new StandardImplForwardingNavigableMap<String, String>(map);
        }
    }).named("ForwardingNavigableMap[SafeTreeMap] with no comparator and standard " + "implementations").withFeatures(CollectionSize.ANY, CollectionFeature.KNOWN_ORDER, MapFeature.ALLOWS_NULL_VALUES, CollectionFeature.SUPPORTS_ITERATOR_REMOVE, MapFeature.GENERAL_PURPOSE).suppressing(MapEntrySetTester.getSetValueMethod()).createTestSuite());
    // TODO(lowasser): add forwarding-to-ImmutableSortedMap test
    return suite;
}
Also used : TestSuite(junit.framework.TestSuite) SafeTreeMap(com.google.common.collect.testing.SafeTreeMap) TestStringSortedMapGenerator(com.google.common.collect.testing.TestStringSortedMapGenerator)

Example 2 with SafeTreeMap

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

the class ForwardingSortedMapTest method suite.

public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTestSuite(ForwardingSortedMapTest.class);
    suite.addTest(MapTestSuiteBuilder.using(new TestStringMapGenerator() {

        @Override
        protected Map<String, String> create(Entry<String, String>[] entries) {
            SortedMap<String, String> map = new SafeTreeMap<String, String>();
            for (Entry<String, String> entry : entries) {
                map.put(entry.getKey(), entry.getValue());
            }
            return new StandardImplForwardingSortedMap<String, String>(map);
        }

        @Override
        public Iterable<Entry<String, String>> order(List<Entry<String, String>> insertionOrder) {
            return sort(insertionOrder);
        }
    }).named("ForwardingSortedMap[SafeTreeMap] with no comparator and standard " + "implementations").withFeatures(CollectionSize.ANY, CollectionFeature.KNOWN_ORDER, MapFeature.ALLOWS_NULL_VALUES, MapFeature.GENERAL_PURPOSE).createTestSuite());
    suite.addTest(MapTestSuiteBuilder.using(new TestStringMapGenerator() {

        private final Comparator<String> comparator = Ordering.natural().nullsFirst();

        @Override
        protected Map<String, String> create(Entry<String, String>[] entries) {
            SortedMap<String, String> map = new SafeTreeMap<String, String>(comparator);
            for (Entry<String, String> entry : entries) {
                map.put(entry.getKey(), entry.getValue());
            }
            return new StandardImplForwardingSortedMap<String, String>(map);
        }

        @Override
        public Iterable<Entry<String, String>> order(List<Entry<String, String>> insertionOrder) {
            return sort(insertionOrder);
        }
    }).named("ForwardingSortedMap[SafeTreeMap] with natural comparator and " + "standard implementations").withFeatures(CollectionSize.ANY, CollectionFeature.KNOWN_ORDER, MapFeature.ALLOWS_NULL_VALUES, MapFeature.ALLOWS_NULL_KEYS, MapFeature.GENERAL_PURPOSE).createTestSuite());
    suite.addTest(MapTestSuiteBuilder.using(new TestStringMapGenerator() {

        @Override
        protected Map<String, String> create(Entry<String, String>[] entries) {
            ImmutableSortedMap.Builder<String, String> builder = ImmutableSortedMap.naturalOrder();
            for (Entry<String, String> entry : entries) {
                builder.put(entry.getKey(), entry.getValue());
            }
            return new StandardImplForwardingSortedMap<String, String>(builder.build());
        }

        @Override
        public Iterable<Entry<String, String>> order(List<Entry<String, String>> insertionOrder) {
            return sort(insertionOrder);
        }
    }).named("ForwardingSortedMap[ImmutableSortedMap] with standard " + "implementations").withFeatures(CollectionSize.ANY, MapFeature.REJECTS_DUPLICATES_AT_CREATION, MapFeature.ALLOWS_NULL_QUERIES).createTestSuite());
    return suite;
}
Also used : MapTestSuiteBuilder(com.google.common.collect.testing.MapTestSuiteBuilder) Entry(java.util.Map.Entry) TestSuite(junit.framework.TestSuite) SortedMap(java.util.SortedMap) TestStringMapGenerator(com.google.common.collect.testing.TestStringMapGenerator) SafeTreeMap(com.google.common.collect.testing.SafeTreeMap) Map(java.util.Map) SortedMap(java.util.SortedMap)

Example 3 with SafeTreeMap

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

the class MapsCollectionTest method suite.

public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTest(NavigableMapTestSuiteBuilder.using(new TestStringSortedMapGenerator() {

        @Override
        protected SortedMap<String, String> create(Entry<String, String>[] entries) {
            SafeTreeMap<String, String> map = new SafeTreeMap<String, String>();
            putEntries(map, entries);
            return Maps.unmodifiableNavigableMap(map);
        }
    }).named("unmodifiableNavigableMap[SafeTreeMap]").withFeatures(CollectionSize.ANY, MapFeature.ALLOWS_NULL_VALUES, CollectionFeature.SERIALIZABLE).createTestSuite());
    suite.addTest(BiMapTestSuiteBuilder.using(new TestStringBiMapGenerator() {

        @Override
        protected BiMap<String, String> create(Entry<String, String>[] entries) {
            BiMap<String, String> bimap = HashBiMap.create(entries.length);
            for (Entry<String, String> entry : entries) {
                checkArgument(!bimap.containsKey(entry.getKey()));
                bimap.put(entry.getKey(), entry.getValue());
            }
            return Maps.unmodifiableBiMap(bimap);
        }
    }).named("unmodifiableBiMap[HashBiMap]").withFeatures(CollectionSize.ANY, MapFeature.ALLOWS_NULL_VALUES, MapFeature.ALLOWS_NULL_KEYS, MapFeature.ALLOWS_ANY_NULL_QUERIES, MapFeature.REJECTS_DUPLICATES_AT_CREATION, CollectionFeature.SERIALIZABLE).createTestSuite());
    suite.addTest(MapTestSuiteBuilder.using(new TestMapGenerator<String, Integer>() {

        @Override
        public SampleElements<Entry<String, Integer>> samples() {
            return new SampleElements<Entry<String, Integer>>(mapEntry("x", 1), mapEntry("xxx", 3), mapEntry("xx", 2), mapEntry("xxxx", 4), mapEntry("aaaaa", 5));
        }

        @Override
        public Map<String, Integer> create(Object... elements) {
            Set<String> set = Sets.newLinkedHashSet();
            for (Object e : elements) {
                Entry<?, ?> entry = (Entry<?, ?>) e;
                checkNotNull(entry.getValue());
                set.add((String) checkNotNull(entry.getKey()));
            }
            return Maps.asMap(set, new Function<String, Integer>() {

                @Override
                public Integer apply(String input) {
                    return input.length();
                }
            });
        }

        @SuppressWarnings("unchecked")
        @Override
        public Entry<String, Integer>[] createArray(int length) {
            return new Entry[length];
        }

        @Override
        public Iterable<Entry<String, Integer>> order(List<Entry<String, Integer>> insertionOrder) {
            return insertionOrder;
        }

        @Override
        public String[] createKeyArray(int length) {
            return new String[length];
        }

        @Override
        public Integer[] createValueArray(int length) {
            return new Integer[length];
        }
    }).named("Maps.asMap[Set, Function]").withFeatures(CollectionSize.ANY, MapFeature.SUPPORTS_REMOVE, CollectionFeature.SUPPORTS_ITERATOR_REMOVE).createTestSuite());
    suite.addTest(SortedMapTestSuiteBuilder.using(new TestMapGenerator<String, Integer>() {

        @Override
        public String[] createKeyArray(int length) {
            return new String[length];
        }

        @Override
        public Integer[] createValueArray(int length) {
            return new Integer[length];
        }

        @Override
        public SampleElements<Entry<String, Integer>> samples() {
            return new SampleElements<Entry<String, Integer>>(mapEntry("a", 1), mapEntry("aa", 2), mapEntry("aba", 3), mapEntry("bbbb", 4), mapEntry("ccccc", 5));
        }

        @Override
        public SortedMap<String, Integer> create(Object... elements) {
            SortedSet<String> set = new NonNavigableSortedSet();
            for (Object e : elements) {
                Entry<?, ?> entry = (Entry<?, ?>) e;
                checkNotNull(entry.getValue());
                set.add((String) checkNotNull(entry.getKey()));
            }
            return Maps.asMap(set, new Function<String, Integer>() {

                @Override
                public Integer apply(String input) {
                    return input.length();
                }
            });
        }

        @SuppressWarnings("unchecked")
        @Override
        public Entry<String, Integer>[] createArray(int length) {
            return new Entry[length];
        }

        @Override
        public Iterable<Entry<String, Integer>> order(List<Entry<String, Integer>> insertionOrder) {
            Collections.sort(insertionOrder, new Comparator<Entry<String, Integer>>() {

                @Override
                public int compare(Entry<String, Integer> o1, Entry<String, Integer> o2) {
                    return o1.getKey().compareTo(o2.getKey());
                }
            });
            return insertionOrder;
        }
    }).named("Maps.asMap[SortedSet, Function]").withFeatures(CollectionSize.ANY, CollectionFeature.SUPPORTS_ITERATOR_REMOVE, MapFeature.SUPPORTS_REMOVE).createTestSuite());
    suite.addTest(NavigableMapTestSuiteBuilder.using(new TestMapGenerator<String, Integer>() {

        @Override
        public String[] createKeyArray(int length) {
            return new String[length];
        }

        @Override
        public Integer[] createValueArray(int length) {
            return new Integer[length];
        }

        @Override
        public SampleElements<Entry<String, Integer>> samples() {
            return new SampleElements<Entry<String, Integer>>(mapEntry("a", 1), mapEntry("aa", 2), mapEntry("aba", 3), mapEntry("bbbb", 4), mapEntry("ccccc", 5));
        }

        @Override
        public NavigableMap<String, Integer> create(Object... elements) {
            NavigableSet<String> set = Sets.newTreeSet(Ordering.natural());
            for (Object e : elements) {
                Map.Entry<?, ?> entry = (Entry<?, ?>) e;
                checkNotNull(entry.getValue());
                set.add((String) checkNotNull(entry.getKey()));
            }
            return Maps.asMap(set, new Function<String, Integer>() {

                @Override
                public Integer apply(String input) {
                    return input.length();
                }
            });
        }

        @SuppressWarnings("unchecked")
        @Override
        public Entry<String, Integer>[] createArray(int length) {
            return new Entry[length];
        }

        @Override
        public Iterable<Entry<String, Integer>> order(List<Entry<String, Integer>> insertionOrder) {
            Collections.sort(insertionOrder, new Comparator<Entry<String, Integer>>() {

                @Override
                public int compare(Entry<String, Integer> o1, Entry<String, Integer> o2) {
                    return o1.getKey().compareTo(o2.getKey());
                }
            });
            return insertionOrder;
        }
    }).named("Maps.asMap[NavigableSet, Function]").withFeatures(CollectionSize.ANY, MapFeature.SUPPORTS_REMOVE, CollectionFeature.SUPPORTS_ITERATOR_REMOVE).createTestSuite());
    suite.addTest(filterSuite());
    suite.addTest(transformSuite());
    return suite;
}
Also used : NavigableSet(java.util.NavigableSet) SortedSet(java.util.SortedSet) Set(java.util.Set) NavigableSet(java.util.NavigableSet) NavigableMap(java.util.NavigableMap) SortedSet(java.util.SortedSet) TestStringSortedMapGenerator(com.google.common.collect.testing.TestStringSortedMapGenerator) Comparator(java.util.Comparator) Function(com.google.common.base.Function) Helpers.mapEntry(com.google.common.collect.testing.Helpers.mapEntry) Entry(java.util.Map.Entry) TestSuite(junit.framework.TestSuite) SafeTreeMap(com.google.common.collect.testing.SafeTreeMap) TestStringBiMapGenerator(com.google.common.collect.testing.google.TestStringBiMapGenerator) SortedMap(java.util.SortedMap) SampleElements(com.google.common.collect.testing.SampleElements) Map(java.util.Map) NavigableMap(java.util.NavigableMap) SafeTreeMap(com.google.common.collect.testing.SafeTreeMap) SortedMap(java.util.SortedMap)

Example 4 with SafeTreeMap

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

the class ForwardingNavigableMapTest method suite.

public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTestSuite(ForwardingNavigableMapTest.class);
    suite.addTest(NavigableMapTestSuiteBuilder.using(new TestStringMapGenerator() {

        @Override
        protected Map<String, String> create(Entry<String, String>[] entries) {
            NavigableMap<String, String> map = new SafeTreeMap<String, String>();
            for (Entry<String, String> entry : entries) {
                map.put(entry.getKey(), entry.getValue());
            }
            return new StandardImplForwardingNavigableMap<String, String>(map);
        }

        @Override
        public Iterable<Entry<String, String>> order(List<Entry<String, String>> insertionOrder) {
            return sort(insertionOrder);
        }
    }).named("ForwardingNavigableMap[SafeTreeMap] with no comparator and standard " + "implementations").withFeatures(CollectionSize.ANY, CollectionFeature.KNOWN_ORDER, MapFeature.ALLOWS_NULL_VALUES, MapFeature.GENERAL_PURPOSE).createTestSuite());
    // TODO(user): add forwarding-to-ImmutableSortedMap test
    return suite;
}
Also used : Maps.immutableEntry(com.google.common.collect.Maps.immutableEntry) Entry(java.util.Map.Entry) TestSuite(junit.framework.TestSuite) NavigableMap(java.util.NavigableMap) TestStringMapGenerator(com.google.common.collect.testing.TestStringMapGenerator) NavigableMap(java.util.NavigableMap) SafeTreeMap(com.google.common.collect.testing.SafeTreeMap) Map(java.util.Map) SortedMap(java.util.SortedMap)

Example 5 with SafeTreeMap

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

the class MapsCollectionTest method suite.

public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTest(NavigableMapTestSuiteBuilder.using(new TestStringMapGenerator() {

        @Override
        protected Map<String, String> create(Entry<String, String>[] entries) {
            SafeTreeMap<String, String> map = new SafeTreeMap<String, String>();
            for (Entry<String, String> entry : entries) {
                map.put(entry.getKey(), entry.getValue());
            }
            return Maps.unmodifiableNavigableMap(map);
        }
    }).named("unmodifiableNavigableMap[SafeTreeMap]").withFeatures(CollectionSize.ANY, MapFeature.ALLOWS_NULL_VALUES).createTestSuite());
    suite.addTest(NavigableMapTestSuiteBuilder.using(new TestStringMapGenerator() {

        @Override
        protected Map<String, String> create(Entry<String, String>[] entries) {
            SafeTreeMap<String, String> map = new SafeTreeMap<String, String>();
            for (Entry<String, String> entry : entries) {
                map.put(entry.getKey(), entry.getValue());
            }
            return SerializableTester.reserialize(Maps.unmodifiableNavigableMap(map));
        }
    }).named("unmodifiableNavigableMap[SafeTreeMap], reserialized").withFeatures(CollectionSize.ANY, MapFeature.ALLOWS_NULL_VALUES).createTestSuite());
    suite.addTest(BiMapTestSuiteBuilder.using(new TestStringBiMapGenerator() {

        @Override
        protected BiMap<String, String> create(Entry<String, String>[] entries) {
            BiMap<String, String> bimap = HashBiMap.create(entries.length);
            for (Entry<String, String> entry : entries) {
                checkArgument(!bimap.containsKey(entry.getKey()));
                bimap.put(entry.getKey(), entry.getValue());
            }
            return Maps.unmodifiableBiMap(bimap);
        }
    }).named("unmodifiableBiMap[HashBiMap]").withFeatures(CollectionSize.ANY, MapFeature.ALLOWS_NULL_VALUES, MapFeature.ALLOWS_NULL_KEYS, MapFeature.REJECTS_DUPLICATES_AT_CREATION).createTestSuite());
    suite.addTest(BiMapTestSuiteBuilder.using(new TestStringBiMapGenerator() {

        @Override
        protected BiMap<String, String> create(Entry<String, String>[] entries) {
            BiMap<String, String> bimap = HashBiMap.create(entries.length);
            for (Entry<String, String> entry : entries) {
                checkArgument(!bimap.containsKey(entry.getKey()));
                bimap.put(entry.getKey(), entry.getValue());
            }
            return SerializableTester.reserialize(Maps.unmodifiableBiMap(bimap));
        }
    }).named("unmodifiableBiMap[HashBiMap], reserialized").withFeatures(CollectionSize.ANY, MapFeature.ALLOWS_NULL_VALUES, MapFeature.ALLOWS_NULL_KEYS, MapFeature.REJECTS_DUPLICATES_AT_CREATION).createTestSuite());
    return suite;
}
Also used : Entry(java.util.Map.Entry) TestSuite(junit.framework.TestSuite) SafeTreeMap(com.google.common.collect.testing.SafeTreeMap) TestStringMapGenerator(com.google.common.collect.testing.TestStringMapGenerator) TestStringBiMapGenerator(com.google.common.collect.testing.google.TestStringBiMapGenerator) SafeTreeMap(com.google.common.collect.testing.SafeTreeMap) Map(java.util.Map)

Aggregations

SafeTreeMap (com.google.common.collect.testing.SafeTreeMap)5 TestSuite (junit.framework.TestSuite)5 Map (java.util.Map)4 Entry (java.util.Map.Entry)4 TestStringMapGenerator (com.google.common.collect.testing.TestStringMapGenerator)3 SortedMap (java.util.SortedMap)3 TestStringSortedMapGenerator (com.google.common.collect.testing.TestStringSortedMapGenerator)2 TestStringBiMapGenerator (com.google.common.collect.testing.google.TestStringBiMapGenerator)2 NavigableMap (java.util.NavigableMap)2 Function (com.google.common.base.Function)1 Maps.immutableEntry (com.google.common.collect.Maps.immutableEntry)1 Helpers.mapEntry (com.google.common.collect.testing.Helpers.mapEntry)1 MapTestSuiteBuilder (com.google.common.collect.testing.MapTestSuiteBuilder)1 SampleElements (com.google.common.collect.testing.SampleElements)1 Comparator (java.util.Comparator)1 NavigableSet (java.util.NavigableSet)1 Set (java.util.Set)1 SortedSet (java.util.SortedSet)1