package jetbrains.mps.internalCollections.test.basicOperations; /*Generated by MPS */ import jetbrains.mps.internalCollections.test.closures.Util_Test; import java.util.SortedSet; import jetbrains.mps.internal.collections.runtime.SortedSetSequence; import java.util.TreeSet; import junit.framework.Assert; import java.util.Arrays; import java.util.Comparator; import jetbrains.mps.internal.collections.runtime.Sequence; import java.util.Collection; import jetbrains.mps.internal.collections.runtime.IterableUtils; import jetbrains.mps.internal.collections.runtime.CollectionSequence; import java.util.Set; import jetbrains.mps.internal.collections.runtime.SetSequence; public class SortedSet_Test extends Util_Test { public void test_order() throws Exception { SortedSet<Integer> set = SortedSetSequence.fromSetAndArray(new TreeSet<Integer>(), 4, 5, 3, 2, 1); this.assertIterableEquals(this.input5(), set); Assert.assertSame(1, SortedSetSequence.fromSet(set).first()); Assert.assertSame(5, SortedSetSequence.fromSet(set).last()); } public void test_multiOrder() throws Exception { SortedSet<Integer> set = SortedSetSequence.fromSetAndArray(new TreeSet<Integer>(), 2, 1, 2, 5, 4, 3, 1, 5, 3, 2, 3, 1); this.assertIterableEquals(this.input5(), set); Assert.assertSame(1, SortedSetSequence.fromSet(set).first()); Assert.assertSame(5, SortedSetSequence.fromSet(set).last()); } public void test_headSet() throws Exception { SortedSet<String> set = SortedSetSequence.fromSetWithValues(new TreeSet<String>(), this.inputABCDEF()); this.assertIterableEquals(Arrays.asList("A", "B"), SortedSetSequence.fromSet(set).headSet("C")); this.assertIterableEquals(Arrays.asList("A", "B", "C"), SortedSetSequence.fromSet(set).headSet("C\0")); } public void test_tailSet() throws Exception { SortedSet<String> set = SortedSetSequence.fromSetWithValues(new TreeSet<String>(), this.inputABCDEF()); this.assertIterableEquals(Arrays.asList("C", "D", "E", "F"), SortedSetSequence.fromSet(set).tailSet("C")); } public void test_subSet() throws Exception { SortedSet<String> set = SortedSetSequence.fromSetWithValues(new TreeSet<String>(), this.inputABCDEF()); this.assertIterableEquals(Arrays.asList("C", "D"), SortedSetSequence.fromSet(set).subSet("C", "E")); this.assertIterableEquals(Arrays.asList("C", "D", "E"), SortedSetSequence.fromSet(set).subSet("C", "E\0")); } public void test_comparator() throws Exception { SortedSet<String> sset = SortedSetSequence.fromSet(new TreeSet<String>(new Comparator<String>() { public int compare(String a, String b) { return -String.CASE_INSENSITIVE_ORDER.compare(a, b); } })); SortedSetSequence.fromSet(sset).addSequence(Sequence.fromIterable(Sequence.fromArray(new String[]{"b", "d", "c", "a"}))); this.assertIterableEquals(Sequence.fromArray(new String[]{"d", "c", "b", "a"}), sset); } public void test_collection() throws Exception { SortedSet<String> ts = SortedSetSequence.fromSetAndArray(new TreeSet<String>(), "a", "b"); Collection<String> cs = ts; Assert.assertEquals("a b", IterableUtils.join(CollectionSequence.fromCollection(cs), " ")); SortedSetSequence.fromSet(ts).addElement("c"); Assert.assertEquals("a b c", IterableUtils.join(CollectionSequence.fromCollection(cs), " ")); } public void test_unmodifiable() throws Exception { SortedSet<String> ts = SortedSetSequence.fromSetAndArray(new TreeSet<String>(), "a", "b", "c"); SortedSetSequence.fromSet(ts).addElement("d"); SortedSetSequence.fromSet(ts).removeElement("b"); Assert.assertEquals("a c d", IterableUtils.join(SortedSetSequence.fromSet(ts), " ")); Set<String> uts = SortedSetSequence.fromSet(ts).asUnmodifiable(); try { SetSequence.fromSet(uts).addElement("e"); Assert.fail(); } catch (UnsupportedOperationException e) { // expected exception } SortedSetSequence.fromSet(ts).removeElement("a"); Assert.assertEquals("c d", IterableUtils.join(SetSequence.fromSet(uts), " ")); try { SetSequence.fromSet(uts).removeElement("c"); Assert.fail(); } catch (UnsupportedOperationException e) { // expected exception } } public SortedSet_Test() { } }