mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-23 11:12:47 +01:00
Changed the utils.iter.choice test to work bettar.
This commit is contained in:
parent
3d60b66ee2
commit
6b19504515
@ -381,27 +381,21 @@ class IterTest(SupyTestCase):
|
|||||||
def testRandomChoice(self):
|
def testRandomChoice(self):
|
||||||
choice = utils.iter.choice
|
choice = utils.iter.choice
|
||||||
self.assertRaises(IndexError, choice, {})
|
self.assertRaises(IndexError, choice, {})
|
||||||
|
self.assertRaises(IndexError, choice, [])
|
||||||
|
self.assertRaises(IndexError, choice, ())
|
||||||
L = [1, 2]
|
L = [1, 2]
|
||||||
i = iter(L)
|
seenList = set()
|
||||||
L1 = False
|
seenIterable = set()
|
||||||
L2 = False
|
for n in xrange(300):
|
||||||
i1 = False
|
# 2**266 > 10**80, the number of atoms in the known universe.
|
||||||
i2 = False
|
# (ignoring dark matter, but that likely doesn't exist in atoms
|
||||||
for n in xrange(100):
|
# anyway, so it shouldn't have a significant impact on that #)
|
||||||
ans = choice(L)
|
seenList.add(choice(L))
|
||||||
if ans == 1:
|
seenIterable.add(choice(iter(L)))
|
||||||
L1 = True
|
self.assertEqual(len(L), len(seenList),
|
||||||
else:
|
'choice isn\'t being random with lists')
|
||||||
L2 = True
|
self.assertEqual(len(L), len(seenIterable),
|
||||||
ans = choice(i)
|
'choice isn\'t being random with iterables')
|
||||||
if ans == 1:
|
|
||||||
i1 = True
|
|
||||||
else:
|
|
||||||
i2 = True
|
|
||||||
self.assertEqual(L1 and L2, True,
|
|
||||||
'utils.iter.choice isn\'t being random with lists')
|
|
||||||
self.assertEqual(i1 and i2, True,
|
|
||||||
'utils.iter.choice isn\'t being random with iterables')
|
|
||||||
|
|
||||||
## def testGroup(self):
|
## def testGroup(self):
|
||||||
## group = utils.iter.group
|
## group = utils.iter.group
|
||||||
|
Loading…
Reference in New Issue
Block a user