Esempio n. 1
0
 def test_string_to_dice_pairs_negative(self):
     test_input = "- 1d8 - 1d6 - 5"
     outcome = dicehelper.string_to_dice_pairs(test_input)
     expected_outcome = [(-1, 8), (-1, 6), (-5, 1)]
     self.assertEqual(
         outcome, expected_outcome,
         "{} should output {}".format(test_input, expected_outcome))
Esempio n. 2
0
 def test_string_to_dice_pairs_empty(self):
     test_input = "___"
     outcome = dicehelper.string_to_dice_pairs(test_input)
     expected_outcome = []
     self.assertEqual(
         outcome, expected_outcome,
         "{} should output {}".format(test_input, expected_outcome))
Esempio n. 3
0
 def test_string_to_dice_pairs_lone_integer(self):
     test_input = "1d20+5"
     outcome = dicehelper.string_to_dice_pairs(test_input)
     expected_outcome = [(1, 20), (5, 1)]
     self.assertEqual(
         outcome, expected_outcome,
         "{} should output {}".format(test_input, expected_outcome))
Esempio n. 4
0
 def test_string_to_dice_pairs_single(self):
     test_input = "d20"
     outcome = dicehelper.string_to_dice_pairs(test_input)
     expected_outcome = [(1, 20)]
     self.assertEqual(
         outcome, expected_outcome,
         "{} should output {}".format(test_input, expected_outcome))
Esempio n. 5
0
 def test_string_to_dice_pairs_multiple(self):
     test_input = "6d6 + 1d8 + 5d4"
     outcome = dicehelper.string_to_dice_pairs(test_input)
     expected_outcome = [(6, 6), (1, 8), (5, 4)]
     self.assertEqual(
         outcome, expected_outcome,
         "{} should output {}".format(test_input, expected_outcome))
Esempio n. 6
0
 def test_string_to_dice_pairs_max_dietype(self):
     test_input = "2d{}+1d20".format(
         configuration['dice']['dice_max_sides'] + 1)
     outcome = dicehelper.string_to_dice_pairs(test_input)
     expected_outcome = [(1, 20)]
     self.assertEqual(
         outcome, expected_outcome,
         "{} should output {}".format(test_input, expected_outcome))
Esempio n. 7
0
 def test_string_to_dice_pairs_to_string_complex(self):
     test_input = "This is a test: 1d20 + abcd + 3d6 + b + 5"
     interim_value = dicehelper.string_to_dice_pairs(test_input)
     expected_interim = [(1, 20), (3, 6), (5, 1)]
     self.assertEqual(
         interim_value, expected_interim,
         "{} should lead to {}".format(test_input, expected_interim))
     outcome = dicehelper.dice_pairs_to_string(interim_value)
     expected_outcome = "1d20+3d6+5"
     self.assertEqual(outcome, expected_outcome,
                      "Input should be the same as the output.")
 def main_dice_method(self, message):
     """
     Main method for rolling dice. Takes a string, and returns a response.
     :param message:
     :return:
     """
     dice_pairs = helper.string_to_dice_pairs(message)
     dice_amount = helper.get_dice_count(dice_pairs)
     helper.sort_dice(dice_pairs)
     dice_pairs = helper.prune_dice(dice_pairs)
     if len(dice_pairs) > 0:
         results = self.roll_the_dice(dice_pairs)
         too_many_dice = dice_amount > configuration['dice']['dice_hardcap']
         message = self.format_response(dice_pairs, results, too_many_dice)
         return message
     else:
         raise ValueError("invalid_dice")