1
1
Fork 0

Added tests for 'displayContent' function

This commit is contained in:
Svetlana Isakova 2019-10-09 18:11:04 +02:00
parent 239afa3a3e
commit 7d86dae3d1
5 changed files with 52 additions and 0 deletions

View File

@ -0,0 +1,18 @@
package repetitionwithwhile1
fun displayContent(s: String) {
var i = 0
while (i < s.length) {
println(s[i])
i++
}
}
fun main() {
displayContent("abc")
}
/* Expected output:
a
b
c
*/

View File

@ -0,0 +1,6 @@
type: edu
files:
- name: src/Task.kt
visible: true
- name: test/Tests.kt
visible: false

View File

@ -0,0 +1,4 @@
## Repetition with `while` (#2)
Using a `while` loop, write a function that takes a `String` argument and
displays each character on its own line.

View File

@ -0,0 +1,23 @@
package repetitionwithwhile1
import org.junit.Test
import util.checkSystemOutput
import util.runAndGetSystemOutput
class TestDisplayContent {
private fun testInput(s: String) {
val output = runAndGetSystemOutput {
displayContent(s)
}
val expected = s.toList().joinToString("\n")
checkSystemOutput("""Wrong output for 'displayContent("$s")'""",
expected, output)
}
@Test
fun testDisplayContent() {
testInput("abc")
testInput("Kotlin")
testInput("Hi! I'm a String")
}
}

View File

@ -1,5 +1,6 @@
content:
- Examples
- Exercise 1
- Exercise 2
- Exercise 3
- Exercise 4