Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion python2/koans/about_dice_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
class DiceSet(object):
def __init__(self):
self._values = None
self._start = False

@property
def values(self):
Expand All @@ -17,7 +18,18 @@ def values(self):
def roll(self, n):
# Needs implementing!
# Tip: random.randint(min, max) can be used to generate random numbers
pass
last_roll = list()
while True:
if self._start == True:
last_roll = self._values
self._start = True
self._values = list()
iterat = range (0, n)
for x in iterat:
self._values.append(random.randint(1, 6))
if last_roll != self._values:
break
pass


class AboutDiceProject(Koan):
Expand Down Expand Up @@ -61,6 +73,11 @@ def test_dice_values_should_change_between_rolls(self):
# likely) that two consecutive rolls are equal. What would be a
# better way to test this?

# I'm not sure if it's the best way, but I added a flag called _start that checks if the dice
# roll was called before, and if it was, get the last value in order to compare with the current
# one, if it's the same, what it does is rolls again and do the same check, in only breaks when
# the list are different

def test_you_can_roll_different_numbers_of_dice(self):
dice = DiceSet()

Expand Down