You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 3, 2025. It is now read-only.
class StringMaxCharTest {
@Test
fun `SOme test`() {
maxChar("a") shouldEqual 'a'
}
}
fun maxChar(str: String): Char? {
val map = mutableMapOf<Char, Int>()
str.forEach {
map[it] = (map[it] ?: 0) + 1
}
return map.maxBy { it.value }?.key
}
Above tests works fine, however when we change our assertion to compare with String, not Char: maxChar("a") shouldEqual "a"
...tests fails with very unintuitive error description java.lang.AssertionError: Expected <a>, actual <a>.
It's quite easy to make such a mistake by a programmer, so maybe Kluent can address this issue in a better way eg. by checking if the string has a single character and converting it to Char or display data types in error description