def test_parse_multiple_simple_dice(self, dice_count, dice_sides):
     input_parser = get_token_parser()
     element = f"{dice_count}d{dice_sides} + {dice_count}d{dice_sides} + {dice_count}d{dice_sides}"
     spec = input_parser.parse(element)
     self.assertEqual(3, len(spec.parts))
     for dice_spec in spec.parts:
         self.assertEqual(
             dice_count,
             dice_spec.dice_count,
             f"Dice Count in {element} does not match {dice_spec.dice_count}",
         )
         self.assertEqual(
             dice_sides,
             dice_spec.dice_sides,
             f"Dice Sides in {element} does not match {dice_spec.dice_sides}",
         )
 def test_parse_lower_target_dice(self, dice_count, dice_sides, target):
     input_parser = get_token_parser()
     element = f"{dice_count}d{dice_sides} t{target}"
     spec = input_parser.parse(element)
     dice_spec = spec.parts[0]
     target_spec = spec.parts[1]
     self.assertEqual(
         dice_count,
         dice_spec.dice_count,
         f"Dice Count in {element} does not match {dice_spec.dice_count}",
     )
     self.assertEqual(
         dice_sides,
         dice_spec.dice_sides,
         f"Dice Sides in {element} does not match {dice_spec.dice_sides}",
     )
     self.assertEqual(target, target_spec.target_number,
                      "Target Does not match")
     self.assertEqual(target, spec.target_number, "Target Does not match")
 def test_parse_simple_dice_with_positive_modifier(self, dice_count,
                                                   dice_sides, modifier):
     input_parser = get_token_parser()
     element = f"{dice_count}d{dice_sides} +{modifier}"
     spec = input_parser.parse(element)
     dice_spec = spec.parts[0]
     modifier_spec = spec.parts[1]
     self.assertEqual(
         dice_count,
         dice_spec.dice_count,
         f"Dice Count in {element} does not match {dice_spec.dice_count}",
     )
     self.assertEqual(
         dice_sides,
         dice_spec.dice_sides,
         f"Dice Sides in {element} does not match {dice_spec.dice_sides}",
     )
     self.assertEqual(
         modifier,
         modifier_spec.dice_modifier,
         f"Dice Modifier in {element} is invalid",
     )
Esempio n. 4
0
def get_spec(roll_string):
    parser = get_token_parser()
    roll_spec = parser.parse(roll_string)
    if not roll_spec.target_number:
        roll_spec.add_part(RollSpec(target_number=5, operation=None))
    return roll_spec
Esempio n. 5
0
def get_spec(roll_string):
    parser = get_token_parser()
    roll_spec = parser.parse(roll_string)
    return roll_spec