updated Vavr's Collection example
This commit is contained in:
parent
e3fed15627
commit
17ce271e8d
@ -34,7 +34,8 @@ public class CollectionAPIUnitTest {
|
|||||||
@Test
|
@Test
|
||||||
public void givenParams_whenListAPI_thenCorrect() {
|
public void givenParams_whenListAPI_thenCorrect() {
|
||||||
|
|
||||||
List<String> list = List.of("Java", "PHP", "Jquery", "JavaScript", "JShell", "JAVA");
|
List<String> list
|
||||||
|
= List.of("Java", "PHP", "Jquery", "JavaScript", "JShell", "JAVA");
|
||||||
|
|
||||||
List list1 = list.drop(2);
|
List list1 = list.drop(2);
|
||||||
assertFalse(list1.contains("Java") && list1.contains("PHP"));
|
assertFalse(list1.contains("Java") && list1.contains("PHP"));
|
||||||
@ -58,7 +59,8 @@ public class CollectionAPIUnitTest {
|
|||||||
assertEquals(list7.size(), 3);
|
assertEquals(list7.size(), 3);
|
||||||
|
|
||||||
//distinct
|
//distinct
|
||||||
List list8 = list.distinctBy( (s1, s2) -> s1.startsWith(s2.charAt(0)+"") ? 0 : 1);
|
List list8
|
||||||
|
= list.distinctBy( (s1, s2) -> s1.startsWith(s2.charAt(0)+"") ? 0 : 1);
|
||||||
assertEquals(list8.size(), 2);
|
assertEquals(list8.size(), 2);
|
||||||
|
|
||||||
//groupBY
|
//groupBY
|
||||||
@ -214,14 +216,12 @@ public class CollectionAPIUnitTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenSortedSet_whenReversed_thenCorrect() {
|
public void givenSortedSet_whenReversed_thenCorrect() {
|
||||||
SortedSet<String> set = TreeSet.of( "Green", "Red", "Blue");
|
SortedSet<String> reversedSet
|
||||||
assertEquals("Blue", set.head());
|
= TreeSet.of(Comparator.reverseOrder(), "Green", "Red", "Blue");
|
||||||
|
|
||||||
SortedSet<String> reversedSet = set.toSortedSet(Comparator.reverseOrder());
|
|
||||||
assertEquals("Red", reversedSet.head());
|
assertEquals("Red", reversedSet.head());
|
||||||
|
|
||||||
String str = set.mkString(" and ");
|
String str = reversedSet.mkString(" and ");
|
||||||
assertEquals("Blue and Green and Red", str);
|
assertEquals("Red and Green and Blue", str);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user