Probability Calculator Test 2 Failure

Tell us what’s happening:

This is the last challenge of “Scientific Computing With Python”

The only test failure I am getting on my code is this.

FAIL: test_hat_draw (test_module.UnitTests)
Traceback (most recent call last):
  File "/home/runner/boilerplate-probability-calculator/", line 16, in test_hat_draw
    self.assertEqual(actual, expected, 'Expected hat draw to return two random items from hat contents.')
AssertionError: Lists differ: ['red', 'red'] != ['blue', 'red']

First differing element 0:

- ['red', 'red']
?   ^ -

+ ['blue', 'red']
?   ^^^
 : Expected hat draw to return two random items from hat contents.

Ran 3 tests in 0.052s

FAILED (failures=1)

Running draw() outside of the test modules confirms that the results are (pseudo-)random despite what the tests say, but evidently it’s not the “right” kind of random. Which randomization method does the test module prefer?

Your code so far

Here is the replit.

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:97.0) Gecko/20100101 Firefox/97.0

Challenge: Probability Calculator

Link to the challenge:

I think random.choice() should work, though I used random.randint().

Yes! Popping element n where n is determined by random.randint() gives the random results demanded by the test module.

In my opinion, this challenge should be revised to allow multiple paths to a correct method, including the more realistic random.sample(), which is written specifically for experiments like this.

But anyway, thank you for your help.

Really? It haven’t worked for me. I changed my code for:

removed = []
for i in range(quant_balls):
            n = random.randint(1,quant_balls)

I tried sample() (my first choice), then shuffle(), now randint().
I think this test is simply wrong. If the balls are drawn randomly, they should be allowed to be in any order and still pass the test.
Besides, with this hat (red=5, blue=2), there is no guarantee we’ll get exactly one blue and one red. The test makes no sense to me at all.
Anyone else? Any hint on how to solve this?

Oh, boy. I love you!!!
But I still think this is a non-sensical test…