pavi2410
08/24/2019, 7:19 PMreadLine
function from stdlib which yields each line in the multiline text block. This is supposed to act just like readLine
but reads from a fixed string instead of stdin.
Here is how I'm trying to make it work: https://pl.kotl.in/f-ayPvSC-Kroppeb
08/24/2019, 7:22 PMpavi2410
08/24/2019, 7:25 PMKroppeb
08/24/2019, 7:34 PMkarelpeeters
08/24/2019, 7:34 PMfun readLine(): Sequence<String>
, it returns a sequence of lines. Right now you're printing that sequence, not items from that sequence.pavi2410
08/24/2019, 8:39 PMf = (x for x in list)
generator function in Kotlin?karelpeeters
08/24/2019, 10:34 PMf = list.iterator()
pavi2410
09/01/2019, 7:00 AMhalirutan
09/01/2019, 11:52 AMfun testFunction(input: String, output: String, func: () -> Unit) {
val oldIn = System.`in`
val oldOut= System.out
val inputStream = ByteArrayInputStream(input.toByteArray())
val outputStream = ByteArrayOutputStream()
System.setIn(inputStream)
System.setOut(PrintStream(outputStream))
func()
System.setIn(oldIn)
System.setOut(oldOut)
assertEquals(output, outputStream.toString().trim())
inputStream.close()
outputStream.close()
}
fun testFunction(testCases: Map<String, String>, func: () -> Unit) {
testCases.forEach { (input, output) ->
testFunction(input, output, func)
}
}