Created
March 12, 2020 14:59
-
-
Save andrewharmellaw/b7d8bb217d9a3edb74008122d1cff127 to your computer and use it in GitHub Desktop.
Folding in Kotlin (Tests)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
fun `foldLeft on a very large list is stack-safe`() { | |
val seed = 1; | |
val massiveList = mutableListOf<Int>() | |
for (i in 1..10000) { | |
massiveList.add(i) | |
} | |
assertEquals(500501, foldLeft(massiveList, seed, ::sum)) | |
} | |
@Test | |
fun `foldRight on a very large list isn't stack safe`() { | |
val seed = 1; | |
val massiveList = mutableListOf<Int>() | |
for (i in 1..10000) { | |
massiveList.add(i) | |
} | |
assertEquals(500501, foldRightOverflows(massiveList, seed, ::product)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment