Skip to content

Commit 2f3398b

Browse files
Doha2012pivovarit
authored andcommitted
add more collection examples (eugenp#2243)
* minor logging fix * spring security sso * use basic auth * use form login * cleanup * cleanup * final cleanup * second client app for sso * spring boot bootstrap * add logic * cleanup * add simple controller * add thymeleaf and security * minor fix * minor fix * add more boot properties * fix live test * fix live test * minor fix * semaphores * fix configuration * kotlin collection * add more collection examples
1 parent 2e119a5 commit 2f3398b

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

‎kotlin/src/test/kotlin/com/baeldung/kotlin/CollectionsTest.kt‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,29 @@ class CollectionsTest {
118118
assertTrue(resultMap[2]!!.contains(5))
119119
}
120120

121+
@Test
122+
fun whenApplyFunctionToAllItems_thenSuccess () {
123+
val theList = listOf(1, 2, 3, 4, 5, 6)
124+
val resultList = theList.map{ it * it }
125+
print(resultList)
126+
assertEquals(4, resultList[1])
127+
assertEquals(9, resultList[2])
128+
}
129+
130+
@Test
131+
fun whenApplyMultiOutputFunctionToAllItems_thenSuccess () {
132+
val theList = listOf("John", "Tom")
133+
val resultList = theList.flatMap{ it.toLowerCase().toList()}
134+
print(resultList)
135+
assertEquals(7, resultList.size)
136+
assertTrue(resultList.contains('j'))
137+
}
138+
139+
@Test
140+
fun whenApplyFunctionToAllItemsWithStartingValue_thenSuccess () {
141+
val theList = listOf(1, 2, 3, 4, 5, 6)
142+
val finalResult = theList.fold( 1000, { oldResult, currentItem -> oldResult + (currentItem *currentItem)})
143+
print(finalResult)
144+
assertEquals(1091, finalResult)
145+
}
121146
}

0 commit comments

Comments
 (0)