public void testLegacyComparable_copyOf_collection() { ImmutableSortedSet<LegacyComparable> set = ImmutableSortedSet.copyOf(LegacyComparable.VALUES_BACKWARD); assertTrue(Iterables.elementsEqual(LegacyComparable.VALUES_FORWARD, set)); }
public void testLegacyComparable_copyOf_iterator() { ImmutableSortedSet<LegacyComparable> set = ImmutableSortedSet.copyOf(LegacyComparable.VALUES_BACKWARD.iterator()); assertTrue(Iterables.elementsEqual(LegacyComparable.VALUES_FORWARD, set)); }
public void testExplicit_tailSet() { SortedSet<String> set = ImmutableSortedSet.orderedBy(STRING_LENGTH) .add("in", "the", "quick", "jumped", "over", "a") .build(); assertTrue(set.tailSet("california") instanceof ImmutableSortedSet); assertTrue(set.tailSet("fish") instanceof ImmutableSortedSet); assertThat(set.tailSet("fish")).containsExactly("over", "quick", "jumped").inOrder(); assertThat(set.tailSet("a")) .containsExactly("a", "in", "the", "over", "quick", "jumped") .inOrder(); assertTrue(set.tailSet("california").isEmpty()); }
@GwtIncompatible // SerializableTester public void testExplicitEmpty_serialization() { SortedSet<String> set = ImmutableSortedSet.orderedBy(STRING_LENGTH).build(); SortedSet<String> copy = SerializableTester.reserializeAndAssert(set); assertTrue(set.isEmpty()); assertTrue(copy.isEmpty()); assertSame(set.comparator(), copy.comparator()); }
public void testContainsAll_sameComparator() { SortedSet<String> set = of("a", "b", "f"); assertTrue(set.containsAll(Sets.newTreeSet())); assertTrue(set.containsAll(Sets.newTreeSet(asList("b")))); assertTrue(set.containsAll(Sets.newTreeSet(asList("a", "f")))); assertTrue(set.containsAll(Sets.newTreeSet(asList("a", "b", "f")))); assertFalse(set.containsAll(Sets.newTreeSet(asList("d")))); assertFalse(set.containsAll(Sets.newTreeSet(asList("z")))); assertFalse(set.containsAll(Sets.newTreeSet(asList("b", "d")))); assertFalse(set.containsAll(Sets.newTreeSet(asList("f", "d", "a")))); }
public void testContainsAll_notSortedSet() { SortedSet<String> set = of("a", "b", "f"); assertTrue(set.containsAll(Collections.emptyList())); assertTrue(set.containsAll(asList("b"))); assertTrue(set.containsAll(asList("b", "b"))); assertTrue(set.containsAll(asList("b", "f"))); assertTrue(set.containsAll(asList("b", "f", "a"))); assertFalse(set.containsAll(asList("d"))); assertFalse(set.containsAll(asList("z"))); assertFalse(set.containsAll(asList("b", "d"))); assertFalse(set.containsAll(asList("f", "d", "a"))); }
public void testExplicit_contains() { SortedSet<String> set = ImmutableSortedSet.orderedBy(STRING_LENGTH) .add("in", "the", "quick", "jumped", "over", "a") .build(); assertTrue(set.contains("quick")); assertTrue(set.contains("google")); assertFalse(set.contains("")); assertFalse(set.contains("california")); assertFalse(set.contains(null)); }
public void testSingle_tailSet() { SortedSet<String> set = of("e"); assertTrue(set.tailSet("c") instanceof ImmutableSortedSet); assertThat(set.tailSet("c")).contains("e"); assertThat(set.tailSet("e")).contains("e"); assertSame(of(), set.tailSet("g")); }
@GwtIncompatible // SerializableTester, ImmutableSortedAsList public void testAsListReturnTypeAndSerialization() { ImmutableSet<String> set = ImmutableSortedSet.of("a", "e", "i", "o", "u"); ImmutableList<String> list = set.asList(); assertTrue(list instanceof ImmutableSortedAsList); ImmutableList<String> copy = SerializableTester.reserializeAndAssert(list); assertTrue(copy instanceof ImmutableSortedAsList); }
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 testSingle_headSet() { SortedSet<String> set = of("e"); assertTrue(set.headSet("g") instanceof ImmutableSortedSet); assertThat(set.headSet("g")).contains("e"); assertSame(of(), set.headSet("c")); assertSame(of(), set.headSet("e")); }
@GwtIncompatible // SerializableTester, ImmutableSortedAsList public void testSubsetAsListReturnTypeAndSerialization() { ImmutableSet<String> set = ImmutableSortedSet.of("a", "e", "i", "o", "u").subSet("c", "r"); ImmutableList<String> list = set.asList(); assertTrue(list instanceof ImmutableSortedAsList); ImmutableList<String> copy = SerializableTester.reserializeAndAssert(list); assertTrue(copy instanceof ImmutableSortedAsList); }
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")); }
@GwtIncompatible // SerializableTester public void testOf_serialization() { SortedSet<String> set = of("e", "f", "b", "d", "c"); SortedSet<String> copy = SerializableTester.reserializeAndAssert(set); assertTrue(Iterables.elementsEqual(set, copy)); assertEquals(set.comparator(), copy.comparator()); }
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())); }
@GwtIncompatible // SerializableTester public void testDifferentComparator_serialization() { // don't use Collections.reverseOrder(); it didn't reserialize to the same instance in JDK5 Comparator<Comparable<?>> comparator = Ordering.natural().reverse(); SortedSet<String> set = new ImmutableSortedSet.Builder<String>(comparator).add("a", "b", "c").build(); SortedSet<String> copy = SerializableTester.reserializeAndAssert(set); assertTrue(Iterables.elementsEqual(set, copy)); assertEquals(set.comparator(), copy.comparator()); }
@GwtIncompatible // SerializableTester public void testExplicit_serialization() { SortedSet<String> set = ImmutableSortedSet.orderedBy(STRING_LENGTH) .add("in", "the", "quick", "jumped", "over", "a") .build(); SortedSet<String> copy = SerializableTester.reserializeAndAssert(set); assertTrue(Iterables.elementsEqual(set, copy)); assertSame(set.comparator(), copy.comparator()); }
public void testLegacyComparable_builder_reverse() { @SuppressWarnings("unchecked") // Note: IntelliJ wrongly reports an error for this statement ImmutableSortedSet.Builder<LegacyComparable> builder = ImmutableSortedSet.<LegacyComparable>reverseOrder(); builder.addAll(LegacyComparable.VALUES_FORWARD); builder.add(LegacyComparable.X); builder.add(LegacyComparable.Y, LegacyComparable.Z); ImmutableSortedSet<LegacyComparable> set = builder.build(); assertTrue(Iterables.elementsEqual(LegacyComparable.VALUES_BACKWARD, set)); }
public void testLegacyComparable_builder_natural() { @SuppressWarnings("unchecked") // Note: IntelliJ wrongly reports an error for this statement ImmutableSortedSet.Builder<LegacyComparable> builder = ImmutableSortedSet.<LegacyComparable>naturalOrder(); builder.addAll(LegacyComparable.VALUES_BACKWARD); builder.add(LegacyComparable.X); builder.add(LegacyComparable.Y, LegacyComparable.Z); ImmutableSortedSet<LegacyComparable> set = builder.build(); assertTrue(Iterables.elementsEqual(LegacyComparable.VALUES_FORWARD, set)); }
public void testSingle_subSet() { SortedSet<String> set = of("e"); assertTrue(set.subSet("c", "g") instanceof ImmutableSortedSet); assertThat(set.subSet("c", "g")).contains("e"); assertThat(set.subSet("e", "g")).contains("e"); assertSame(of(), set.subSet("f", "g")); assertSame(of(), set.subSet("c", "e")); assertSame(of(), set.subSet("c", "d")); }