use of com.google.common.collect.testing.SampleElements in project guava by google.
the class TableCollectionTest method suite.
// suite
@GwtIncompatible
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(ArrayRowTests.class);
suite.addTestSuite(HashRowTests.class);
suite.addTestSuite(TreeRowTests.class);
suite.addTestSuite(TransposeRowTests.class);
suite.addTestSuite(TransformValueRowTests.class);
suite.addTestSuite(UnmodifiableHashRowTests.class);
suite.addTestSuite(UnmodifiableTreeRowTests.class);
suite.addTestSuite(ArrayColumnTests.class);
suite.addTestSuite(HashColumnTests.class);
suite.addTestSuite(TreeColumnTests.class);
suite.addTestSuite(TransposeColumnTests.class);
suite.addTestSuite(TransformValueColumnTests.class);
suite.addTestSuite(UnmodifiableHashColumnTests.class);
suite.addTestSuite(UnmodifiableTreeColumnTests.class);
suite.addTestSuite(ArrayRowMapTests.class);
suite.addTestSuite(HashRowMapTests.class);
suite.addTestSuite(TreeRowMapTests.class);
suite.addTestSuite(TreeRowMapHeadMapTests.class);
suite.addTestSuite(TreeRowMapTailMapTests.class);
suite.addTestSuite(TreeRowMapSubMapTests.class);
suite.addTestSuite(TransformValueRowMapTests.class);
suite.addTestSuite(UnmodifiableHashRowMapTests.class);
suite.addTestSuite(UnmodifiableTreeRowMapTests.class);
suite.addTestSuite(ArrayColumnMapTests.class);
suite.addTestSuite(HashColumnMapTests.class);
suite.addTestSuite(TreeColumnMapTests.class);
suite.addTestSuite(TransformValueColumnMapTests.class);
suite.addTestSuite(UnmodifiableHashColumnMapTests.class);
suite.addTestSuite(UnmodifiableTreeColumnMapTests.class);
// Not testing rowKeySet() or columnKeySet() of Table.transformValues()
// since the transformation doesn't affect the row and column key sets.
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
Table<String, Integer, Character> table = ArrayTable.create(ImmutableList.copyOf(elements), ImmutableList.of(1, 2));
populateForRowKeySet(table, elements);
return table.rowKeySet();
}
}).named("ArrayTable.rowKeySet").withFeatures(CollectionSize.ONE, CollectionSize.SEVERAL, CollectionFeature.KNOWN_ORDER, CollectionFeature.REJECTS_DUPLICATES_AT_CREATION, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
Table<String, Integer, Character> table = HashBasedTable.create();
populateForRowKeySet(table, elements);
return table.rowKeySet();
}
}).named("HashBasedTable.rowKeySet").withFeatures(COLLECTION_FEATURES_REMOVE).withFeatures(CollectionFeature.SUPPORTS_ITERATOR_REMOVE).createTestSuite());
suite.addTest(SortedSetTestSuiteBuilder.using(new TestStringSortedSetGenerator() {
@Override
protected SortedSet<String> create(String[] elements) {
TreeBasedTable<String, Integer, Character> table = TreeBasedTable.create();
populateForRowKeySet(table, elements);
return table.rowKeySet();
}
@Override
public List<String> order(List<String> insertionOrder) {
Collections.sort(insertionOrder);
return insertionOrder;
}
}).named("TreeBasedTable.rowKeySet").withFeatures(COLLECTION_FEATURES_REMOVE_ORDER).withFeatures(CollectionFeature.SUPPORTS_ITERATOR_REMOVE).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
Table<String, Integer, Character> table = HashBasedTable.create();
populateForRowKeySet(table, elements);
return Tables.unmodifiableTable(table).rowKeySet();
}
}).named("unmodifiableTable[HashBasedTable].rowKeySet").withFeatures(COLLECTION_FEATURES).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
RowSortedTable<String, Integer, Character> table = TreeBasedTable.create();
populateForRowKeySet(table, elements);
return Tables.unmodifiableRowSortedTable(table).rowKeySet();
}
@Override
public List<String> order(List<String> insertionOrder) {
Collections.sort(insertionOrder);
return insertionOrder;
}
}).named("unmodifiableRowSortedTable[TreeBasedTable].rowKeySet").withFeatures(COLLECTION_FEATURES_ORDER).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
Table<Integer, String, Character> table = ArrayTable.create(ImmutableList.of(1, 2), ImmutableList.copyOf(elements));
populateForColumnKeySet(table, elements);
return table.columnKeySet();
}
}).named("ArrayTable.columnKeySet").withFeatures(CollectionSize.ONE, CollectionSize.SEVERAL, CollectionFeature.KNOWN_ORDER, CollectionFeature.REJECTS_DUPLICATES_AT_CREATION, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
Table<Integer, String, Character> table = HashBasedTable.create();
populateForColumnKeySet(table, elements);
return table.columnKeySet();
}
}).named("HashBasedTable.columnKeySet").withFeatures(COLLECTION_FEATURES_REMOVE).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
Table<Integer, String, Character> table = TreeBasedTable.create();
populateForColumnKeySet(table, elements);
return table.columnKeySet();
}
@Override
public List<String> order(List<String> insertionOrder) {
Collections.sort(insertionOrder);
return insertionOrder;
}
}).named("TreeBasedTable.columnKeySet").withFeatures(COLLECTION_FEATURES_REMOVE_ORDER).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
Table<Integer, String, Character> table = HashBasedTable.create();
populateForColumnKeySet(table, elements);
return Tables.unmodifiableTable(table).columnKeySet();
}
}).named("unmodifiableTable[HashBasedTable].columnKeySet").withFeatures(COLLECTION_FEATURES).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
RowSortedTable<Integer, String, Character> table = TreeBasedTable.create();
populateForColumnKeySet(table, elements);
return Tables.unmodifiableRowSortedTable(table).columnKeySet();
}
@Override
public List<String> order(List<String> insertionOrder) {
Collections.sort(insertionOrder);
return insertionOrder;
}
}).named("unmodifiableRowSortedTable[TreeBasedTable].columnKeySet").withFeatures(COLLECTION_FEATURES_ORDER).createTestSuite());
suite.addTest(CollectionTestSuiteBuilder.using(new TestStringCollectionGenerator() {
@Override
protected Collection<String> create(String[] elements) {
List<Integer> rowKeys = Lists.newArrayList();
for (int i = 0; i < elements.length; i++) {
rowKeys.add(i);
}
Table<Integer, Character, String> table = ArrayTable.create(rowKeys, ImmutableList.of('a'));
populateForValues(table, elements);
return table.values();
}
}).named("ArrayTable.values").withFeatures(CollectionSize.ONE, CollectionSize.SEVERAL, CollectionFeature.ALLOWS_NULL_VALUES, CollectionFeature.KNOWN_ORDER).createTestSuite());
suite.addTest(CollectionTestSuiteBuilder.using(new TestStringCollectionGenerator() {
@Override
protected Collection<String> create(String[] elements) {
Table<Integer, Character, String> table = HashBasedTable.create();
table.put(1, 'a', "foo");
table.clear();
populateForValues(table, elements);
return table.values();
}
}).named("HashBasedTable.values").withFeatures(COLLECTION_FEATURES_REMOVE).withFeatures(CollectionFeature.SUPPORTS_ITERATOR_REMOVE).createTestSuite());
suite.addTest(CollectionTestSuiteBuilder.using(new TestStringCollectionGenerator() {
@Override
protected Collection<String> create(String[] elements) {
Table<Integer, Character, String> table = TreeBasedTable.create();
table.put(1, 'a', "foo");
table.clear();
populateForValues(table, elements);
return table.values();
}
}).named("TreeBasedTable.values").withFeatures(COLLECTION_FEATURES_REMOVE_ORDER).withFeatures(CollectionFeature.SUPPORTS_ITERATOR_REMOVE).createTestSuite());
final Function<String, String> removeFirstCharacter = new Function<String, String>() {
@Override
public String apply(String input) {
return input.substring(1);
}
};
suite.addTest(CollectionTestSuiteBuilder.using(new TestStringCollectionGenerator() {
@Override
protected Collection<String> create(String[] elements) {
Table<Integer, Character, String> table = HashBasedTable.create();
for (int i = 0; i < elements.length; i++) {
table.put(i, 'a', "x" + checkNotNull(elements[i]));
}
return Tables.transformValues(table, removeFirstCharacter).values();
}
}).named("TransformValues.values").withFeatures(COLLECTION_FEATURES_REMOVE).withFeatures(CollectionFeature.SUPPORTS_ITERATOR_REMOVE).createTestSuite());
suite.addTest(CollectionTestSuiteBuilder.using(new TestStringCollectionGenerator() {
@Override
protected Collection<String> create(String[] elements) {
Table<Integer, Character, String> table = HashBasedTable.create();
table.put(1, 'a', "foo");
table.clear();
populateForValues(table, elements);
return Tables.unmodifiableTable(table).values();
}
}).named("unmodifiableTable[HashBasedTable].values").withFeatures(COLLECTION_FEATURES).createTestSuite());
suite.addTest(CollectionTestSuiteBuilder.using(new TestStringCollectionGenerator() {
@Override
protected Collection<String> create(String[] elements) {
RowSortedTable<Integer, Character, String> table = TreeBasedTable.create();
table.put(1, 'a', "foo");
table.clear();
populateForValues(table, elements);
return Tables.unmodifiableRowSortedTable(table).values();
}
}).named("unmodifiableTable[TreeBasedTable].values").withFeatures(COLLECTION_FEATURES_ORDER).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestCellSetGenerator() {
@Override
public SampleElements<Cell<String, Integer, Character>> samples() {
return new SampleElements<Cell<String, Integer, Character>>(Tables.immutableCell("bar", 1, 'a'), Tables.immutableCell("bar", 2, 'b'), Tables.immutableCell("bar", 3, (Character) null), Tables.immutableCell("bar", 4, 'b'), Tables.immutableCell("bar", 5, 'b'));
}
@Override
public Set<Cell<String, Integer, Character>> create(Object... elements) {
List<Integer> columnKeys = Lists.newArrayList();
for (Object element : elements) {
@SuppressWarnings("unchecked") Cell<String, Integer, Character> cell = (Cell<String, Integer, Character>) element;
columnKeys.add(cell.getColumnKey());
}
Table<String, Integer, Character> table = ArrayTable.create(ImmutableList.of("bar"), columnKeys);
for (Object element : elements) {
@SuppressWarnings("unchecked") Cell<String, Integer, Character> cell = (Cell<String, Integer, Character>) element;
table.put(cell.getRowKey(), cell.getColumnKey(), cell.getValue());
}
return table.cellSet();
}
@Override
Table<String, Integer, Character> createTable() {
throw new UnsupportedOperationException();
}
}).named("ArrayTable.cellSet").withFeatures(CollectionSize.ONE, CollectionSize.SEVERAL, CollectionFeature.KNOWN_ORDER, CollectionFeature.REJECTS_DUPLICATES_AT_CREATION, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestCellSetGenerator() {
@Override
Table<String, Integer, Character> createTable() {
return HashBasedTable.create();
}
}).named("HashBasedTable.cellSet").withFeatures(CollectionSize.ANY, CollectionFeature.REMOVE_OPERATIONS, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestCellSetGenerator() {
@Override
Table<String, Integer, Character> createTable() {
return TreeBasedTable.create();
}
}).named("TreeBasedTable.cellSet").withFeatures(CollectionSize.ANY, CollectionFeature.REMOVE_OPERATIONS, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestCellSetGenerator() {
@Override
Table<String, Integer, Character> createTable() {
Table<Integer, String, Character> original = TreeBasedTable.create();
return Tables.transpose(original);
}
}).named("TransposedTable.cellSet").withFeatures(CollectionSize.ANY, CollectionFeature.REMOVE_OPERATIONS, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestCellSetGenerator() {
@Override
Table<String, Integer, Character> createTable() {
return HashBasedTable.create();
}
@Override
public Set<Cell<String, Integer, Character>> create(Object... elements) {
Table<String, Integer, Character> table = createTable();
for (Object element : elements) {
@SuppressWarnings("unchecked") Cell<String, Integer, Character> cell = (Cell<String, Integer, Character>) element;
table.put(cell.getRowKey(), cell.getColumnKey(), cell.getValue());
}
return Tables.transformValues(table, Functions.<Character>identity()).cellSet();
}
}).named("TransformValues.cellSet").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_QUERIES, CollectionFeature.REMOVE_OPERATIONS).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestCellSetGenerator() {
@Override
Table<String, Integer, Character> createTable() {
return Tables.unmodifiableTable(HashBasedTable.<String, Integer, Character>create());
}
@Override
public Set<Cell<String, Integer, Character>> create(Object... elements) {
Table<String, Integer, Character> table = HashBasedTable.create();
for (Object element : elements) {
@SuppressWarnings("unchecked") Cell<String, Integer, Character> cell = (Cell<String, Integer, Character>) element;
table.put(cell.getRowKey(), cell.getColumnKey(), cell.getValue());
}
return Tables.unmodifiableTable(table).cellSet();
}
}).named("unmodifiableTable[HashBasedTable].cellSet").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestCellSetGenerator() {
@Override
RowSortedTable<String, Integer, Character> createTable() {
return Tables.unmodifiableRowSortedTable(TreeBasedTable.<String, Integer, Character>create());
}
@Override
public Set<Cell<String, Integer, Character>> create(Object... elements) {
RowSortedTable<String, Integer, Character> table = TreeBasedTable.create();
for (Object element : elements) {
@SuppressWarnings("unchecked") Cell<String, Integer, Character> cell = (Cell<String, Integer, Character>) element;
table.put(cell.getRowKey(), cell.getColumnKey(), cell.getValue());
}
return Tables.unmodifiableRowSortedTable(table).cellSet();
}
}).named("unmodifiableRowSortedTable[TreeBasedTable].cellSet").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
Iterable<String> rowKeys = ImmutableSet.copyOf(elements);
Iterable<Integer> columnKeys = ImmutableList.of(1, 2, 3);
Table<String, Integer, Character> table = ArrayTable.create(rowKeys, columnKeys);
populateForRowKeySet(table, elements);
return table.column(1).keySet();
}
}).named("ArrayTable.column.keySet").withFeatures(CollectionSize.ONE, CollectionSize.SEVERAL, CollectionFeature.KNOWN_ORDER, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
Table<String, Integer, Character> table = HashBasedTable.create();
populateForRowKeySet(table, elements);
return table.column(1).keySet();
}
}).named("HashBasedTable.column.keySet").withFeatures(COLLECTION_FEATURES_REMOVE).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
Table<String, Integer, Character> table = TreeBasedTable.create();
populateForRowKeySet(table, elements);
return table.column(1).keySet();
}
@Override
public List<String> order(List<String> insertionOrder) {
Collections.sort(insertionOrder);
return insertionOrder;
}
}).named("TreeBasedTable.column.keySet").withFeatures(COLLECTION_FEATURES_REMOVE_ORDER).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
Table<String, Integer, Character> table = HashBasedTable.create();
populateForRowKeySet(table, elements);
return Tables.transformValues(table, Functions.toStringFunction()).column(1).keySet();
}
}).named("TransformValues.column.keySet").withFeatures(COLLECTION_FEATURES_REMOVE).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
Table<String, Integer, Character> table = HashBasedTable.create();
populateForRowKeySet(table, elements);
return Tables.unmodifiableTable(table).column(1).keySet();
}
}).named("unmodifiableTable[HashBasedTable].column.keySet").withFeatures(COLLECTION_FEATURES).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
RowSortedTable<String, Integer, Character> table = TreeBasedTable.create();
populateForRowKeySet(table, elements);
return Tables.unmodifiableRowSortedTable(table).column(1).keySet();
}
@Override
public List<String> order(List<String> insertionOrder) {
Collections.sort(insertionOrder);
return insertionOrder;
}
}).named("unmodifiableRowSortedTable[TreeBasedTable].column.keySet").withFeatures(COLLECTION_FEATURES_ORDER).createTestSuite());
return suite;
}
use of com.google.common.collect.testing.SampleElements in project guava by google.
the class TreeMultimapNaturalTest method suite.
// suite
@GwtIncompatible
public static Test suite() {
TestSuite suite = new TestSuite();
// TODO(lowasser): should we force TreeMultimap to be more thorough about checking nulls?
suite.addTest(SortedSetMultimapTestSuiteBuilder.using(new TestStringSetMultimapGenerator() {
@Override
protected SetMultimap<String, String> create(Entry<String, String>[] entries) {
SetMultimap<String, String> multimap = TreeMultimap.create(Ordering.natural().nullsFirst(), Ordering.natural().nullsFirst());
for (Entry<String, String> entry : entries) {
multimap.put(entry.getKey(), entry.getValue());
}
return multimap;
}
@Override
public Iterable<Entry<String, String>> order(List<Entry<String, String>> insertionOrder) {
return new Ordering<Entry<String, String>>() {
@Override
public int compare(Entry<String, String> left, Entry<String, String> right) {
return ComparisonChain.start().compare(left.getKey(), right.getKey(), Ordering.natural().nullsFirst()).compare(left.getValue(), right.getValue(), Ordering.natural().nullsFirst()).result();
}
}.sortedCopy(insertionOrder);
}
}).named("TreeMultimap nullsFirst").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, CollectionFeature.KNOWN_ORDER, CollectionFeature.SERIALIZABLE, CollectionSize.ANY).createTestSuite());
suite.addTest(NavigableSetTestSuiteBuilder.using(new TestStringSortedSetGenerator() {
@Override
protected NavigableSet<String> create(String[] elements) {
TreeMultimap<String, Integer> multimap = TreeMultimap.create(Ordering.natural().nullsFirst(), Ordering.natural());
for (int i = 0; i < elements.length; i++) {
multimap.put(elements[i], i);
}
return multimap.keySet();
}
@Override
public List<String> order(List<String> insertionOrder) {
return Ordering.natural().nullsFirst().sortedCopy(insertionOrder);
}
}).named("TreeMultimap.keySet").withFeatures(CollectionFeature.ALLOWS_NULL_VALUES, CollectionFeature.REMOVE_OPERATIONS, CollectionFeature.KNOWN_ORDER, CollectionSize.ANY).createTestSuite());
suite.addTest(NavigableMapTestSuiteBuilder.using(new TestSortedMapGenerator<String, Collection<String>>() {
@Override
public String[] createKeyArray(int length) {
return new String[length];
}
@SuppressWarnings("unchecked")
@Override
public Collection<String>[] createValueArray(int length) {
return new Collection[length];
}
@Override
public SampleElements<Entry<String, Collection<String>>> samples() {
return new SampleElements<Entry<String, Collection<String>>>(Helpers.mapEntry("a", (Collection<String>) ImmutableSortedSet.of("alex")), Helpers.mapEntry("b", (Collection<String>) ImmutableSortedSet.of("bob", "bagel")), Helpers.mapEntry("c", (Collection<String>) ImmutableSortedSet.of("carl", "carol")), Helpers.mapEntry("d", (Collection<String>) ImmutableSortedSet.of("david", "dead")), Helpers.mapEntry("e", (Collection<String>) ImmutableSortedSet.of("eric", "elaine")));
}
@SuppressWarnings("unchecked")
@Override
public Entry<String, Collection<String>>[] createArray(int length) {
return new Entry[length];
}
@Override
public Iterable<Entry<String, Collection<String>>> order(List<Entry<String, Collection<String>>> insertionOrder) {
return new Ordering<Entry<String, ?>>() {
@Override
public int compare(Entry<String, ?> left, Entry<String, ?> right) {
return left.getKey().compareTo(right.getKey());
}
}.sortedCopy(insertionOrder);
}
@Override
public NavigableMap<String, Collection<String>> create(Object... elements) {
TreeMultimap<String, String> multimap = TreeMultimap.create();
for (Object o : elements) {
@SuppressWarnings("unchecked") Entry<String, Collection<String>> entry = (Entry<String, Collection<String>>) o;
checkArgument(!multimap.containsKey(entry.getKey()));
multimap.putAll(entry.getKey(), entry.getValue());
}
return multimap.asMap();
}
@Override
public Entry<String, Collection<String>> belowSamplesLesser() {
return Helpers.mapEntry("-- a", (Collection<String>) ImmutableSortedSet.of("--below"));
}
@Override
public Entry<String, Collection<String>> belowSamplesGreater() {
return Helpers.mapEntry("-- b", (Collection<String>) ImmutableSortedSet.of("--below"));
}
@Override
public Entry<String, Collection<String>> aboveSamplesLesser() {
return Helpers.mapEntry("~~ b", (Collection<String>) ImmutableSortedSet.of("~above"));
}
@Override
public Entry<String, Collection<String>> aboveSamplesGreater() {
return Helpers.mapEntry("~~ c", (Collection<String>) ImmutableSortedSet.of("~above"));
}
}).named("TreeMultimap.asMap").withFeatures(MapFeature.SUPPORTS_REMOVE, MapFeature.REJECTS_DUPLICATES_AT_CREATION, CollectionFeature.SUPPORTS_ITERATOR_REMOVE, CollectionFeature.KNOWN_ORDER, CollectionSize.ANY).createTestSuite());
suite.addTest(NavigableSetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
TreeMultimap<Integer, String> multimap = TreeMultimap.create(Ordering.natural(), Ordering.natural().nullsFirst());
multimap.putAll(1, Arrays.asList(elements));
return multimap.get(1);
}
@Override
public List<String> order(List<String> insertionOrder) {
return Ordering.natural().nullsFirst().sortedCopy(insertionOrder);
}
}).named("TreeMultimap.get").withFeatures(CollectionFeature.ALLOWS_NULL_VALUES, CollectionFeature.GENERAL_PURPOSE, CollectionFeature.KNOWN_ORDER, CollectionSize.ANY).createTestSuite());
suite.addTest(NavigableSetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
TreeMultimap<Integer, String> multimap = TreeMultimap.create(Ordering.natural(), Ordering.natural().nullsFirst());
multimap.putAll(1, Arrays.asList(elements));
return (Set<String>) multimap.asMap().entrySet().iterator().next().getValue();
}
@Override
public List<String> order(List<String> insertionOrder) {
return Ordering.natural().nullsFirst().sortedCopy(insertionOrder);
}
}).named("TreeMultimap.asMap.entrySet collection").withFeatures(CollectionFeature.ALLOWS_NULL_VALUES, CollectionFeature.GENERAL_PURPOSE, CollectionFeature.KNOWN_ORDER, CollectionSize.ONE, CollectionSize.SEVERAL).createTestSuite());
suite.addTestSuite(TreeMultimapNaturalTest.class);
return suite;
}
use of com.google.common.collect.testing.SampleElements in project guava by google.
the class TreeRangeMapTest method suite.
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(TreeRangeMapTest.class);
suite.addTest(MapTestSuiteBuilder.using(new TestMapGenerator<Range<Integer>, String>() {
@Override
public SampleElements<Entry<Range<Integer>, String>> samples() {
return new SampleElements<Entry<Range<Integer>, String>>(mapEntry(Range.singleton(0), "banana"), mapEntry(Range.closedOpen(3, 5), "frisbee"), mapEntry(Range.atMost(-1), "fruitcake"), mapEntry(Range.open(10, 15), "elephant"), mapEntry(Range.closed(20, 22), "umbrella"));
}
@Override
public Map<Range<Integer>, String> create(Object... elements) {
RangeMap<Integer, String> rangeMap = TreeRangeMap.create();
for (Object o : elements) {
@SuppressWarnings("unchecked") Entry<Range<Integer>, String> entry = (Entry<Range<Integer>, String>) o;
rangeMap.put(entry.getKey(), entry.getValue());
}
return rangeMap.asMapOfRanges();
}
@SuppressWarnings("unchecked")
@Override
public Entry<Range<Integer>, String>[] createArray(int length) {
return new Entry[length];
}
@Override
public Iterable<Entry<Range<Integer>, String>> order(List<Entry<Range<Integer>, String>> insertionOrder) {
return Range.RANGE_LEX_ORDERING.<Range<Integer>>onKeys().sortedCopy(insertionOrder);
}
@SuppressWarnings("unchecked")
@Override
public Range<Integer>[] createKeyArray(int length) {
return new Range[length];
}
@Override
public String[] createValueArray(int length) {
return new String[length];
}
}).named("TreeRangeMap.asMapOfRanges").withFeatures(CollectionSize.ANY, MapFeature.SUPPORTS_REMOVE, MapFeature.ALLOWS_ANY_NULL_QUERIES, CollectionFeature.KNOWN_ORDER, CollectionFeature.SUPPORTS_ITERATOR_REMOVE).createTestSuite());
suite.addTest(MapTestSuiteBuilder.using(new TestMapGenerator<Range<Integer>, String>() {
@Override
public SampleElements<Entry<Range<Integer>, String>> samples() {
return new SampleElements<Entry<Range<Integer>, String>>(mapEntry(Range.singleton(0), "banana"), mapEntry(Range.closedOpen(3, 5), "frisbee"), mapEntry(Range.atMost(-1), "fruitcake"), mapEntry(Range.open(10, 15), "elephant"), mapEntry(Range.closed(20, 22), "umbrella"));
}
@Override
public Map<Range<Integer>, String> create(Object... elements) {
RangeMap<Integer, String> rangeMap = TreeRangeMap.create();
for (Object o : elements) {
@SuppressWarnings("unchecked") Entry<Range<Integer>, String> entry = (Entry<Range<Integer>, String>) o;
rangeMap.put(entry.getKey(), entry.getValue());
}
return rangeMap.subRangeMap(Range.atMost(22)).asMapOfRanges();
}
@SuppressWarnings("unchecked")
@Override
public Entry<Range<Integer>, String>[] createArray(int length) {
return new Entry[length];
}
@Override
public Iterable<Entry<Range<Integer>, String>> order(List<Entry<Range<Integer>, String>> insertionOrder) {
return Range.RANGE_LEX_ORDERING.<Range<Integer>>onKeys().sortedCopy(insertionOrder);
}
@SuppressWarnings("unchecked")
@Override
public Range<Integer>[] createKeyArray(int length) {
return new Range[length];
}
@Override
public String[] createValueArray(int length) {
return new String[length];
}
}).named("TreeRangeMap.subRangeMap.asMapOfRanges").withFeatures(CollectionSize.ANY, MapFeature.SUPPORTS_REMOVE, MapFeature.ALLOWS_ANY_NULL_QUERIES, CollectionFeature.KNOWN_ORDER).createTestSuite());
suite.addTest(MapTestSuiteBuilder.using(new TestMapGenerator<Range<Integer>, String>() {
@Override
public SampleElements<Entry<Range<Integer>, String>> samples() {
return new SampleElements<Entry<Range<Integer>, String>>(mapEntry(Range.singleton(0), "banana"), mapEntry(Range.closedOpen(3, 5), "frisbee"), mapEntry(Range.atMost(-1), "fruitcake"), mapEntry(Range.open(10, 15), "elephant"), mapEntry(Range.closed(20, 22), "umbrella"));
}
@Override
public Map<Range<Integer>, String> create(Object... elements) {
RangeMap<Integer, String> rangeMap = TreeRangeMap.create();
for (Object o : elements) {
@SuppressWarnings("unchecked") Entry<Range<Integer>, String> entry = (Entry<Range<Integer>, String>) o;
rangeMap.put(entry.getKey(), entry.getValue());
}
return rangeMap.asDescendingMapOfRanges();
}
@SuppressWarnings("unchecked")
@Override
public Entry<Range<Integer>, String>[] createArray(int length) {
return new Entry[length];
}
@Override
public Iterable<Entry<Range<Integer>, String>> order(List<Entry<Range<Integer>, String>> insertionOrder) {
return Range.RANGE_LEX_ORDERING.reverse().<Range<Integer>>onKeys().sortedCopy(insertionOrder);
}
@SuppressWarnings("unchecked")
@Override
public Range<Integer>[] createKeyArray(int length) {
return new Range[length];
}
@Override
public String[] createValueArray(int length) {
return new String[length];
}
}).named("TreeRangeMap.asDescendingMapOfRanges").withFeatures(CollectionSize.ANY, MapFeature.SUPPORTS_REMOVE, MapFeature.ALLOWS_ANY_NULL_QUERIES, CollectionFeature.KNOWN_ORDER, CollectionFeature.SUPPORTS_ITERATOR_REMOVE).createTestSuite());
suite.addTest(MapTestSuiteBuilder.using(new TestMapGenerator<Range<Integer>, String>() {
@Override
public SampleElements<Entry<Range<Integer>, String>> samples() {
return new SampleElements<Entry<Range<Integer>, String>>(mapEntry(Range.singleton(0), "banana"), mapEntry(Range.closedOpen(3, 5), "frisbee"), mapEntry(Range.atMost(-1), "fruitcake"), mapEntry(Range.open(10, 15), "elephant"), mapEntry(Range.closed(20, 22), "umbrella"));
}
@Override
public Map<Range<Integer>, String> create(Object... elements) {
RangeMap<Integer, String> rangeMap = TreeRangeMap.create();
for (Object o : elements) {
@SuppressWarnings("unchecked") Entry<Range<Integer>, String> entry = (Entry<Range<Integer>, String>) o;
rangeMap.put(entry.getKey(), entry.getValue());
}
return rangeMap.subRangeMap(Range.atMost(22)).asDescendingMapOfRanges();
}
@SuppressWarnings("unchecked")
@Override
public Entry<Range<Integer>, String>[] createArray(int length) {
return new Entry[length];
}
@Override
public Iterable<Entry<Range<Integer>, String>> order(List<Entry<Range<Integer>, String>> insertionOrder) {
return Range.RANGE_LEX_ORDERING.reverse().<Range<Integer>>onKeys().sortedCopy(insertionOrder);
}
@SuppressWarnings("unchecked")
@Override
public Range<Integer>[] createKeyArray(int length) {
return new Range[length];
}
@Override
public String[] createValueArray(int length) {
return new String[length];
}
}).named("TreeRangeMap.subRangeMap.asDescendingMapOfRanges").withFeatures(CollectionSize.ANY, MapFeature.SUPPORTS_REMOVE, MapFeature.ALLOWS_ANY_NULL_QUERIES, CollectionFeature.KNOWN_ORDER).createTestSuite());
return suite;
}
use of com.google.common.collect.testing.SampleElements in project guava by hceylan.
the class TableCollectionTest method suite.
@GwtIncompatible("suite")
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(ArrayRowTests.class);
suite.addTestSuite(HashRowTests.class);
suite.addTestSuite(TreeRowTests.class);
suite.addTestSuite(TransposeRowTests.class);
suite.addTestSuite(TransformValueRowTests.class);
suite.addTestSuite(UnmodifiableHashRowTests.class);
suite.addTestSuite(UnmodifiableTreeRowTests.class);
suite.addTestSuite(ArrayColumnTests.class);
suite.addTestSuite(HashColumnTests.class);
suite.addTestSuite(TreeColumnTests.class);
suite.addTestSuite(TransposeColumnTests.class);
suite.addTestSuite(TransformValueColumnTests.class);
suite.addTestSuite(UnmodifiableHashColumnTests.class);
suite.addTestSuite(UnmodifiableTreeColumnTests.class);
suite.addTestSuite(ArrayRowMapTests.class);
suite.addTestSuite(HashRowMapTests.class);
suite.addTestSuite(TreeRowMapTests.class);
suite.addTestSuite(TreeRowMapHeadMapTests.class);
suite.addTestSuite(TreeRowMapTailMapTests.class);
suite.addTestSuite(TreeRowMapSubMapTests.class);
suite.addTestSuite(TransformValueRowMapTests.class);
suite.addTestSuite(UnmodifiableHashRowMapTests.class);
suite.addTestSuite(UnmodifiableTreeRowMapTests.class);
suite.addTestSuite(ArrayColumnMapTests.class);
suite.addTestSuite(HashColumnMapTests.class);
suite.addTestSuite(TreeColumnMapTests.class);
suite.addTestSuite(TransformValueColumnMapTests.class);
suite.addTestSuite(UnmodifiableHashColumnMapTests.class);
suite.addTestSuite(UnmodifiableTreeColumnMapTests.class);
// Not testing rowKeySet() or columnKeySet() of Table.transformValues()
// since the transformation doesn't affect the row and column key sets.
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
Table<String, Integer, Character> table = ArrayTable.create(ImmutableList.copyOf(elements), ImmutableList.of(1, 2));
populateForRowKeySet(table, elements);
return table.rowKeySet();
}
}).named("ArrayTable.rowKeySet").withFeatures(CollectionSize.ONE, CollectionSize.SEVERAL, CollectionFeature.KNOWN_ORDER, CollectionFeature.REJECTS_DUPLICATES_AT_CREATION, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
Table<String, Integer, Character> table = HashBasedTable.create();
populateForRowKeySet(table, elements);
return table.rowKeySet();
}
}).named("HashBasedTable.rowKeySet").withFeatures(COLLECTION_FEATURES_REMOVE).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
Table<String, Integer, Character> table = TreeBasedTable.create();
populateForRowKeySet(table, elements);
return table.rowKeySet();
}
@Override
public List<String> order(List<String> insertionOrder) {
Collections.sort(insertionOrder);
return insertionOrder;
}
}).named("TreeBasedTable.rowKeySet").withFeatures(COLLECTION_FEATURES_REMOVE_ORDER).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
TreeBasedTable<String, Integer, Character> table = TreeBasedTable.create();
populateForRowKeySet(table, elements);
table.put("z", 1, 'a');
return table.rowKeySet().headSet("x");
}
@Override
public List<String> order(List<String> insertionOrder) {
Collections.sort(insertionOrder);
return insertionOrder;
}
}).named("TreeBasedTable.rowKeySet.headSet").withFeatures(COLLECTION_FEATURES_REMOVE_ORDER).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
TreeBasedTable<String, Integer, Character> table = TreeBasedTable.create();
populateForRowKeySet(table, elements);
table.put("\0", 1, 'a');
return table.rowKeySet().tailSet("a");
}
@Override
public List<String> order(List<String> insertionOrder) {
Collections.sort(insertionOrder);
return insertionOrder;
}
}).named("TreeBasedTable.rowKeySet.tailSet").withFeatures(COLLECTION_FEATURES_REMOVE_ORDER).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
TreeBasedTable<String, Integer, Character> table = TreeBasedTable.create();
populateForRowKeySet(table, elements);
table.put("\0", 1, 'a');
table.put("z", 1, 'a');
return table.rowKeySet().subSet("a", "x");
}
@Override
public List<String> order(List<String> insertionOrder) {
Collections.sort(insertionOrder);
return insertionOrder;
}
}).named("TreeBasedTable.rowKeySet.subSet").withFeatures(COLLECTION_FEATURES_REMOVE_ORDER).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
Table<String, Integer, Character> table = HashBasedTable.create();
populateForRowKeySet(table, elements);
return Tables.unmodifiableTable(table).rowKeySet();
}
}).named("unmodifiableTable[HashBasedTable].rowKeySet").withFeatures(COLLECTION_FEATURES).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
RowSortedTable<String, Integer, Character> table = TreeBasedTable.create();
populateForRowKeySet(table, elements);
return Tables.unmodifiableRowSortedTable(table).rowKeySet();
}
@Override
public List<String> order(List<String> insertionOrder) {
Collections.sort(insertionOrder);
return insertionOrder;
}
}).named("unmodifiableRowSortedTable[TreeBasedTable].rowKeySet").withFeatures(COLLECTION_FEATURES_ORDER).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
Table<Integer, String, Character> table = ArrayTable.create(ImmutableList.of(1, 2), ImmutableList.copyOf(elements));
populateForColumnKeySet(table, elements);
return table.columnKeySet();
}
}).named("ArrayTable.columnKeySet").withFeatures(CollectionSize.ONE, CollectionSize.SEVERAL, CollectionFeature.KNOWN_ORDER, CollectionFeature.REJECTS_DUPLICATES_AT_CREATION, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
Table<Integer, String, Character> table = HashBasedTable.create();
populateForColumnKeySet(table, elements);
return table.columnKeySet();
}
}).named("HashBasedTable.columnKeySet").withFeatures(COLLECTION_FEATURES_REMOVE).suppressing(getIteratorUnknownOrderRemoveSupportedMethod()).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
Table<Integer, String, Character> table = TreeBasedTable.create();
populateForColumnKeySet(table, elements);
return table.columnKeySet();
}
@Override
public List<String> order(List<String> insertionOrder) {
Collections.sort(insertionOrder);
return insertionOrder;
}
}).named("TreeBasedTable.columnKeySet").withFeatures(COLLECTION_FEATURES_REMOVE_ORDER).suppressing(getIteratorKnownOrderRemoveSupportedMethod()).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
Table<Integer, String, Character> table = HashBasedTable.create();
populateForColumnKeySet(table, elements);
return Tables.unmodifiableTable(table).columnKeySet();
}
}).named("unmodifiableTable[HashBasedTable].columnKeySet").withFeatures(COLLECTION_FEATURES).suppressing(getIteratorUnknownOrderRemoveSupportedMethod()).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
RowSortedTable<Integer, String, Character> table = TreeBasedTable.create();
populateForColumnKeySet(table, elements);
return Tables.unmodifiableRowSortedTable(table).columnKeySet();
}
@Override
public List<String> order(List<String> insertionOrder) {
Collections.sort(insertionOrder);
return insertionOrder;
}
}).named("unmodifiableRowSortedTable[TreeBasedTable].columnKeySet").withFeatures(COLLECTION_FEATURES_ORDER).suppressing(getIteratorKnownOrderRemoveSupportedMethod()).createTestSuite());
suite.addTest(CollectionTestSuiteBuilder.using(new TestStringCollectionGenerator() {
@Override
protected Collection<String> create(String[] elements) {
List<Integer> rowKeys = Lists.newArrayList();
for (int i = 0; i < elements.length; i++) {
rowKeys.add(i);
}
Table<Integer, Character, String> table = ArrayTable.create(rowKeys, ImmutableList.of('a'));
populateForValues(table, elements);
return table.values();
}
}).named("ArrayTable.values").withFeatures(CollectionSize.ONE, CollectionSize.SEVERAL, CollectionFeature.ALLOWS_NULL_VALUES, CollectionFeature.KNOWN_ORDER).createTestSuite());
suite.addTest(CollectionTestSuiteBuilder.using(new TestStringCollectionGenerator() {
@Override
protected Collection<String> create(String[] elements) {
Table<Integer, Character, String> table = HashBasedTable.create();
table.put(1, 'a', "foo");
table.clear();
populateForValues(table, elements);
return table.values();
}
}).named("HashBasedTable.values").withFeatures(COLLECTION_FEATURES_REMOVE).createTestSuite());
suite.addTest(CollectionTestSuiteBuilder.using(new TestStringCollectionGenerator() {
@Override
protected Collection<String> create(String[] elements) {
Table<Integer, Character, String> table = TreeBasedTable.create();
table.put(1, 'a', "foo");
table.clear();
populateForValues(table, elements);
return table.values();
}
}).named("TreeBasedTable.values").withFeatures(COLLECTION_FEATURES_REMOVE_ORDER).createTestSuite());
final Function<String, String> removeFirstCharacter = new Function<String, String>() {
@Override
public String apply(String input) {
return input.substring(1);
}
};
suite.addTest(CollectionTestSuiteBuilder.using(new TestStringCollectionGenerator() {
@Override
protected Collection<String> create(String[] elements) {
Table<Integer, Character, String> table = HashBasedTable.create();
for (int i = 0; i < elements.length; i++) {
table.put(i, 'a', "x" + checkNotNull(elements[i]));
}
return Tables.transformValues(table, removeFirstCharacter).values();
}
}).named("TransformValues.values").withFeatures(COLLECTION_FEATURES_REMOVE).createTestSuite());
suite.addTest(CollectionTestSuiteBuilder.using(new TestStringCollectionGenerator() {
@Override
protected Collection<String> create(String[] elements) {
Table<Integer, Character, String> table = HashBasedTable.create();
table.put(1, 'a', "foo");
table.clear();
populateForValues(table, elements);
return Tables.unmodifiableTable(table).values();
}
}).named("unmodifiableTable[HashBasedTable].values").withFeatures(COLLECTION_FEATURES).createTestSuite());
suite.addTest(CollectionTestSuiteBuilder.using(new TestStringCollectionGenerator() {
@Override
protected Collection<String> create(String[] elements) {
RowSortedTable<Integer, Character, String> table = TreeBasedTable.create();
table.put(1, 'a', "foo");
table.clear();
populateForValues(table, elements);
return Tables.unmodifiableRowSortedTable(table).values();
}
}).named("unmodifiableTable[TreeBasedTable].values").withFeatures(COLLECTION_FEATURES_ORDER).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestCellSetGenerator() {
@Override
public SampleElements<Cell<String, Integer, Character>> samples() {
return new SampleElements<Cell<String, Integer, Character>>(Tables.immutableCell("bar", 1, 'a'), Tables.immutableCell("bar", 2, 'b'), Tables.immutableCell("bar", 3, (Character) null), Tables.immutableCell("bar", 4, 'b'), Tables.immutableCell("bar", 5, 'b'));
}
@Override
public Set<Cell<String, Integer, Character>> create(Object... elements) {
List<Integer> columnKeys = Lists.newArrayList();
for (Object element : elements) {
@SuppressWarnings("unchecked") Cell<String, Integer, Character> cell = (Cell<String, Integer, Character>) element;
columnKeys.add(cell.getColumnKey());
}
Table<String, Integer, Character> table = ArrayTable.create(ImmutableList.of("bar"), columnKeys);
for (Object element : elements) {
@SuppressWarnings("unchecked") Cell<String, Integer, Character> cell = (Cell<String, Integer, Character>) element;
table.put(cell.getRowKey(), cell.getColumnKey(), cell.getValue());
}
return table.cellSet();
}
@Override
Table<String, Integer, Character> createTable() {
throw new UnsupportedOperationException();
}
}).named("ArrayTable.cellSet").withFeatures(CollectionSize.ONE, CollectionSize.SEVERAL, CollectionFeature.KNOWN_ORDER, CollectionFeature.REJECTS_DUPLICATES_AT_CREATION, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestCellSetGenerator() {
@Override
Table<String, Integer, Character> createTable() {
return HashBasedTable.create();
}
}).named("HashBasedTable.cellSet").withFeatures(CollectionSize.ANY, CollectionFeature.REMOVE_OPERATIONS, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestCellSetGenerator() {
@Override
Table<String, Integer, Character> createTable() {
return TreeBasedTable.create();
}
}).named("TreeBasedTable.cellSet").withFeatures(CollectionSize.ANY, CollectionFeature.REMOVE_OPERATIONS, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestCellSetGenerator() {
@Override
Table<String, Integer, Character> createTable() {
Table<Integer, String, Character> original = TreeBasedTable.create();
return Tables.transpose(original);
}
}).named("TransposedTable.cellSet").withFeatures(CollectionSize.ANY, CollectionFeature.REMOVE_OPERATIONS, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestCellSetGenerator() {
@Override
Table<String, Integer, Character> createTable() {
return HashBasedTable.create();
}
@Override
public Set<Cell<String, Integer, Character>> create(Object... elements) {
Table<String, Integer, Character> table = createTable();
for (Object element : elements) {
@SuppressWarnings("unchecked") Cell<String, Integer, Character> cell = (Cell<String, Integer, Character>) element;
table.put(cell.getRowKey(), cell.getColumnKey(), cell.getValue());
}
return Tables.transformValues(table, Functions.<Character>identity()).cellSet();
}
}).named("TransformValues.cellSet").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_QUERIES, CollectionFeature.REMOVE_OPERATIONS).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestCellSetGenerator() {
@Override
Table<String, Integer, Character> createTable() {
return Tables.unmodifiableTable(HashBasedTable.<String, Integer, Character>create());
}
@Override
public Set<Cell<String, Integer, Character>> create(Object... elements) {
Table<String, Integer, Character> table = HashBasedTable.create();
for (Object element : elements) {
@SuppressWarnings("unchecked") Cell<String, Integer, Character> cell = (Cell<String, Integer, Character>) element;
table.put(cell.getRowKey(), cell.getColumnKey(), cell.getValue());
}
return Tables.unmodifiableTable(table).cellSet();
}
}).named("unmodifiableTable[HashBasedTable].cellSet").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestCellSetGenerator() {
@Override
RowSortedTable<String, Integer, Character> createTable() {
return Tables.unmodifiableRowSortedTable(TreeBasedTable.<String, Integer, Character>create());
}
@Override
public Set<Cell<String, Integer, Character>> create(Object... elements) {
RowSortedTable<String, Integer, Character> table = TreeBasedTable.create();
for (Object element : elements) {
@SuppressWarnings("unchecked") Cell<String, Integer, Character> cell = (Cell<String, Integer, Character>) element;
table.put(cell.getRowKey(), cell.getColumnKey(), cell.getValue());
}
return Tables.unmodifiableRowSortedTable(table).cellSet();
}
}).named("unmodifiableRowSortedTable[TreeBasedTable].cellSet").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
Iterable<String> rowKeys = ImmutableSet.copyOf(elements);
Iterable<Integer> columnKeys = ImmutableList.of(1, 2, 3);
Table<String, Integer, Character> table = ArrayTable.create(rowKeys, columnKeys);
populateForRowKeySet(table, elements);
return table.column(1).keySet();
}
}).named("ArrayTable.column.keySet").withFeatures(CollectionSize.ONE, CollectionSize.SEVERAL, CollectionFeature.KNOWN_ORDER, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
Table<String, Integer, Character> table = HashBasedTable.create();
populateForRowKeySet(table, elements);
return table.column(1).keySet();
}
}).named("HashBasedTable.column.keySet").withFeatures(COLLECTION_FEATURES_REMOVE).suppressing(getIteratorUnknownOrderRemoveSupportedMethod()).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
Table<String, Integer, Character> table = TreeBasedTable.create();
populateForRowKeySet(table, elements);
return table.column(1).keySet();
}
@Override
public List<String> order(List<String> insertionOrder) {
Collections.sort(insertionOrder);
return insertionOrder;
}
}).named("TreeBasedTable.column.keySet").withFeatures(COLLECTION_FEATURES_REMOVE_ORDER).suppressing(getIteratorKnownOrderRemoveSupportedMethod()).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
Table<String, Integer, Character> table = HashBasedTable.create();
populateForRowKeySet(table, elements);
return Tables.transformValues(table, Functions.toStringFunction()).column(1).keySet();
}
}).named("TransformValues.column.keySet").withFeatures(COLLECTION_FEATURES_REMOVE).suppressing(getIteratorUnknownOrderRemoveSupportedMethod()).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
Table<String, Integer, Character> table = HashBasedTable.create();
populateForRowKeySet(table, elements);
return Tables.unmodifiableTable(table).column(1).keySet();
}
}).named("unmodifiableTable[HashBasedTable].column.keySet").withFeatures(COLLECTION_FEATURES).suppressing(getIteratorUnknownOrderRemoveSupportedMethod()).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
RowSortedTable<String, Integer, Character> table = TreeBasedTable.create();
populateForRowKeySet(table, elements);
return Tables.unmodifiableRowSortedTable(table).column(1).keySet();
}
@Override
public List<String> order(List<String> insertionOrder) {
Collections.sort(insertionOrder);
return insertionOrder;
}
}).named("unmodifiableRowSortedTable[TreeBasedTable].column.keySet").withFeatures(COLLECTION_FEATURES_ORDER).suppressing(getIteratorKnownOrderRemoveSupportedMethod()).createTestSuite());
return suite;
}
use of com.google.common.collect.testing.SampleElements 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;
}
Aggregations