Skip to content

Commit

Permalink
randomizer should also work with a single element
Browse files Browse the repository at this point in the history
  • Loading branch information
jabdoa2 committed Dec 11, 2016
1 parent 32da897 commit 6b65362
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion mpf/core/randomizer.py
Expand Up @@ -60,7 +60,8 @@ def __next__(self):

self.data['items_sent'] = set()

if self.force_different:
# force different only works with more than 1 elements
if self.force_different and len(self.items) > 1:
potential_nexts = [x for x in self.items if x[0] is not (
self.data['current_item'])]
else:
Expand Down
11 changes: 11 additions & 0 deletions mpf/tests/test_Randomizer.py
Expand Up @@ -11,6 +11,17 @@ def getConfigFile(self):
def getMachinePath(self):
return 'tests/machine_files/randomizer/'

def test_one_element_with_force_different(self):
items = ['1']

r = Randomizer(items)
self.assertTrue(r.force_different)

# it has one element and should thereby always return it
self.assertEqual('1', next(r))
self.assertEqual('1', next(r))
self.assertEqual('1', next(r))

def test_machine_randomizer(self):

items = [
Expand Down

0 comments on commit 6b65362

Please sign in to comment.