7 kyu

Fix the base conversion function!

Description
Loading description...
Debugging
  • Please sign in or sign up to leave a comment.
  • saudiGuy Avatar

    python new test framework is required. updated in this fork

  • oldcoder Avatar

    good kata

  • WestwardLand968 Avatar

    This comment has been hidden.

    • user8751232 Avatar

      Regarding return value description says #The output should be a string at all times, also Fix his convert_num() function so it correctly converts a base-10 integer so you should check if passed input is an int.

      Issue marked resolved by user8751232 5 years ago
    • WestwardLand968 Avatar

      No, more specifically; bool data types have different expected values, check the test cases.

      (anyways, solved this thing through some trial and error)

    • user8751232 Avatar

      This kata favors certain way of type checking and uses certain property of booleans that is present in python. Description doesn't deviate from actual task and as such I don't see it being an issue, more of hidden trickiness.

    • WestwardLand968 Avatar

      Makes sense, thanks!

  • zebulan Avatar

    @Caders,

    • Your tests are backwards. If you look at the Codewars Python docs, you will see this:

      test.assert_equals(actual, expected, message)

      Checks that the actual value equals the expected value. If the test does not pass, an (optional) specified message is displayed. The default for message is

      "{actual} should be {expected}".format(actual=actual, expected=expected)

      The error messages get messed up because your tests are written like this:

      test.assert_equals(expected, actual)

    • Instead of using print statements above each test, you should use test.it('describe your test here...'). That is why your kata is not compatible with Python 3.

    • Lastly, you need random tests. Make sure to use range instead of xrange so that your random tests are compatible with both versions of Python.

    Thanks!

    • Caders Avatar

      @zebulan,

      Thank you so much for the suggestion, I need all the help I can get!

      I've updated the testing as you suggested, let me know if there are any other improvements to be made!

      Issue marked resolved by Caders 9 years ago
    • zebulan Avatar

      @Caders,

      Thanks for the fast response!

      Since you asked about other improvements, I started making a list but it was getting a bit long so I thought it might be better if I updated them myself and let you look at them:

      • You don't need to add the message part to test.assert_equals (unless you wanted to change the format/output of the error message)
      • The example test cases were still backwards
      • You don't need to add the first number 0 inside of range(start, stop, step) since start defaults to 0
      • Also, since you aren't using i for anything you could replace it with _ -> for _ in range(50):
      • If you put cant_touch inside of Preloaded Code, everyone can access it... just put it inside of Test Cases
        • I can simply put this inside of the function and it would have passed all tests return cant_touch(number, base)
      • I'm not sure if there is some reason as to why you are generating random ints in the way you were, you can also just use random.randint?
      • The random tests didn't seem DRY, there was some unnecessary duplication

      Hopefully you don't mind the changes!

      EDIT:

      Of course, after my own comment bringing up the backwards tests that's what I ended up doing to the random tests haha. I just fixed that after looking at it again. They should match test.assert_equals(actual, expected) now.

    • Caders Avatar

      Thanks for the tip on range()!

      What does using the _ do in a range() rather than i? Or is it just to avoid use of i anywhere else?

      My bad, I thought the docs said that Preloaded Code wasn't accessible by the user!

      I really appreciate the changes, I'll definitely be updating my other kata to match the standard! :D

    • zebulan Avatar

      It's basically just a throwaway value. It just indicates that the value isn't going to be used for anything.

      EDIT: https://stackoverflow.com/questions/5893163/what-is-the-purpose-of-the-single-underscore-variable-in-python

      Preloaded code is great if (for example) you had a big dictionary that everyone was supposed to use in their solution. If you didn't put it in the preloaded section, every single solution would have to copy/paste that same dictionary. I like to look through maybe the first 20 or 30 solutions after I solve a kata but if there is the same dictionary that is massive in each one, I don't really spend as much time looking through other solutions.

      It can be used for other things too, helper functions, classes, etc. Anything that you just don't want to have duplicated in each solution (at least that's how I look at it!).

    • Caders Avatar

      Thank you for the further explanation and swift replies!

      I'll keep all of these things in mind going forward, and hopefully (admittedly probably not) won't need too much more help in the future.

      Thanks!

    • zebulan Avatar

      @Caders,

      No problem at all. I have only authored a single kata so far, so I don't want to give the impression that I know all the ins and outs of the authoring process. I just solve katas for fun/learning but after solving almost 1000 katas (mostly Python, some JavaScript), I am just used to seeing the test cases and the patterns involved.

      I have learned so much using Codewars that I like to try and give back in whatever small way I can.

      Keep up the great work on your katas, I've enjoyed a few of them so far! (I'm just about to start Colored hexes)