exercism / kotlin

Exercism exercises in Kotlin.
https://exercism.org/tracks/kotlin
MIT License
221 stars 191 forks source link

Add test cases to Secret Handshake exercise #624

Closed irene-mandarine closed 6 months ago

irene-mandarine commented 6 months ago

There is a small gap in test cases which would allow error prone code to pass the tests. For example, there is checked 32 with empty list as the result (because it's 10_000 in binary), and it works fine for following code (returns empty list on after index == 4 check) : ` fun calculateHandshake(number: Int): List { val action = Integer.toBinaryString(number).reversed() val result = mutableListOf()

    for((index, n) in action.withIndex()) {
        if (index == 4) {
            return result.reversed()
        }
        if (n.toString().toInt() == 1) {
           result.add(Signal.values()[index])
        }
    }
    return result
}`

Once you change test number to 33, which also should return an empty list, the list actually contains "WINK"

I propose to add one more test case to cover that little gap

github-actions[bot] commented 6 months ago

Hello. Thanks for opening an issue on Exercism 🙂

At Exercism we use our Community Forum, not GitHub issues, as the primary place for discussion. That allows maintainers and contributors from across Exercism's ecosystem to discuss your problems/ideas/suggestions without them having to subscribe to hundreds of repositories.

This issue will be automatically closed. Please use [this link](https://forum.exercism.org/new-topic?title=Add%20test%20cases%20to%20Secret%20Handshake%20exercise&body=There%20is%20a%20small%20gap%20in%20test%20cases%20which%20would%20allow%20error%20prone%20code%20to%20pass%20the%20tests.%20%0D%0AFor%20example,%20there%20is%20checked%2032%20with%20empty%20list%20as%20the%20result%20(because%20it's%2010_000%20in%20binary),%20and%20it%20works%20fine%20for%20following%20code%20(returns%20empty%20list%20on%20after%20index%20==%204%20check)%20:%0D%0A%60%20%20%20%20fun%20calculateHandshake(number:%20Int):%20List%3CSignal%3E%20%7B%0D%0A%20%20%20%20%20%20%20%20val%20action%20=%20Integer.toBinaryString(number).reversed()%0D%0A%20%20%20%20%20%20%20%20val%20result%20=%20mutableListOf%3CSignal%3E()%0D%0A%0D%0A%20%20%20%20%20%20%20%20for((index,%20n)%20in%20action.withIndex())%20%7B%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20(index%20==%204)%20%7B%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20return%20result.reversed()%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20(n.toString().toInt()%20==%201)%20%7B%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20result.add(Signal.values()%5Bindex%5D)%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0D%0A%20%20%20%20%20%20%20%20%7D%0D%0A%20%20%20%20%20%20%20%20return%20result%0D%0A%20%20%20%20%7D%60%0D%0A%0D%0AOnce%20you%20change%20test%20number%20to%2033,%20which%20also%20should%20return%20an%20empty%20list,%20the%20list%20actually%20contains%20%22WINK%22%20%0D%0A%0D%0AI%20propose%20to%20add%20one%20more%20test%20case%20to%20cover%20that%20little%20gap%0D%0A&category=kotlin ) to copy your GitHub Issue into a new topic on the forum, where we look forward to chatting with you!

If you're interested in learning more about this auto-responder, please read this blog post.