0
0
Kotlinprogramming~10 mins

Why testing matters in Kotlin - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to print a test message.

Kotlin
fun main() {
    println([1])
}
Drag options to blanks, or click blank then click option'
A"Test passed!"
BTest passed!
Cprintln("Test passed!")
Dpass
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put quotes around the string.
Trying to print without using println.
2fill in blank
medium

Complete the code to check if a test result is true.

Kotlin
fun isTestSuccessful(result: Boolean): Boolean {
    return result [1] true
}
Drag options to blanks, or click blank then click option'
A=>
B=
C!=
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using single equals instead of double equals for comparison.
Using wrong comparison operators.
3fill in blank
hard

Fix the error in the test function to return the correct message.

Kotlin
fun testMessage(passed: Boolean): String {
    return if (passed) [1] else "Test failed"
}
Drag options to blanks, or click blank then click option'
Aprintln("Test passed")
B"Test passed"
CTest passed
Dpassed
Attempts:
3 left
💡 Hint
Common Mistakes
Returning a print statement instead of a string.
Forgetting quotes around the string.
4fill in blank
hard

Fill both blanks to create a list of test results and check if all passed.

Kotlin
val results = listOf([1], [2], false)
val allPassed = results.all { it }
println(allPassed)
Drag options to blanks, or click blank then click option'
Atrue
Bfalse
C1
D"passed"
Attempts:
3 left
💡 Hint
Common Mistakes
Using numbers or strings instead of Booleans in the list.
Confusing true and false values.
5fill in blank
hard

Fill all three blanks to create a map of test names to results and filter passed tests.

Kotlin
val testResults = mapOf([1] to [2], "test2" to false, "test3" to true)
val passedTests = testResults.filter { it.value [3] true }
println(passedTests.keys)
Drag options to blanks, or click blank then click option'
A"test1"
Btrue
C==
D"passed"
Attempts:
3 left
💡 Hint
Common Mistakes
Using strings instead of Booleans for test results.
Using wrong comparison operators in filter.