Ad
  • Custom User Avatar

    The test constraints work perfectly. Thats why solutions without those unnecessary checks pass.

  • Custom User Avatar

    What on earth are you talking about?

  • Custom User Avatar

    Yeah. It passed all the tests, therefore it's incorrect. Solid logic.

  • Default User Avatar

    You read too much into it. When it says "input constraints" it doesn't mean you need to verify the inputs fall into that range. It means that all test case inputs to the function you create will fall into those ranges.

    I don't need to verify that h hours will be greater than or equal to 0 and less than or equal to 23 when the contraints tell me the input will be 0 <= h <= 23.

  • Custom User Avatar

    I just wanted to say that building applications that are resistant to unexpected user use requires writing more code.

  • Custom User Avatar

    You're telling me that undefined behaviour in a system is... undefined? Shocking.

  • Custom User Avatar

    How many fewer lines of code would we have if users typed what we wanted? 😉

  • Custom User Avatar

    If any of the constraints fail then the whole solution should return None.

    Actually, you do not need to implement these constraints yourself.

    Rather, the constraints are there to tell you the limits of the tested inputs, so you do not need to worry about / handle cases outside these limits.

    Input constraints:

    • 0 <= h <= 23
    • 0 <= m <= 59
    • 0 <= s <= 59

    For example, this tells you that h as an input will always be a number between 0 to 23, not -10 / 12345 / "ABCDEF" / [1] ...

    Example discussions


    Still, your solution is a valid approach to this kata, since the behaviour is not defined for values outside of these limit.

    • Should I raise an Exception here?
    • Should I return None here?
    • Should I just make the values overflow? e.g. "25:10:10" --> "01:10:10"
    • Should I just return the calculated result as is?

    These are all equally valid approaches depending on the use case, so you may implement whichever you see fit outside these bounds.

    Happy coding ^_^