Retired

Basic Statement Coverage in Unit Testing (retired)

86 of 151drchangliu
Description
Loading description...
Fundamentals
  • Please sign in or sign up to leave a comment.
  • Voile Avatar

    This shouldn't pass, but it passes.

  • Voile Avatar

    The reference code in the description is missing the JS version.

  • yaneX Avatar

    It's a pretty interesting kata and unique, that's for sure. The problem is that the description is quite confusing. You should provide some details about how the function should work, that would be much easier to make some tests, that would prove that the implementation is wrong.

    Also, in C# tests break, when I call function with null as a parameter, I think you should probably look into that, because the first parameters, that would come to my mind when testing using string as paarameter is string.Empty and null.

  • Shane-Xue Avatar

    Thank you for the invitation. The idea of the kata is very interesting. However, I could not understand what you want me to do. You gave me a piece of code that I think I can run alright. Do you want me to correct that code? Or do you want me to solve some problem. What should I do in my function? What will I return? Neither the explanation nor the tests gave me any idea on what to do. Good luck!

    • drchangliu Avatar

      Which language were you working on? I can give you more detailed info if I know which version of the kata you were referring to. Thanks.

    • Shane-Xue Avatar

      Python. Would be gr8 if you do so. Thx

    • drchangliu Avatar

      If you click "test", it would fail for the provided template. That's because you need to provide test cases.

      From the problem description: "Your function should do all the calls to the count_ballot() function needed to obtain full statement coverage for this function as listed below."

  • Kacarott Avatar

    The kata itself is a little disappointing, but I think that is only because the concept is very interesting, and I was hoping for more of a challenge. This one I think is fine for beginners (if a little confusing for what they have to do), but I think this could certainly be a cool kata series of 'unit testing' for progressively harder, more complex testing and functions being tested. I look forward to more!

    • drchangliu Avatar

      Thank you for the encouragement. Yes, doing testing is very different. I'm not sure if CodeWars is the right platform for unit tests but it's worth a try.

  • dinglemouse Avatar

    This comment has been hidden.

  • rge123 Avatar

    https://www.codewars.com/kata/reviews/5faff110c93b4900017ab86e/groups/5fb44c428a65f20001ee7175

    You need to remove anything to do with testing from preloaded.

  • JohanWiltink Avatar

    Statement coverage is clearly insufficient. I can follow all code paths without ever testing a ballot that votes for both Biden and Green.

    You don't claim statement coverage is sufficient ( or even necessary ), but acknowledging this situation would clarify what it can and can't do.

    • drchangliu Avatar

      Thanks for the suggestion. I updated the description to reflect this. You can't cover all statements without testing a ballot that votes for both Biden and Green, though, because there's a "return "INVALID"" statement.

      Suggestion marked resolved by drchangliu 4 years ago
    • JohanWiltink Avatar

      Nyet.

      An empty string will test that branch. But that ballot for Green + Biden will result in a vote for Biden ( if I remember correctly ), which shows the inadequacy of this way of testing. Because it should result in invalid, of course.

    • drchangliu Avatar

      An empty string covers the "None" case, not the "Invalid" case. "Green + Biden" will indeed become a vote for Biden. That would be a bug but in this case we are only asking for full statement coverage, not a specification-based testing round. In fact, the "full spec" was not provided. Thanks.

    • JohanWiltink Avatar

      Oh sorry, "Trump Biden" tests that branch. I didn't actually look it up and went from memory.

      If you insist on bad testing, have at it. Thanks. Unsatisfied. Done.

  • JohanWiltink Avatar

    What is ballot.lower() ?

    Note that I'm not American, and don't know about their ballots. Our input is ballot. What is that, actually? Does it have a lower half, or can they be lowered, or something? What's the upper half then, and why are we getting it if we are not to test it?

    In short: specs for ballot are incomplete. ( Well, missing. )

    • drchangliu Avatar

      Function lower() is to turn all letters to lower case so that "Biden" and "biden" can both be matched with the search string "biden".

      Paramter ballot is a string that contains the name of the person that one voted for.

    • StephenDonovan1 Avatar

      Yeah ballot is just a string here, it's mentioned in the code snippet in the description. So .lower() is just Python's lowercase method.

    • JohanWiltink Avatar

      it's mentioned

      It is now.

      Question marked resolved by JohanWiltink 4 years ago
  • Blind4Basics Avatar

    Hi,

    It's a bit surprising as a kata, but the idea is rather nice. You have several things to take care of:

    (This will end up in white level, so you need to be perfectly clear about what happens in the kata)

    cheers

    • drchangliu Avatar

      Very good suggestions. I updated the description to reflect your points 2 and 3. As for your first point, if I don't put the code in the preloaded part, where should I put it? I can't put in the example test because that's visible to users. I can't put it in the "test cases" section because I assume that means user can't do local test - they will have to click attempt/submit button all the time to reach the function-under-test. I also cannot put it in the complete solution because I assume that means, it's not accessible to users. Any suggestions as to where to hide the function-under-test? Thanks.

      Issue marked resolved by drchangliu 4 years ago
    • Blind4Basics Avatar

      Don't resolve issues if you actually didn't handle it completely, plz...

      about the tests, you only have to duplicate everything that is in preloaded at the beginning of the test cases: you're passing the function to the user's solution, so you can define it wherever you want. And you keep the version in the preloaded section for the sample tests.

    • drchangliu Avatar

      Good idea. Just updated the kata with that. Now this is really resolved. Thanks.

    • StephenDonovan1 Avatar

      Quick note, I already made the switch but you were still importing the preloaded evaluation function from preloaded, which was causing some silliness where we could just overwrite the evaluation function to make it always 1.