Ad
  • Default User Avatar

    Okay, I fixed the problem in the description, but it shouldn't change your solution

  • Custom User Avatar

    Yes, I understand the rules (or at least I think so). I do not understand how to create a program which uses check_url. I called check_url, assigned its result to valriable res, and now what? How do I drive further logic depending on whether the ID is reported to be valid, or invalid? For example, how should I fill the gaps here:

    url = read_from_file('myfile.txt')
    res = check_url(url)
    if ... what to enter here... :
       open_in_browser(url) # or whatever action on a valid URL, or on a valid ID
    else:
      error = ... how to use res to recognize the error ...
      show_error(error)
    

    The point is, if the check_url returns a string on success and a string on failure, it is very difficult to tell whether the URL is valid or not. The choice of return values is very inconvenient.

  • Custom User Avatar

    Normally there are double slashes in urls and alike:

    https://google.com
    file://c:/test.txt
    
  • Default User Avatar

    I have now specified that the ID's have only the digits 0-9

  • Default User Avatar

    A URL is valid if all of the following are true

    1.The scheme (every charecter before the first "/") has to equal "https:"

    2.The Id (every charecter after the last "/") has to have a length of five or four

    If the Id is four charecters long at this point you would add a "0" to the begining

    3.The modified Id does not start with "00"

    The scheme is invalid if statement 1. is not true. The ID is invalid if either statement 2. or 3. are false.

  • Default User Avatar

    Okay I have changed the hs/UL.com/4 examples to hs:/UL.com/4. And changed the use of protocol to scheme

  • Custom User Avatar

    This should be specified. This can also be surprising in context of working with URLs, because if 12%32 was a part of an URL, it would usually translate to three characters, not five.

  • Custom User Avatar

    Let's assume that my program calls res = check_url(some_url). What code should I write, what should I do with res, to determine whether the URL is valid or not (and why not)?

  • Default User Avatar

    For this kata 12%32 has five, but all the IDs should only have the numerical digits 0-9 in them

  • Default User Avatar

    I am sorry for any confusion I have caused. If you are talking about outputs when either the ID or protocol is invalid protocol_string = "{whatever the protocol is} is an invalid protocol." Id_string = "{Id} is an invalid store ID.".The returned string should have the protocol_string if the protocol is invalid and the Id isn't. If the ID is invalid but the protocol isn't you should return Id_string. When both are invalid return protocol_string+Id_string. If this is not what you're talking about, I do not quite understand what you are saying.

  • Custom User Avatar

    URLs are tricky. Is 12%32 three characters, or five?

  • Custom User Avatar

    Raising an appropriate, annotated, Exception on failure feels like the way to go here.

  • Custom User Avatar

    Additionally, I think the better term would be "scheme". For example mailto and file are well known schemes commonly used in URLs, but they are not protocols.

  • Custom User Avatar

    This should be actually an issue. Current design does not allow to easily distinguish success from invalid_scenario1 from invalid_scenario2.

  • Custom User Avatar

    Is there any way to distinguish result strings for valid and invalid inputs? Something like how Haskell has Left "invalid ID" and Right "12345" ?

    Searching return values for the substring "invalid" does not feel like good datatype design.

  • Loading more items...