public void testCopyOfExplicit_ordering() { SortedSet<String> set = ImmutableSortedSet.copyOf( STRING_LENGTH, asList("in", "the", "quick", "jumped", "over", "a")); assertThat(set).containsExactly("a", "in", "the", "over", "quick", "jumped").inOrder(); }
public void testCopyOfExplicit_ordering_dupes() { SortedSet<String> set = ImmutableSortedSet.copyOf( STRING_LENGTH, asList("in", "the", "quick", "brown", "fox", "jumped", "over", "a", "lazy", "dog")); assertThat(set).containsExactly("a", "in", "the", "over", "quick", "jumped").inOrder(); }
public void testCopyOf_sortedSetIterable() { SortedSet<String> input = Sets.newTreeSet(STRING_LENGTH); Collections.addAll(input, "in", "the", "quick", "jumped", "over", "a"); SortedSet<String> set = copyOf(input); assertThat(set).containsExactly("a", "in", "jumped", "over", "quick", "the").inOrder(); }
public void testCopyOfExplicit_iterator_ordering_dupes() { SortedSet<String> set = ImmutableSortedSet.copyOf( STRING_LENGTH, asIterator("in", "the", "quick", "brown", "fox", "jumped", "over", "a", "lazy", "dog")); assertThat(set).containsExactly("a", "in", "the", "over", "quick", "jumped").inOrder(); }
public void testCopyOfExplicit_iterator_ordering() { SortedSet<String> set = ImmutableSortedSet.copyOf( STRING_LENGTH, asIterator("in", "the", "quick", "jumped", "over", "a")); assertThat(set).containsExactly("a", "in", "the", "over", "quick", "jumped").inOrder(); }
public void testOf_tailSet() { SortedSet<String> set = of("e", "f", "b", "d", "c"); assertTrue(set.tailSet("e") instanceof ImmutableSortedSet); assertThat(set.tailSet("e")).containsExactly("e", "f").inOrder(); assertThat(set.tailSet("a")).containsExactly("b", "c", "d", "e", "f").inOrder(); assertSame(of(), set.tailSet("g")); }
public void testOrderedGet() { TreeMultimap<String, Integer> multimap = createPopulate(); assertThat(multimap.get("foo")).containsExactly(1, 3, 7).inOrder(); assertThat(multimap.get("google")).containsExactly(2, 6).inOrder(); assertThat(multimap.get("tree")).containsExactly(0, 4).inOrder(); }
public void testTailSet() { ImmutableSortedSet<Integer> set = ContiguousSet.create(Range.closed(1, 3), integers()); assertThat(set.tailSet(Integer.MIN_VALUE)).containsExactly(1, 2, 3).inOrder(); assertThat(set.tailSet(1)).containsExactly(1, 2, 3).inOrder(); assertThat(set.tailSet(2)).containsExactly(2, 3).inOrder(); assertThat(set.tailSet(3)).containsExactly(3).inOrder(); assertThat(set.tailSet(Integer.MIN_VALUE, false)).containsExactly(1, 2, 3).inOrder(); assertThat(set.tailSet(1, false)).containsExactly(2, 3).inOrder(); assertThat(set.tailSet(2, false)).containsExactly(3).inOrder(); assertThat(set.tailSet(3, false)).isEmpty(); }
public void testOf_headSet() { SortedSet<String> set = of("e", "f", "b", "d", "c"); assertTrue(set.headSet("e") instanceof ImmutableSortedSet); assertThat(set.headSet("e")).containsExactly("b", "c", "d").inOrder(); assertThat(set.headSet("g")).containsExactly("b", "c", "d", "e", "f").inOrder(); assertSame(of(), set.headSet("a")); assertSame(of(), set.headSet("b")); }
public void testAsMapSortedWritesThrough() { SortedSet<String> strings = new NonNavigableSortedSet(); Collections.addAll(strings, "one", "two", "three"); SortedMap<String, Integer> map = Maps.asMap(strings, LENGTH_FUNCTION); assertEquals(ImmutableMap.of("one", 3, "two", 3, "three", 5), map); assertEquals(Integer.valueOf(3), map.remove("two")); assertThat(strings).containsExactly("one", "three").inOrder(); }
public void testNewTreeSetEmptyDerived() { TreeSet<Derived> set = Sets.newTreeSet(); assertTrue(set.isEmpty()); set.add(new Derived("foo")); set.add(new Derived("bar")); assertThat(set).containsExactly(new Derived("bar"), new Derived("foo")).inOrder(); }
public void testSynchronizedSortedSetMultimap() { SortedSetMultimap<String, Integer> multimap = Multimaps.synchronizedSortedSetMultimap(TreeMultimap.<String, Integer>create()); multimap.putAll("foo", Arrays.asList(3, -1, 2, 4, 1)); multimap.putAll("bar", Arrays.asList(1, 2, 3, 1)); assertThat(multimap.removeAll("foo")).containsExactly(-1, 1, 2, 3, 4).inOrder(); assertFalse(multimap.containsKey("foo")); assertThat(multimap.replaceValues("bar", Arrays.asList(6, 5))) .containsExactly(1, 2, 3) .inOrder(); assertThat(multimap.get("bar")).containsExactly(5, 6).inOrder(); }
public void testToSortedSet() { assertThat(fluent(1, 4, 2, 3).toSortedSet(Ordering.<Integer>natural().reverse())) .containsExactly(4, 3, 2, 1) .inOrder(); }
public void testNewTreeSetFromIterableDerived() { Iterable<Derived> iterable = Arrays.asList(new Derived("foo"), new Derived("bar")); TreeSet<Derived> set = Sets.newTreeSet(iterable); assertThat(set).containsExactly(new Derived("bar"), new Derived("foo")).inOrder(); }
public void testNewTreeSetFromIterableNonGeneric() { Iterable<LegacyComparable> iterable = Arrays.asList(new LegacyComparable("foo"), new LegacyComparable("bar")); TreeSet<LegacyComparable> set = Sets.newTreeSet(iterable); assertThat(set) .containsExactly(new LegacyComparable("bar"), new LegacyComparable("foo")) .inOrder(); }
public void testExplicit_ordering() { SortedSet<String> set = ImmutableSortedSet.orderedBy(STRING_LENGTH) .add("in", "the", "quick", "jumped", "over", "a") .build(); assertThat(set).containsExactly("a", "in", "the", "over", "quick", "jumped").inOrder(); }
public void testReverseOrder() { SortedSet<String> set = ImmutableSortedSet.<String>reverseOrder().add("a", "b", "c").build(); assertThat(set).containsExactly("c", "b", "a").inOrder(); assertTrue(Comparators.isInOrder(Arrays.asList("c", "b", "a"), set.comparator())); }
public void testSupertypeComparatorSubtypeElements() { SortedSet<Number> set = new ImmutableSortedSet.Builder<Number>(TO_STRING).add(3, 12, 101, 44).build(); assertThat(set).containsExactly(101, 12, 3, 44).inOrder(); }
@GwtIncompatible // NavigableMap public void testAsMapNavigableWritesThrough() { NavigableSet<String> strings = Sets.newTreeSet(); Collections.addAll(strings, "one", "two", "three"); NavigableMap<String, Integer> map = Maps.asMap(strings, LENGTH_FUNCTION); assertEquals(ImmutableMap.of("one", 3, "two", 3, "three", 5), map); assertEquals(Integer.valueOf(3), map.remove("two")); assertThat(strings).containsExactly("one", "three").inOrder(); assertEquals(mapEntry("three", 5), map.subMap("one", false, "zzz", true).pollLastEntry()); assertThat(strings).contains("one"); }
@GwtIncompatible // SerializableTester public void testExplicitComparatorSerialization() { TreeMultimap<String, Integer> multimap = createPopulate(); TreeMultimap<String, Integer> copy = SerializableTester.reserializeAndAssert(multimap); assertThat(copy.values()).containsExactly(7, 3, 1, null, 0, 6, 2).inOrder(); assertThat(copy.keySet()).containsExactly(null, "tree", "google").inOrder(); assertEquals(multimap.keyComparator(), copy.keyComparator()); assertEquals(multimap.valueComparator(), copy.valueComparator()); } }