Guest User

Untitled

a guest
Oct 22nd, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. package com.ffbit.collectioins;
  2.  
  3. import static org.junit.Assert.assertEquals;
  4. import static org.junit.Assert.assertNull;
  5.  
  6. import java.util.Comparator;
  7. import java.util.SortedSet;
  8. import java.util.TreeSet;
  9.  
  10. import org.junit.Before;
  11. import org.junit.Test;
  12.  
  13. public class SortedSetTest {
  14. private final String APPLE = "apple";
  15. private final String APRICOT = "apricot";
  16. private final String BERRY = "berry";
  17. private final String PLUM = "plum";
  18. private final String ZOO = "zoo";
  19.  
  20. private SortedSet<String> sortedSet;
  21.  
  22. @Before
  23. public void init() {
  24. sortedSet = new TreeSet<String>();
  25. fill(sortedSet, APPLE, APRICOT, BERRY, PLUM, ZOO);
  26. }
  27.  
  28. @Test
  29. public void testComparator() {
  30. Comparator<?> comparator = sortedSet.comparator();
  31. assertNull(comparator);
  32. }
  33.  
  34. @Test
  35. public void testFirst() {
  36. assertEquals(APPLE, sortedSet.first());
  37. }
  38.  
  39. @Test
  40. public void testHeadSet() {
  41. SortedSet<String> headSet = new TreeSet<String>();
  42. fill(headSet, APPLE, APRICOT, BERRY);
  43. assertEquals(headSet, sortedSet.headSet(PLUM));
  44. }
  45.  
  46. @Test
  47. public void testLast() {
  48. assertEquals(ZOO, sortedSet.last());
  49. }
  50.  
  51. @Test
  52. public void testSubSet() {
  53. SortedSet<String> subSet = new TreeSet<String>();
  54. fill(subSet, APRICOT, BERRY, PLUM);
  55. assertEquals(subSet, sortedSet.subSet(APRICOT, ZOO));
  56. }
  57.  
  58. @Test
  59. public void testTailSet() {
  60. SortedSet<String> tailSet = new TreeSet<String>();
  61. fill(tailSet, PLUM, ZOO);
  62. assertEquals(tailSet, sortedSet.tailSet(PLUM));
  63. }
  64.  
  65. private <T> void fill(SortedSet<T> set, T...args) {
  66. for (T e : args) {
  67. set.add(e);
  68. }
  69. }
  70.  
  71. }
Add Comment
Please, Sign In to add comment