add a Cypher System dice rolling library method
not available to the bot, yet, but that's next Signed-off-by: Brian S. Stephan <bss@incorporeal.org>
This commit is contained in:
77
tests/test_dice_lib.py
Normal file
77
tests/test_dice_lib.py
Normal file
@@ -0,0 +1,77 @@
|
||||
"""Tests for dice operations."""
|
||||
from unittest import mock
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
import dice.lib
|
||||
|
||||
|
||||
class DiceLibTestCase(TestCase):
|
||||
"""Test that a variety of dice rolls work as expected."""
|
||||
|
||||
def test_cypher_rolls(self):
|
||||
"""Roll a variety of Cypher System rolls."""
|
||||
# simple task, simple check
|
||||
with mock.patch('random.SystemRandom.randint', return_value=5):
|
||||
result = dice.lib.cypher_roll(difficulty=1)
|
||||
self.assertEqual(result, (5, 1, True, None))
|
||||
|
||||
# simple failure
|
||||
with mock.patch('random.SystemRandom.randint', return_value=2):
|
||||
result = dice.lib.cypher_roll(difficulty=1)
|
||||
self.assertEqual(result, (2, 0, False, None))
|
||||
|
||||
# rolled a 1
|
||||
with mock.patch('random.SystemRandom.randint', return_value=1):
|
||||
result = dice.lib.cypher_roll(difficulty=1)
|
||||
self.assertEqual(result, (1, None, False, 'a GM intrusion'))
|
||||
|
||||
# rolled a 17
|
||||
with mock.patch('random.SystemRandom.randint', return_value=17):
|
||||
result = dice.lib.cypher_roll(difficulty=1)
|
||||
self.assertEqual(result, (17, 5, True, '+1 damage'))
|
||||
|
||||
# rolled a 18
|
||||
with mock.patch('random.SystemRandom.randint', return_value=18):
|
||||
result = dice.lib.cypher_roll(difficulty=1)
|
||||
self.assertEqual(result, (18, 6, True, '+2 damage'))
|
||||
|
||||
# rolled a 19
|
||||
with mock.patch('random.SystemRandom.randint', return_value=19):
|
||||
result = dice.lib.cypher_roll(difficulty=1)
|
||||
self.assertEqual(result, (19, 6, True, 'a minor effect'))
|
||||
|
||||
# rolled a 20
|
||||
with mock.patch('random.SystemRandom.randint', return_value=20):
|
||||
result = dice.lib.cypher_roll(difficulty=1)
|
||||
self.assertEqual(result, (20, 6, True, 'a MAJOR EFFECT'))
|
||||
|
||||
# mods affect the result of what the roll beats
|
||||
with mock.patch('random.SystemRandom.randint', return_value=2):
|
||||
result = dice.lib.cypher_roll(difficulty=1, mods='-5')
|
||||
self.assertEqual(result, (2, 5, True, None))
|
||||
|
||||
# complex mods
|
||||
with mock.patch('random.SystemRandom.randint', return_value=2):
|
||||
result = dice.lib.cypher_roll(difficulty=3, mods='+1-4')
|
||||
self.assertEqual(result, (2, 3, True, None))
|
||||
|
||||
# complex mods
|
||||
with mock.patch('random.SystemRandom.randint', return_value=2):
|
||||
result = dice.lib.cypher_roll(difficulty=3, mods='-4+1')
|
||||
self.assertEqual(result, (2, 3, True, None))
|
||||
|
||||
# ...even without a difficulty known
|
||||
with mock.patch('random.SystemRandom.randint', return_value=2):
|
||||
result = dice.lib.cypher_roll(mods='-5')
|
||||
self.assertEqual(result, (2, 5, None, None))
|
||||
|
||||
# general "don't know the difficulty" kind of check
|
||||
with mock.patch('random.SystemRandom.randint', return_value=10):
|
||||
result = dice.lib.cypher_roll(mods='-2')
|
||||
self.assertEqual(result, (10, 5, None, None))
|
||||
|
||||
# general "don't know the difficulty" kind of check in the other direction
|
||||
with mock.patch('random.SystemRandom.randint', return_value=10):
|
||||
result = dice.lib.cypher_roll(mods='2')
|
||||
self.assertEqual(result, (10, 1, None, None))
|
||||
Reference in New Issue
Block a user