From 2f3398beaf47999cba34dbb020c2f211ae81235a Mon Sep 17 00:00:00 2001 From: Doha2012 Date: Mon, 10 Jul 2017 07:47:58 +0200 Subject: [PATCH] add more collection examples (#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 --- .../com/baeldung/kotlin/CollectionsTest.kt | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/kotlin/src/test/kotlin/com/baeldung/kotlin/CollectionsTest.kt b/kotlin/src/test/kotlin/com/baeldung/kotlin/CollectionsTest.kt index 81a01ca4fb..59d6adccac 100644 --- a/kotlin/src/test/kotlin/com/baeldung/kotlin/CollectionsTest.kt +++ b/kotlin/src/test/kotlin/com/baeldung/kotlin/CollectionsTest.kt @@ -118,4 +118,29 @@ class CollectionsTest { assertTrue(resultMap[2]!!.contains(5)) } + @Test + fun whenApplyFunctionToAllItems_thenSuccess () { + val theList = listOf(1, 2, 3, 4, 5, 6) + val resultList = theList.map{ it * it } + print(resultList) + assertEquals(4, resultList[1]) + assertEquals(9, resultList[2]) + } + + @Test + fun whenApplyMultiOutputFunctionToAllItems_thenSuccess () { + val theList = listOf("John", "Tom") + val resultList = theList.flatMap{ it.toLowerCase().toList()} + print(resultList) + assertEquals(7, resultList.size) + assertTrue(resultList.contains('j')) + } + + @Test + fun whenApplyFunctionToAllItemsWithStartingValue_thenSuccess () { + val theList = listOf(1, 2, 3, 4, 5, 6) + val finalResult = theList.fold( 1000, { oldResult, currentItem -> oldResult + (currentItem *currentItem)}) + print(finalResult) + assertEquals(1091, finalResult) + } } \ No newline at end of file