I was convinced my code for populating and returning ‘contents’ worked just fine and was perplexed at failing test 1.
The test
hat = prob_calculator.Hat(red=3,blue=2)
actual = hat.contents
expected = ["red","red","red","blue","blue"]
what my code returns: [‘blue’, ‘blue’, ‘red’, ‘red’, ‘red’]
The user is free to pass in balls of any colour with no restrictions. So I created init() to have a list of colour args that all default to zero. That makes it impossible to determine the order of balls in the call.
Each line in my init looks something like this:
self.contents += ["blue"] * blue
So to pass the test I can just make sure red is processed first.
But this is very unsatisfactory and a massive fudge. I’ve also seen that test 3 (I haven’t got that far) creates a hat with those colour arguments reversed. Luckily it doesn’t test for contents again, but if it did there is no way I could ever pass all 3 tests in 1 pass.
You may disagree, but I would say my list and the test’s list are effectively the same (I hope to prove this when I implement def experiment()). If the test was just insisting on the list having the balls in alphabetical order that would be trivial to solve (ideally the test would do its own sort). But it just seems to be insisting on the order of balls in the container being the same order as passed in.
If I’m right, that would force me into a particular style of solution, when I should be free to implement as I choose as long as the spec is matched.
Am I missing something here?