add a couple dice roller tests
Signed-off-by: Brian S. Stephan <bss@incorporeal.org>
This commit is contained in:
parent
1674300ec3
commit
8f76e54d30
30
tests/test_dice_roller.py
Normal file
30
tests/test_dice_roller.py
Normal file
@ -0,0 +1,30 @@
|
||||
"""Test the dice parsing and generator."""
|
||||
from unittest import mock
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
import dice.roller
|
||||
|
||||
|
||||
class DiceRollerTestCase(TestCase):
|
||||
"""Test that a variety of dice rolls can be parsed."""
|
||||
|
||||
def setUp(self):
|
||||
"""Create the dice roller."""
|
||||
self.roller = dice.roller.DiceRoller()
|
||||
|
||||
def test_standard_rolls(self):
|
||||
"""Roll a variety of normal rolls."""
|
||||
with mock.patch('random.randint', return_value=5):
|
||||
result = self.roller.do_roll('1d20')
|
||||
self.assertEqual(result, '5 (5[5])')
|
||||
|
||||
with mock.patch('random.randint', side_effect=[5, 6]):
|
||||
result = self.roller.do_roll('2d20')
|
||||
self.assertEqual(result, '11 (11[5,6])')
|
||||
|
||||
with mock.patch('random.randint', side_effect=[1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3,
|
||||
4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6]):
|
||||
result = self.roller.do_roll('6#3/4d6')
|
||||
self.assertEqual(result, '3 (3[1,1,1,1]), 6 (6[2,2,2,2]), 9 (9[3,3,3,3]), '
|
||||
'12 (12[4,4,4,4]), 15 (15[5,5,5,5]), 18 (18[6,6,6,6])')
|
Loading…
Reference in New Issue
Block a user