def test_roll(self, randrange_mock): (result, min_value, max_value, step) = (7, 5, 10, 2) randrange_mock.return_value = result dice = Dice.roll(min_value, max_value, step) randrange_mock.assert_called_with(min_value, max_value + 1, step) self.assertEqual(dice.value, result)
def __resolve_dices(cls, dices_pattern: str) -> [Dice]: matches = cls.__DICE_TYPE_PATTERN.match(dices_pattern) if not matches: raise DiceException(f'Unsupported dice type: {dices_pattern}') groups: [str] = matches.groups() dice_amount: int = int(groups[0]) if (groups[0] and groups[1]) else 1 dice_range: int = int(groups[1]) if groups[1] else int(groups[0]) if dice_amount < 1: raise DiceException( f'Dice amount must be positive, but is: {dice_amount}') return [Dice.roll(1, dice_range) for _ in range(0, dice_amount)]
def roll(self) -> OvercomeTroubleResult: dices = [ Dice.roll(1, 6) for _ in range(0, self.__arguments.dice_amount) ] successes = self.__filter_successes(dices) successes_amount = len(successes) result_type = self.__check_result_type( successes_amount, self.__arguments.success_requirement) description = self.__describe_roll(successes_amount, dices) return OvercomeTroubleResult(user=self.__user, descriptions=[description], type=result_type, success_amount=successes_amount, dices=dices, basic_arguments=self.__arguments)
def __roll_dice() -> Dice: return Dice.roll(1, 6)