Added tests for 'displayContent' function
This commit is contained in:
parent
239afa3a3e
commit
7d86dae3d1
|
@ -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
|
||||
*/
|
|
@ -0,0 +1,6 @@
|
|||
type: edu
|
||||
files:
|
||||
- name: src/Task.kt
|
||||
visible: true
|
||||
- name: test/Tests.kt
|
||||
visible: false
|
|
@ -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.
|
|
@ -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")
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
content:
|
||||
- Examples
|
||||
- Exercise 1
|
||||
- Exercise 2
|
||||
- Exercise 3
|
||||
- Exercise 4
|
||||
|
|
Loading…
Reference in New Issue