Complete the code to assert that two values are equal.
import kotlin.test.assertEquals fun testSum() { val result = 2 + 3 assertEquals([1], result) }
The assertEquals function checks if the first value equals the second. Here, 2 + 3 equals 5, so we assert 5.
Complete the code to assert that a condition is true.
import kotlin.test.assertTrue fun testPositive() { val number = 10 assertTrue([1]) }
The assertTrue function checks if the condition is true. Since 10 is greater than 0, number > 0 is correct.
Fix the error in the assertion that checks if a list is empty.
import kotlin.test.assertTrue fun testEmptyList() { val list = listOf<Int>() assertTrue([1]) }
To assert that the list is empty, we use list.isEmpty(). Using list.isNotEmpty() would fail the test.
Fill both blanks to assert that a string contains a substring and is not empty.
import kotlin.test.assertTrue fun testString() { val text = "Hello Kotlin" assertTrue(text.[1]("Kotlin") && text.[2]()) }
The code checks if text contains "Kotlin" and is not empty. So, contains and isNotEmpty are correct.
Fill all three blanks to assert that a map has a key, the value is not null, and the value equals 42.
import kotlin.test.assertTrue fun testMap() { val map = mapOf("answer" to 42) assertTrue(map.[1]("answer") && map["answer"] [2] null && map["answer"] [3] 42) }
The code checks if the map contains the key "answer", the value is not null, and the value equals 42. So, containsKey, !=, and == are correct.