/*
* Copyright 2014 Goldman Sachs.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gs.collections.impl.set.sorted.mutable;
import java.util.Collections;
import java.util.Comparator;
import java.util.SortedSet;
import java.util.TreeSet;
import com.gs.collections.api.LazyIterable;
import com.gs.collections.api.set.sorted.MutableSortedSet;
import com.gs.collections.impl.list.mutable.FastList;
import com.gs.collections.impl.test.Verify;
import org.junit.Assert;
import org.junit.Test;
public class TreeSortedSetTest extends AbstractSortedSetTestCase
{
@Override
protected <T> TreeSortedSet<T> newWith(T... elements)
{
return TreeSortedSet.newSetWith(elements);
}
@Override
protected <T> TreeSortedSet<T> newWith(Comparator<? super T> comparator, T... elements)
{
return TreeSortedSet.newSetWith(comparator, elements);
}
@Override
@Test
public void asSynchronized()
{
Verify.assertInstanceOf(SynchronizedSortedSet.class, this.newWith().asSynchronized());
}
@Override
@Test
public void asUnmodifiable()
{
Verify.assertInstanceOf(UnmodifiableSortedSet.class, this.newWith().asUnmodifiable());
}
@Test
public void sortedSetIterableConstructor()
{
TreeSortedSet<Integer> sortedSetA = TreeSortedSet.newSet(Collections.<Integer>reverseOrder());
TreeSortedSet<Integer> sortedSetB = TreeSortedSet.newSet(sortedSetA.with(1).with(2, 3).with(4, 5, 6));
Verify.assertSortedSetsEqual(sortedSetA, sortedSetB);
Assert.assertTrue(sortedSetA.first().equals(sortedSetB.first()) && sortedSetB.first() == 6);
Verify.assertSortedSetsEqual(sortedSetB, new TreeSortedSet<>(sortedSetB));
}
@Test
public void sortedSetConstructor()
{
SortedSet<String> setA = new TreeSet<>(FastList.newListWith("a", "c", "b", "d"));
Verify.assertSortedSetsEqual(setA, TreeSortedSet.newSet(setA));
Verify.assertSortedSetsEqual(setA, new TreeSortedSet<>(setA));
}
@Test
public void iterableConstructor()
{
LazyIterable<Integer> integerLazyIterable = FastList.newListWith(2, 4, 1, 3).asLazy();
TreeSortedSet<Integer> sortedSet = TreeSortedSet.newSet(integerLazyIterable);
Verify.assertSortedSetsEqual(TreeSortedSet.newSetWith(1, 2, 3, 4), sortedSet);
}
@Test
public void serialization()
{
MutableSortedSet<Integer> set = this.newWith(1, 2, 3, 4, 5);
Verify.assertPostSerializedEqualsAndHashCode(set);
}
}