[All Your Base] Two tests appear to be expecting wrong values

I have some feedback on the tests for this exercise: All Your Base in Python on Exercism.

I believe the intent of the exercise is to treat the input list digits as a single number in the original input_base and to convert that number to a number in output_base expressed as a list of digits. For example, rebase(7, [0, 6, 0], 10) means, “convert 60 from base-7 to base-10.”

If that is a correct understanding, then I believe that two of the tests are expecting incorrect results:

First Issue

    def test_15_bit_integer(self):
        self.assertEqual(rebase(97, [3, 46, 60], 73), [6, 10, 45])
  • 34660 in base-97 is 269295571 in base-10
  • 269295571 in base-10 is 935177131 in base-73

The correct answer should be [9, 35, 17, 71, 31]

Second Issue

    def test_hexadecimal_to_trinary(self):
        self.assertEqual(rebase(16, [2, 10], 3), [1, 1, 2, 0])
  • 210 in base-16 is 528 in base-10
  • 528 in base-10 is 201120 in base-3

The correct answer should be [2, 0, 1, 1, 2, 0]

Thanks for your time and my apologies if I’m missing something about the exercise or the math involved here.

My code for this challenge, which you’re under no obligation to look at unless it’s diagnostically useful for you, is here.

2, 10 is not 210. It is 2 in the second place and 10 (or, a in hex) in the first place. Hex 210 would be [2, 1, 0] which is very different than [2, 10]. [2, 10] is one greater than [2, 9] (hex 29).

I hope this helps :slight_smile:

Note, this exercise has nearly 4,000 completed solutions. If this test was terribly broken, all those solutions would be equally broken. Python is one of the larger Exercism tracks; the tests might be terribly broken, but it’s not very likely.

1 Like

Thank you! Yes, I completely agree about the many solutions being a good indicator. I typically don’t submit until all tests are passing so I hadn’t had a chance to look at the other solutions.

As for the intent of the exercise, I appreciate the clarification. The exercise only says, “Convert a sequence of digits in one base, representing a number …”. I actually think your comment provides a much more understandable explanation of what the exercise is asking for!

1 Like