Looking for a bug

Report a typo

Imagine that you copied a palindrome checker method from stackoverflow.com and now want to be sure that it works as you expect. Here is that suspicious code:

class StringUtils {
    fun isPalindrome(string: String?): Boolean {
        if (string.isNullOrBlank() || string.length < 2) {
            return false
        }
        var start = 0
        var end = string.length - 1
        while (start < end) {
            if (string[start] != string[end]) {
                return false
            }
            start++
            end--
        }
        return true
    }
}

You quickly wrote a test method with some test cases:

import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.ValueSource

internal class StringUtilsTest{
    @ParameterizedTest
    @ValueSource(strings = ["rotator", "Stats", "(radar)", "level", "race car"])
    fun testPalindrome(str: String?) {
        val stringUtils = StringUtils()
        assertTrue(stringUtils.isPalindrome(str))
    }
}

Which of the test cases are going to fail when you run this test?

Select one or more options from the list
___

Create a free account to access the full topic