Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.ffbit.collectioins;
- import static org.junit.Assert.assertEquals;
- import static org.junit.Assert.assertNull;
- import java.util.Comparator;
- import java.util.SortedSet;
- import java.util.TreeSet;
- import org.junit.Before;
- import org.junit.Test;
- public class SortedSetTest {
- private final String APPLE = "apple";
- private final String APRICOT = "apricot";
- private final String BERRY = "berry";
- private final String PLUM = "plum";
- private final String ZOO = "zoo";
- private SortedSet<String> sortedSet;
- @Before
- public void init() {
- sortedSet = new TreeSet<String>();
- fill(sortedSet, APPLE, APRICOT, BERRY, PLUM, ZOO);
- }
- @Test
- public void testComparator() {
- Comparator<?> comparator = sortedSet.comparator();
- assertNull(comparator);
- }
- @Test
- public void testFirst() {
- assertEquals(APPLE, sortedSet.first());
- }
- @Test
- public void testHeadSet() {
- SortedSet<String> headSet = new TreeSet<String>();
- fill(headSet, APPLE, APRICOT, BERRY);
- assertEquals(headSet, sortedSet.headSet(PLUM));
- }
- @Test
- public void testLast() {
- assertEquals(ZOO, sortedSet.last());
- }
- @Test
- public void testSubSet() {
- SortedSet<String> subSet = new TreeSet<String>();
- fill(subSet, APRICOT, BERRY, PLUM);
- assertEquals(subSet, sortedSet.subSet(APRICOT, ZOO));
- }
- @Test
- public void testTailSet() {
- SortedSet<String> tailSet = new TreeSet<String>();
- fill(tailSet, PLUM, ZOO);
- assertEquals(tailSet, sortedSet.tailSet(PLUM));
- }
- private <T> void fill(SortedSet<T> set, T...args) {
- for (T e : args) {
- set.add(e);
- }
- }
- }
Add Comment
Please, Sign In to add comment