[pycrypto] Issue with the new random.choice() unit test
Thorsten Behrens
sbehrens at gmx.li
Tue Jan 4 14:40:18 CST 2011
I have introduced a unit test in test_random.py that has too high a rate
of failure. Specifically, this:
# Test choice
seq = []
for i in range(500): # seed the sequence
seq[i:] = [random.getrandbits(32)]
x = random.choice(seq)
y = random.choice(seq)
self.assertNotEqual(x, y)
just produced a FAIL:
FAIL: runTest (Crypto.SelfTest.Random.test_random.SimpleTest)
Crypto.Random.new()
----------------------------------------------------------------------
Traceback (most recent call last):
File "build\lib.win-amd64-2.7\Crypto\SelfTest\Random\test_random.py",
line 103, in runTest
self.assertNotEqual(x, y)
AssertionError: 1793595220L == 1793595220L
Well darn. I guess saying "hey it's a 1 in 500 chance, it'll never
fail!" is indeed naive. What would be a less naive test, then? I am
thinking seeding a much smaller seq, and then running choice many times,
counting collisions each time, and getting some form of expected value
with an expected precision from that. It's been very long since I've
done stochastic stuff, however. Before I screw this up further: Concrete
suggestions on how to fix this unit test?
Thanks!
Thorsten
More information about the pycrypto
mailing list