Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5. Extract duplicated code - alternative solution rejected #75

Open
rwst opened this issue Mar 15, 2024 · 0 comments
Open

5. Extract duplicated code - alternative solution rejected #75

rwst opened this issue Mar 15, 2024 · 0 comments

Comments

@rwst
Copy link

rwst commented Mar 15, 2024

In the "5. Extract duplicated code" task, submitting this solution fails:

...
fun wordCount(fileName: String): Int {
    val file = checkFile(fileName)
    var wordCount = 0
    file.forEachLine { line ->
        wordCount += line.split("\\s+".toRegex()).count()
    }
    return wordCount
}

private fun checkFile(fileName: String): File {
    val file = File(fileName)
    if (!file.exists() || !file.isFile) {
        throw FileNotFoundException()
    }
    return file
}

fun copyFile(srcName: String, destName: String) {
    val file = checkFile(srcName)
    val to = File(destName)
    file.copyTo(to)
}

While the err message states: Please, extract the code that checks if the file exists and is valid. I think this solution should also be accepted, or, if you reject the suggestion then, at least, that sentence should be shown in the task description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant